Repository: apache/arrow
File: cpp/src/parquet/arrow/arrow_reader_writer_test.cc (C++)

Code before:
INSTANTIATE_TEST_SUITE_P(Repetition_type, TestNestedSchemaRead,
                         ::testing::Values(Repetition::REQUIRED, Repetition::OPTIONAL));

TEST(TestImpalaConversion, ArrowTimestampToImpalaTimestamp) {
  // June 20, 2017 16:32:56 and 123456789 nanoseconds
  int64_t nanoseconds = INT64_C(1497976376123456789);

  Int96 calculated;

  Int96 expected = {{UINT32_C(632093973), UINT32_C(13871), UINT32_C(2457925)}};
  ::parquet::internal::NanosecondsToImpalaTimestamp(nanoseconds, &calculated);
  ASSERT_EQ(expected, calculated);
}

void TryReadDataFile(const std::string& path,
                     ::arrow::StatusCode expected_code = ::arrow::StatusCode::OK,
                     const std::string& expected_message = "") {
  auto pool = ::arrow::default_memory_pool();

  std::unique_ptr<FileReader> arrow_reader;
  Status s;
  Result result = FileReader::Make(pool, ParquetFileReader::OpenFile(path, false));
  if (result.ok()) {
    std::shared_ptr<::arrow::Table> table;
    auto arrow_reader = result->get();
    s = arrow_reader->ReadTable(&table);
  }

  ASSERT_EQ(s.code(), expected_code)
      << "Expected reading file to return " << arrow::Status::CodeAsString(expected_code)
      << ", but got " << s.ToString();

  if (!expected_message.empty()) {
    ASSERT_EQ(s.message().find(expected_message), 0)
        << "Expected an error message beginning with '" << expected_message
        << "', but got '" << s.message() << "'";
  }
}

TEST(TestArrowReaderAdHoc, Int96BadMemoryAccess) {
  // PARQUET-995
  TryReadDataFile(test::get_data_file("alltypes_plain.parquet"));
}

TEST(TestArrowReaderAdHoc, CorruptedSchema) {
  // PARQUET-1481
  auto path = test::get_data_file("PARQUET-1481.parquet", /*is_good=*/false);
  TryReadDataFile(path, ::arrow::StatusCode::IOError);
}

TEST(TestArrowReaderAdHoc, InvalidRepetitionLevels) {

Review comment (suggestion):
```suggestion
    s = (*reader_result)->ReadTable(&table);
```

Code after:
  }
}

INSTANTIATE_TEST_SUITE_P(Repetition_type, TestNestedSchemaRead,
                         ::testing::Values(Repetition::REQUIRED, Repetition::OPTIONAL));

TEST(TestImpalaConversion, ArrowTimestampToImpalaTimestamp) {
  std::vector<std::pair<int64_t, Int96>> test_cases = {
      // June 20, 2017 16:32:56 and 123456789 nanoseconds
      {INT64_C(1497976376123456789),
       {{UINT32_C(632093973), UINT32_C(13871), UINT32_C(2457925)}}},
      // January 1, 1970 00:00:00 and 000000000 nanoseconds
      {INT64_C(0), {{UINT32_C(0), UINT32_C(0), UINT32_C(2440588)}}},
      // December 31, 1969 23:59:59 and 999999000 nanoseconds
      {INT64_C(-1000), {{UINT32_C(2437872664), UINT32_C(20116), UINT32_C(2440587)}}},
      // December 31, 1969 00:00:00 and 000000000 nanoseconds
      {INT64_C(-86400000000000), {{UINT32_C(0), UINT32_C(0), UINT32_C(2440587)}}},
      // January 1, 1970 00:00:00 and 000001000 nanoseconds
      {INT64_C(1000), {{UINT32_C(1000), UINT32_C(0), UINT32_C(2440588)}}},
      // January 2, 1970 00:00:00 and 000000000 nanoseconds
      {INT64_C(86400000000000), {{UINT32_C(0), UINT32_C(0), UINT32_C(2440589)}}},
  };

  for (auto& [timestamp, impala_timestamp] : test_cases) {
    ASSERT_EQ(timestamp, ::parquet::Int96GetNanoSeconds(impala_timestamp));

    Int96 calculated;
    ::parquet::internal::NanosecondsToImpalaTimestamp(timestamp, &calculated);
    ASSERT_EQ(impala_timestamp, calculated);
  }
}

void TryReadDataFile(const std::string& path,
                     ::arrow::StatusCode expected_code = ::arrow::StatusCode::OK,
                     const std::string& expected_message = "") {
  auto pool = ::arrow::default_memory_pool();

  Status s;
  auto reader_result = FileReader::Make(pool, ParquetFileReader::OpenFile(path, false));
  if (reader_result.ok()) {
    std::shared_ptr<::arrow::Table> table;
    s = (*reader_result)->ReadTable(&table);
  } else {
    s = reader_result.status();
  }

  ASSERT_EQ(s.code(), expected_code)
      << "Expected reading file to return " << arrow::Status::CodeAsString(expected_code)
      << ", but got " << s.ToString();

  if (!expected_message.empty()) {