Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

GH-45185: [C++][Parquet] Raise an error for invalid repetition levels when delimiting records #45186

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion cpp/src/parquet/arrow/arrow_reader_writer_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3963,7 +3963,8 @@ TEST(TestImpalaConversion, ArrowTimestampToImpalaTimestamp) {
}

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

std::unique_ptr<FileReader> arrow_reader;
Expand All @@ -3977,6 +3978,12 @@ void TryReadDataFile(const std::string& path,
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) {
Expand All @@ -3990,6 +3997,13 @@ TEST(TestArrowReaderAdHoc, CorruptedSchema) {
TryReadDataFile(path, ::arrow::StatusCode::IOError);
}

TEST(TestArrowReaderAdHoc, InvalidRepetitionLevels) {
// GH-45185 - Repetition levels start with 1 instead of 0
auto path = test::get_data_file("ARROW-GH-45185.parquet", /*is_good=*/false);
TryReadDataFile(path, ::arrow::StatusCode::IOError,
"The repetition level at the start of a record must be 0 but got 1");
}

TEST(TestArrowReaderAdHoc, LARGE_MEMORY_TEST(LargeStringColumn)) {
// ARROW-3762
::arrow::StringBuilder builder;
Expand Down
7 changes: 6 additions & 1 deletion cpp/src/parquet/column_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1611,7 +1611,12 @@ class TypedRecordReader : public TypedColumnReaderImpl<DType>,
// another record start or exhausting the ColumnChunk
int64_t level = levels_position_;
if (at_record_start_) {
ARROW_DCHECK_EQ(0, rep_levels[levels_position_]);
if (ARROW_PREDICT_FALSE(rep_levels[levels_position_] != 0)) {
std::stringstream ss;
ss << "The repetition level at the start of a record must be 0 but got "
<< rep_levels[levels_position_];
throw ParquetException(ss.str());
}
++levels_position_;
// We have decided to consume the level at this position; therefore we
// must advance until we find another record boundary
Expand Down
Loading