Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

GH-39562: [C++][Parquet] Fix crash in test_parquet_dataset_lazy_filtering #39632

Merged
merged 1 commit into from
Jan 16, 2024
Merged
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
14 changes: 11 additions & 3 deletions cpp/src/arrow/dataset/file_parquet.cc
Original file line number Diff line number Diff line change
Expand Up @@ -813,11 +813,17 @@ Status ParquetFileFragment::EnsureCompleteMetadata(parquet::arrow::FileReader* r

Status ParquetFileFragment::SetMetadata(
std::shared_ptr<parquet::FileMetaData> metadata,
std::shared_ptr<parquet::arrow::SchemaManifest> manifest) {
std::shared_ptr<parquet::arrow::SchemaManifest> manifest,
std::shared_ptr<parquet::FileMetaData> original_metadata) {
DCHECK(row_groups_.has_value());

metadata_ = std::move(metadata);
manifest_ = std::move(manifest);
original_metadata_ = original_metadata ? std::move(original_metadata) : metadata_;
Copy link
Member

Choose a reason for hiding this comment

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

This is ok for be but should we check Subset for this?

Copy link
Member Author

Choose a reason for hiding this comment

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

Do you mean FileMetaData::Subset?

Copy link
Member

@mapleFU mapleFU Jan 16, 2024

Choose a reason for hiding this comment

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

Yeah, I misunderstand this previously, metadata_ is from Subset, but manifest is shared and having lifetime problem here, this looks ok to me

// The SchemaDescriptor needs to be owned by a FileMetaData instance,
// because SchemaManifest only stores a raw pointer (GH-39562).
DCHECK_EQ(manifest_->descr, original_metadata_->schema())
<< "SchemaDescriptor should be owned by the original FileMetaData";

statistics_expressions_.resize(row_groups_->size(), compute::literal(true));
statistics_expressions_complete_.resize(manifest_->descr->num_columns(), false);
Expand Down Expand Up @@ -846,7 +852,8 @@ Result<FragmentVector> ParquetFileFragment::SplitByRowGroup(
parquet_format_.MakeFragment(source_, partition_expression(),
physical_schema_, {row_group}));

RETURN_NOT_OK(fragment->SetMetadata(metadata_, manifest_));
RETURN_NOT_OK(fragment->SetMetadata(metadata_, manifest_,
/*original_metadata=*/original_metadata_));
fragments[i++] = std::move(fragment);
}

Expand Down Expand Up @@ -1106,7 +1113,8 @@ ParquetDatasetFactory::CollectParquetFragments(const Partitioning& partitioning)
format_->MakeFragment({path, filesystem_}, std::move(partition_expression),
physical_schema_, std::move(row_groups)));

RETURN_NOT_OK(fragment->SetMetadata(metadata_subset, manifest_));
RETURN_NOT_OK(fragment->SetMetadata(metadata_subset, manifest_,
/*original_metadata=*/metadata_));
fragments[i++] = std::move(fragment);
}

Expand Down
5 changes: 4 additions & 1 deletion cpp/src/arrow/dataset/file_parquet.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ class ARROW_DS_EXPORT ParquetFileFragment : public FileFragment {
std::optional<std::vector<int>> row_groups);

Status SetMetadata(std::shared_ptr<parquet::FileMetaData> metadata,
std::shared_ptr<parquet::arrow::SchemaManifest> manifest);
std::shared_ptr<parquet::arrow::SchemaManifest> manifest,
std::shared_ptr<parquet::FileMetaData> original_metadata = {});

// Overridden to opportunistically set metadata since a reader must be opened anyway.
Result<std::shared_ptr<Schema>> ReadPhysicalSchemaImpl() override {
Expand Down Expand Up @@ -219,6 +220,8 @@ class ARROW_DS_EXPORT ParquetFileFragment : public FileFragment {
std::vector<bool> statistics_expressions_complete_;
std::shared_ptr<parquet::FileMetaData> metadata_;
std::shared_ptr<parquet::arrow::SchemaManifest> manifest_;
// The FileMetaData that owns the SchemaDescriptor pointed by SchemaManifest.
std::shared_ptr<parquet::FileMetaData> original_metadata_;

friend class ParquetFileFormat;
friend class ParquetDatasetFactory;
Expand Down
Loading