-
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
06eb293
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,88 @@ | ||
| /* | ||
| * 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, | ||
| std::unordered_map<std::string, std::string> file_branch_mapping) { | ||
| for (const auto& file : data_files) { | ||
| if (file_branch_mapping.find(file->file_name) == file_branch_mapping.end()) { | ||
| return Status::Invalid( | ||
| fmt::format("branch is missing for ChainSplit file {}", file->file_name)); | ||
| } | ||
| 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), | ||
| std::move(file_branch_mapping)); | ||
| } | ||
|
|
||
| ChainSplitFilePathFactory::ChainSplitFilePathFactory( | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping) | ||
| : ChainSplitFilePathFactory(std::move(file_bucket_path_mapping), | ||
| std::unordered_map<std::string, std::string>()) {} | ||
|
|
||
| ChainSplitFilePathFactory::ChainSplitFilePathFactory( | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping, | ||
| std::unordered_map<std::string, std::string> file_branch_mapping) | ||
| : file_bucket_path_mapping_(std::move(file_bucket_path_mapping)), | ||
| file_branch_mapping_(std::move(file_branch_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); | ||
| } | ||
|
|
||
| std::optional<std::string> ChainSplitFilePathFactory::BranchForFile( | ||
| const std::string& file_name) const { | ||
| auto it = file_branch_mapping_.find(file_name); | ||
| if (it == file_branch_mapping_.end()) { | ||
| return std::nullopt; | ||
| } | ||
| return it->second; | ||
| } | ||
|
|
||
| } // namespace paimon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * 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 <optional> | ||
| #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, | ||
| std::unordered_map<std::string, std::string> file_branch_mapping); | ||
|
|
||
| explicit ChainSplitFilePathFactory( | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping); | ||
| ChainSplitFilePathFactory(std::unordered_map<std::string, std::string> file_bucket_path_mapping, | ||
| std::unordered_map<std::string, std::string> file_branch_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; | ||
| std::optional<std::string> BranchForFile(const std::string& file_name) const; | ||
|
|
||
| private: | ||
| std::unordered_map<std::string, std::string> file_bucket_path_mapping_; | ||
| std::unordered_map<std::string, std::string> file_branch_mapping_; | ||
| }; | ||
|
|
||
| } // namespace paimon |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ | |
|
|
||
| #pragma once | ||
|
|
||
| #include <map> | ||
| #include <memory> | ||
| #include <optional> | ||
| #include <set> | ||
|
|
@@ -76,6 +77,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( | ||
|
|
@@ -109,6 +113,12 @@ class AbstractSplitRead : public SplitRead { | |
| const std::optional<std::vector<Range>>& row_ranges, | ||
| const std::shared_ptr<DataFilePathFactory>& data_file_path_factory) const; | ||
|
|
||
| Result<std::shared_ptr<TableSchema>> ReadDataSchema( | ||
| const std::shared_ptr<DataFileMeta>& file_meta, | ||
| const std::shared_ptr<DataFilePathFactory>& data_file_path_factory) const; | ||
|
|
||
| Result<const SchemaManager*> GetSchemaManagerForBranch(const std::string& branch) const; | ||
|
|
||
| Result<std::pair<std::unique_ptr<FileBatchReader>, std::set<int32_t>>> | ||
| ApplySharedShreddingReaderIfNeeded(std::unique_ptr<FileBatchReader>&& file_reader, | ||
| const std::shared_ptr<arrow::Schema>& read_schema) const; | ||
|
|
@@ -125,6 +135,7 @@ class AbstractSplitRead : public SplitRead { | |
| std::shared_ptr<arrow::Schema> raw_read_schema_; | ||
| std::shared_ptr<InternalReadContext> context_; | ||
| std::unique_ptr<SchemaManager> schema_manager_; | ||
| mutable std::map<std::string, std::unique_ptr<SchemaManager>> branch_schema_managers_; | ||
| }; | ||
|
|
||
| } // 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?