-
Notifications
You must be signed in to change notification settings - Fork 55
feat(shared-shredding): Expose shared-shredding utilities #405
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
Merged
lxy-9602
merged 5 commits into
alibaba:main
from
dalingmeng:feature/shared-shredding-schema-utils
Jul 11, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0f4cd63
feat(shared-shredding): Expose shared-shredding utilities
dalingmeng 26d59f5
Merge branch 'main' into feature/shared-shredding-schema-utils
dalingmeng 0e16cf3
Address shared-shredding schema utils review comments
dalingmeng 1e49753
Merge branch 'main' into feature/shared-shredding-schema-utils
dalingmeng ca4753d
Merge branch 'main' into feature/shared-shredding-schema-utils
zjw1111 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
include/paimon/data/shredding/map_shared_shredding_schema_utils.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| /* | ||
| * 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 <cstdint> | ||
| #include <map> | ||
| #include <memory> | ||
| #include <set> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "paimon/arrow/abi.h" | ||
| #include "paimon/result.h" | ||
| #include "paimon/status.h" | ||
| #include "paimon/visibility.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| /// Parsed file-level meta for one shared-shredding MAP column. | ||
| struct PAIMON_EXPORT MapSharedShreddingFieldMeta { | ||
| /// field_name -> field_id | ||
| std::map<std::string, int32_t> name_to_id; | ||
| /// field_id -> ordered physical column indices | ||
| std::map<int32_t, std::vector<int32_t>> field_to_columns; | ||
| /// Set of field_ids that ever spilled into __overflow | ||
| std::set<int32_t> overflow_field_set; | ||
| /// Number of physical columns K in this file | ||
| int32_t num_columns = 0; | ||
| /// Maximum row width observed in this file | ||
| int32_t max_row_width = 0; | ||
|
|
||
| bool operator==(const MapSharedShreddingFieldMeta& other) const { | ||
| if (this == &other) { | ||
| return true; | ||
| } | ||
| return name_to_id == other.name_to_id && field_to_columns == other.field_to_columns && | ||
| overflow_field_set == other.overflow_field_set && num_columns == other.num_columns && | ||
| max_row_width == other.max_row_width; | ||
| } | ||
| }; | ||
|
|
||
| class PAIMON_EXPORT MapSharedShreddingSchemaUtils { | ||
| public: | ||
| MapSharedShreddingSchemaUtils() = delete; | ||
| ~MapSharedShreddingSchemaUtils() = delete; | ||
|
|
||
| /// Converts a logical schema to a physical schema by replacing shredding MAP columns | ||
| /// with their physical Struct representation. | ||
| /// @param logical_schema The original Arrow C schema with MAP<STRING, T> columns. | ||
| /// Ownership of schema resources is transferred to this method. | ||
| /// @param field_to_num_columns Map from field name to its physical column count K. | ||
| /// Each shredding column can have its own width. | ||
| /// @return The exported Arrow C schema for file writing. | ||
| static Result<std::unique_ptr<::ArrowSchema>> LogicalToPhysicalSchema( | ||
| std::unique_ptr<::ArrowSchema> logical_schema, | ||
| const std::map<std::string, int32_t>& field_to_num_columns); | ||
|
|
||
| /// Attaches shared-shredding metadata to fields in a physical schema. | ||
| /// @param physical_schema The Arrow C physical schema whose fields should receive metadata. | ||
| /// Ownership of schema resources is transferred to this method. | ||
| /// @param field_name_to_meta Map from physical field name to its shared-shredding metadata. | ||
| /// Existing shared-shredding metadata keys on matching fields are overwritten. | ||
| /// @param compression Compression codec name for field_dict serialization. | ||
| /// @return A new Arrow C schema with shared-shredding metadata attached to matching fields. | ||
| static Result<std::unique_ptr<::ArrowSchema>> AttachMetadataToSchema( | ||
| std::unique_ptr<::ArrowSchema> physical_schema, | ||
| const std::map<std::string, MapSharedShreddingFieldMeta>& field_name_to_meta, | ||
| const std::string& compression); | ||
|
|
||
| /// Extracts shared-shredding metadata from a named field in a physical schema. | ||
| /// @param physical_schema The Arrow C physical schema that contains the target field. | ||
| /// Ownership of schema resources is transferred to this method. | ||
| /// @param field_name The physical field name whose metadata should be extracted. | ||
| /// @param compression Compression codec name for field_dict deserialization. | ||
| /// @return Parsed shared-shredding metadata for the field. | ||
| static Result<MapSharedShreddingFieldMeta> ExtractMetadataFromField( | ||
| std::unique_ptr<::ArrowSchema> physical_schema, const std::string& field_name, | ||
| const std::string& compression); | ||
| }; | ||
|
|
||
| } // namespace paimon | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.