-
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
af12574
8332390
ad8fa33
98d0811
2e87f75
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,66 @@ | ||
| /* | ||
| * 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_split_file_path_factory.h" | ||
|
|
||
| #include <utility> | ||
|
|
||
| #include "fmt/format.h" | ||
| #include "paimon/common/utils/path_util.h" | ||
| #include "paimon/core/io/data_file_meta.h" | ||
| #include "paimon/status.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| Result<std::shared_ptr<ChainSplitFilePathFactory>> ChainSplitFilePathFactory::Create( | ||
| const std::vector<std::shared_ptr<DataFileMeta>>& data_files, | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping) { | ||
| for (const auto& file : data_files) { | ||
| if (file->external_path) { | ||
| continue; | ||
| } | ||
| if (file_bucket_path_mapping.find(file->file_name) == file_bucket_path_mapping.end()) { | ||
| return Status::Invalid( | ||
| fmt::format("bucket path is missing for ChainSplit file {}", file->file_name)); | ||
| } | ||
| } | ||
| return std::make_shared<ChainSplitFilePathFactory>(std::move(file_bucket_path_mapping)); | ||
| } | ||
|
|
||
| ChainSplitFilePathFactory::ChainSplitFilePathFactory( | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping) | ||
| : file_bucket_path_mapping_(std::move(file_bucket_path_mapping)) {} | ||
|
|
||
| std::string ChainSplitFilePathFactory::ToPath( | ||
| const std::shared_ptr<DataFileMeta>& file_meta) const { | ||
| if (file_meta->external_path) { | ||
| return file_meta->external_path.value(); | ||
| } | ||
|
|
||
| return PathUtil::JoinPath(file_bucket_path_mapping_.at(file_meta->file_name), | ||
| file_meta->file_name); | ||
| } | ||
|
|
||
| std::string ChainSplitFilePathFactory::ToAlignedPath( | ||
| const std::string& file_name, const std::shared_ptr<DataFileMeta>& aligned) const { | ||
| auto external_path = aligned->ExternalPathDir(); | ||
| if (external_path) { | ||
| return PathUtil::JoinPath(external_path.value(), file_name); | ||
| } | ||
| return PathUtil::JoinPath(file_bucket_path_mapping_.at(aligned->file_name), file_name); | ||
| } | ||
|
|
||
| } // namespace paimon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| /* | ||
| * 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 <vector> | ||
|
|
||
| #include "paimon/core/io/data_file_path_factory.h" | ||
| #include "paimon/result.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| class ChainSplitFilePathFactory : public DataFilePathFactory { | ||
| public: | ||
| static Result<std::shared_ptr<ChainSplitFilePathFactory>> Create( | ||
| const std::vector<std::shared_ptr<DataFileMeta>>& data_files, | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping); | ||
|
|
||
| explicit ChainSplitFilePathFactory( | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping); | ||
|
|
||
| std::string ToPath(const std::shared_ptr<DataFileMeta>& file_meta) const override; | ||
| std::string ToAlignedPath(const std::string& file_name, | ||
| const std::shared_ptr<DataFileMeta>& aligned) const override; | ||
|
|
||
| private: | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping_; | ||
| }; | ||
|
|
||
| } // namespace paimon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,9 @@ class AbstractSplitRead : public SplitRead { | |
| Result<std::unique_ptr<BatchReader>> ApplyPredicateFilterIfNeeded( | ||
| std::unique_ptr<BatchReader>&& reader, const std::shared_ptr<Predicate>& predicate) const; | ||
|
|
||
| Result<std::shared_ptr<DataFilePathFactory>> CreateDataFilePathFactory( | ||
|
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. Minor:
Author
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. Fixed in the latest revision. |
||
| const std::shared_ptr<DataSplitImpl>& data_split) const; | ||
|
|
||
| protected: | ||
| // return nullptr if file is skipped by index or dv | ||
| virtual Result<std::unique_ptr<FileBatchReader>> ApplyIndexAndDvReaderIfNeeded( | ||
|
|
||
| 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 ChainSplitImpl : public DataSplitImpl { | ||
| public: | ||
| static constexpr const char* VIRTUAL_BUCKET_PATH = "placeholder::virtual-bucket-path"; | ||
|
|
||
| ChainSplitImpl(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
Author
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. Added a note in the API and Format section to clarify 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.
I think there is still a semantic gap with the Java ChainSplit read path.
The PR now deserializes and preserves
fileBranchMapping, and usesfileBucketPathMappingto resolve each file path. However, Java also consumesfileBranchMappingwhen reading each file:MergeFileSplitRead#createChainReaderbuilds aChainReadContext, andChainKeyValueFileReaderFactory#getDataSchemauseschainReadContext.fileBranchMapping().get(fileMeta.fileName())to choose the branch-specificSchemaManagerbefore loadingfileMeta.schemaId().In the C++ path,
AbstractSplitRead::CreateFieldMappingReaderstill loads schemas from the current table/current branch only viacontext_->GetTableSchema()orschema_manager_->ReadSchema(file_meta->schema_id). For a ChainSplit containing files from both snapshot and delta branches, the sameschema_idmay refer to different schemas across branches, or may not exist in the current branch at all. In that case C++ can read with the wrong schema or fail, while Java reads with the schema from the file’s own branch.Could we either make ChainSplit reads branch-aware when resolving
DataFileMeta::schema_id, usingChainSplitImpl::FileBranchMapping(), or explicitly fail fast for ChainSplits whose files belong to a non-current branch until branch-aware schema selection is supported?