emkornfield commented on a change in pull request #12216: URL: https://github.com/apache/arrow/pull/12216#discussion_r790222470
########## File path: cpp/src/parquet/arrow/arrow_reader_writer_test.cc ########## @@ -3719,6 +3719,77 @@ TEST(TestArrowReaderAdHoc, WriteBatchedNestedNullableStringColumn) { ::arrow::AssertTablesEqual(*expected, *actual, /*same_chunk_layout=*/false); } +TEST(TestArrowReaderAdHoc, RepeatReadNullableStructColumnFile) { + // ARROW-14047 + auto pool = default_memory_pool(); + + // Special parquet file; see attachment in Jira + auto file_path = test::get_data_file("writeReadRowGroup.parquet"); + PARQUET_ASSIGN_OR_THROW(auto infile, ::arrow::io::ReadableFile::Open(file_path, pool)); + + std::unique_ptr<parquet::arrow::FileReader> arrow_reader; + ASSERT_OK(OpenFile(infile, pool, &arrow_reader)); + + std::shared_ptr<::arrow::Table> first_read; + ASSERT_OK(arrow_reader->ReadTable(&first_read)); + + ASSERT_OK(first_read->column(1)->chunk(0)->ValidateFull()); // So it's in theory valid + + std::shared_ptr<::arrow::Table> second_read; + ASSERT_OK(arrow_reader->ReadTable(&second_read)); + ASSERT_OK(arrow_reader->ReadTable(&second_read)); // (Actually third read) + + // 'first_read->column(1)->chunk(0)->ValidateFull()' failed with Invalid: List child array invalid: Invalid: Struct child array #0 invalid: Invalid: null_count value (854) doesn't match actual number of nulls in array (861) + // ASSERT_OK(first_read->column(1)->chunk(0)->ValidateFull()); + + ::arrow::AssertTablesEqual(*first_read.get(), *second_read.get()); + + // To eliminate possibility of parquet writer oddities, rewrite table to new parquet: + using ::arrow::io::BufferOutputStream; + ASSERT_OK_AND_ASSIGN(auto outs, BufferOutputStream::Create(1 << 10, pool)); + auto props = default_writer_properties(); + std::unique_ptr<arrow::FileWriter> writer; + ASSERT_OK( + arrow::FileWriter::Open(*first_read->schema().get(), pool, outs, props, &writer)); + ASSERT_OK(writer->WriteTable(*first_read.get(), std::numeric_limits<int64_t>::max())); + ASSERT_OK(writer->Close()); + ASSERT_OK_AND_ASSIGN(auto buffer, outs->Finish()); + + // Read from table + std::unique_ptr<parquet::arrow::FileReader> arrow_reader2; + ASSERT_OK(parquet::arrow::OpenFile(std::make_shared<BufferReader>(buffer), pool, &arrow_reader2)); + + ASSERT_OK(arrow_reader2->ReadTable(&first_read)); + ASSERT_OK(first_read->column(1)->chunk(0)->ValidateFull()); // So it's in theory valid + + ASSERT_OK(arrow_reader2->ReadTable(&second_read)); + // 'first_read->column(1)->chunk(0)->ValidateFull()' failed with Invalid: List child array invalid: + // Invalid: Struct child array #0 invalid: Invalid: null_count value (854) doesn't match actual number + // of nulls in array (861) + // ASSERT_OK(second_read->column(1)->chunk(0)->ValidateFull()); + + ::arrow::AssertTablesEqual(*first_read.get(), *second_read.get()); Review comment: Wow, that is strange. Also, just to check they also equal after round-tripping or is there data loss? Most of the state should be constructed by scratch on read, so I can't think of anything off the top of my head that would cause this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org