-
Notifications
You must be signed in to change notification settings - Fork 52
feat: support to read chain data split #387
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include "paimon/core/io/chain_data_file_path_factory.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "paimon/common/utils/path_util.h" | ||
| #include "paimon/core/io/data_file_meta.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| ChainDataFilePathFactory::ChainDataFilePathFactory( | ||
| std::shared_ptr<DataFilePathFactory> fallback, | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping) | ||
| : fallback_(std::move(fallback)), | ||
| file_bucket_path_mapping_(std::move(file_bucket_path_mapping)) {} | ||
|
|
||
| std::string ChainDataFilePathFactory::ToPath(const std::shared_ptr<DataFileMeta>& file_meta) const { | ||
| if (file_meta->external_path) { | ||
| return file_meta->external_path.value(); | ||
| } | ||
|
|
||
| auto it = file_bucket_path_mapping_.find(file_meta->file_name); | ||
| if (it != file_bucket_path_mapping_.end()) { | ||
| return PathUtil::JoinPath(it->second, file_meta->file_name); | ||
| } | ||
|
|
||
| return fallback_->ToPath(file_meta); | ||
| } | ||
|
|
||
| } // namespace paimon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
|
|
||
| #include "paimon/core/io/data_file_path_factory.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| class ChainDataFilePathFactory : public DataFilePathFactory { | ||
| public: | ||
| ChainDataFilePathFactory(std::shared_ptr<DataFilePathFactory> fallback, | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping); | ||
|
|
||
| std::string ToPath(const std::shared_ptr<DataFileMeta>& file_meta) const override; | ||
|
|
||
| private: | ||
| std::shared_ptr<DataFilePathFactory> fallback_; | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping_; | ||
| }; | ||
|
|
||
| } // namespace paimon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,17 +66,26 @@ Result<std::unique_ptr<BatchReader>> RawFileSplitRead::CreateReader( | |
| if (!data_split) { | ||
| return Status::Invalid("cannot cast split to data_split in RawFileSplitRead"); | ||
| } | ||
| auto dv_factory = DeletionVector::CreateFactory( | ||
| options_.GetFileSystem(), | ||
| DeletionVector::CreateDeletionFileMap(data_split->DataFiles(), data_split->DeletionFiles()), | ||
| pool_); | ||
| PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<DataFilePathFactory> data_file_path_factory, | ||
| CreateDataFilePathFactory(data_split)); | ||
| return CreateReader(data_split->Partition(), data_split->Bucket(), data_split->DataFiles(), | ||
| data_split->DeletionFiles()); | ||
| dv_factory, data_file_path_factory); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<BatchReader>> RawFileSplitRead::CreateReader( | ||
| const BinaryRow& partition, int32_t bucket, | ||
| const std::vector<std::shared_ptr<DataFileMeta>>& data_files, | ||
| DeletionVector::Factory dv_factory) { | ||
| DeletionVector::Factory dv_factory, | ||
| std::shared_ptr<DataFilePathFactory> data_file_path_factory) { | ||
| const auto& predicate = context_->GetPredicate(); | ||
| PAIMON_ASSIGN_OR_RAISE(std::shared_ptr<DataFilePathFactory> data_file_path_factory, | ||
| path_factory_->CreateDataFilePathFactory(partition, bucket)); | ||
| if (!data_file_path_factory) { | ||
| PAIMON_ASSIGN_OR_RAISE(data_file_path_factory, | ||
| path_factory_->CreateDataFilePathFactory(partition, bucket)); | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This design feels a bit too implicit. Why can’t each caller just pass in the correct
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, let’s avoid using default arguments in production code. |
||
|
|
||
| PAIMON_ASSIGN_OR_RAISE( | ||
| std::vector<std::unique_ptr<FileBatchReader>> raw_file_readers, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| /* | ||
| * Copyright 2026-present Alibaba Inc. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <unordered_map> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "paimon/common/data/binary_row.h" | ||
| #include "paimon/core/table/source/data_split_impl.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| class ChainDataSplitImpl : public DataSplitImpl { | ||
| public: | ||
| static constexpr const char* VIRTUAL_BUCKET_PATH = "placeholder::virtual-bucket-path"; | ||
|
|
||
| ChainDataSplitImpl(const std::shared_ptr<DataSplitImpl>& base_split, bool all_snapshot_split, | ||
| const BinaryRow& read_partition, | ||
| std::unordered_map<std::string, std::string>&& file_bucket_path_mapping, | ||
| std::unordered_map<std::string, std::string>&& file_branch_mapping) | ||
| : DataSplitImpl(base_split->Partition(), base_split->Bucket(), base_split->BucketPath(), | ||
| std::vector<std::shared_ptr<DataFileMeta>>(base_split->DataFiles())), | ||
| all_snapshot_split_(all_snapshot_split), | ||
| read_partition_(read_partition), | ||
| file_bucket_path_mapping_(std::move(file_bucket_path_mapping)), | ||
| file_branch_mapping_(std::move(file_branch_mapping)) { | ||
| CopyMetadataFrom(*base_split); | ||
| } | ||
|
|
||
| bool AllSnapshotSplit() const { | ||
| return all_snapshot_split_; | ||
| } | ||
|
|
||
| const BinaryRow& ReadPartition() const { | ||
| return read_partition_; | ||
| } | ||
|
|
||
| const std::unordered_map<std::string, std::string>& FileBucketPathMapping() const { | ||
| return file_bucket_path_mapping_; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that |
||
|
|
||
| const std::unordered_map<std::string, std::string>& FileBranchMapping() const { | ||
| return file_branch_mapping_; | ||
| } | ||
|
|
||
| private: | ||
| bool all_snapshot_split_; | ||
| BinaryRow read_partition_; | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping_; | ||
| std::unordered_map<std::string, std::string> file_branch_mapping_; | ||
| }; | ||
|
|
||
| } // namespace paimon | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor:
CreateDataFilePathFactoryis currently in thepublicsection, but it seems to only be called by subclasses internally. Would it be possible to move it into theprotectedsection just below?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest revision.
CreateDataFilePathFactoryis now protected since it is only used byAbstractSplitReadsubclasses.