Skip to content
Closed
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
25 changes: 19 additions & 6 deletions cpp/src/arrow/dataset/file_parquet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,25 @@ Result<ScanTaskIterator> ParquetFileFormat::ScanFile(std::shared_ptr<ScanOptions
GetReader(fragment->source(), options.get(), context.get()));

if (!parquet_fragment->HasCompleteMetadata()) {
// row groups were not already filtered; do this now
RETURN_NOT_OK(parquet_fragment->EnsureCompleteMetadata(reader.get()));
ARROW_ASSIGN_OR_RAISE(row_groups,
parquet_fragment->FilterRowGroups(*options->filter));
if (row_groups.empty()) {
return MakeEmptyIterator<std::shared_ptr<ScanTask>>();
// row groups were not already filtered; do this now (if there is a filter)
if (!options->filter->Equals(true)) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bkietz ideally we would also skip this if the flilter only involves the partition_expression and not any actual columns of the file. What is the best way to check this? (simplify the filter first with partition_expression ?)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplifying the filter by the partition expression would work, but it's not safe without loading the physical schema since we need to validate the filter against that. Otherwise a filter without implicit casts (for example) would result in an assertion failure. Let's leave that optimization for a follow up; the right way to do this is probably to rewrite Expression::Assume to return a Result (allowing it to fail non-catastrophically even without a schema against which to validate), but that's a much larger project

RETURN_NOT_OK(parquet_fragment->EnsureCompleteMetadata(reader.get()));
ARROW_ASSIGN_OR_RAISE(row_groups,
parquet_fragment->FilterRowGroups(*options->filter));
if (row_groups.empty()) {
return MakeEmptyIterator<std::shared_ptr<ScanTask>>();
}
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
} else {
// since we are not scanning this fragment with a filter, don't bother loading statistics

// since we are not scanning this fragment with a filter, don't bother loading
// statistics
row_groups = parquet_fragment->row_groups();
if (row_groups.empty()) {
// empty vector represents all row groups
std::shared_ptr<parquet::FileMetaData> metadata =
reader->parquet_reader()->metadata();
int num_row_groups = metadata->num_row_groups();
row_groups = RowGroupInfo::FromCount(num_row_groups);
}
}
}

Expand Down