-
Notifications
You must be signed in to change notification settings - Fork 52
feat: add read-optimized system table #403
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
Open
gripleaf
wants to merge
3
commits into
alibaba:main
Choose a base branch
from
gripleaf:feat/value_stats_filter
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+651
−15
Open
Changes from all commits
Commits
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| .. 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. | ||
| System Tables | ||
| ============= | ||
|
|
||
| Paimon C++ supports reading system tables by appending a system table suffix to | ||
| the data table path. For example, ``/warehouse/db.db/orders$snapshots`` reads | ||
| the snapshots system table for ``orders``. | ||
|
|
||
| Branch-qualified paths are also supported. For example, | ||
| ``/warehouse/db.db/orders$branch_audit$files`` reads the files system table from | ||
| the ``audit`` branch. | ||
|
|
||
| Read-Optimized System Table | ||
| --------------------------- | ||
|
|
||
| The read-optimized system table is addressed by the ``$ro`` suffix: | ||
|
|
||
| .. code-block:: text | ||
| /warehouse/db.db/orders$ro | ||
| For primary-key tables, ``$ro`` only plans data files from the highest LSM | ||
| level, which is the level produced by full compaction. This avoids merging data | ||
| from multiple LSM levels during query planning and reading. The tradeoff is that | ||
| the result may lag behind the latest committed data until a full compaction | ||
| publishes the newest records into the highest level. | ||
|
|
||
| For primary-key tables, ``$ro`` also enables value-stats filtering, so file-level | ||
| pruning of the reader predicate can be more aggressive than the base table. | ||
|
|
||
| For append-only tables, ``$ro`` has the same read behavior as the base table, | ||
| including streaming reads. | ||
|
|
||
| Limitations | ||
| ~~~~~~~~~~~ | ||
|
|
||
| - Primary-key ``$ro`` scans are batch-only. Streaming scans are not supported. | ||
| - Freshness depends on full compaction frequency. | ||
| - Primary-key tables in bucket-unaware mode are not supported by the current C++ | ||
| scan path. | ||
|
|
||
| Typical Usage | ||
| ~~~~~~~~~~~~~ | ||
|
|
||
| Use ``$ro`` for OLAP or batch workloads that can tolerate stale results and | ||
| prefer reading compacted files directly. Use the base table path when the query | ||
| must see the latest committed data. |
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
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
24 changes: 24 additions & 0 deletions
24
src/paimon/core/table/source/read_optimized_scan_options.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,24 @@ | ||
| /* | ||
| * 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 | ||
|
|
||
| namespace paimon { | ||
|
|
||
| /// Internal scan option used by `T$ro` to request top-level-only planning. | ||
| inline constexpr char kReadOptimizedScanOption[] = "__paimon.internal.read-optimized"; | ||
|
|
||
| } // 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
120 changes: 120 additions & 0 deletions
120
src/paimon/core/table/system/read_optimized_system_table.cpp
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,120 @@ | ||
| /* | ||
| * 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/table/system/read_optimized_system_table.h" | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
| #include <utility> | ||
|
|
||
| #include "paimon/common/types/data_field.h" | ||
| #include "paimon/core/schema/table_schema.h" | ||
| #include "paimon/core/table/source/read_optimized_scan_options.h" | ||
| #include "paimon/defs.h" | ||
| #include "paimon/read_context.h" | ||
| #include "paimon/scan_context.h" | ||
| #include "paimon/table/source/table_read.h" | ||
| #include "paimon/table/source/table_scan.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| ReadOptimizedSystemTable::ReadOptimizedSystemTable(std::string table_path, | ||
| std::shared_ptr<TableSchema> table_schema, | ||
| std::map<std::string, std::string> options) | ||
| : table_path_(std::move(table_path)), | ||
| table_schema_(std::move(table_schema)), | ||
| options_(std::move(options)) {} | ||
|
|
||
| std::string ReadOptimizedSystemTable::Name() const { | ||
| return kName; | ||
| } | ||
|
|
||
| Result<std::shared_ptr<arrow::Schema>> ReadOptimizedSystemTable::ArrowSchema() const { | ||
| return DataField::ConvertDataFieldsToArrowSchema(table_schema_->Fields()); | ||
| } | ||
|
|
||
| std::map<std::string, std::string> ReadOptimizedSystemTable::ReadOptimizedOptions() const { | ||
| auto options = options_; | ||
| options[kReadOptimizedScanOption] = "true"; | ||
| return options; | ||
| } | ||
|
|
||
| Result<std::unique_ptr<TableScan>> ReadOptimizedSystemTable::NewScan( | ||
| const std::shared_ptr<ScanContext>& context) const { | ||
| auto options = ReadOptimizedOptions(); | ||
| ScanContextBuilder builder(table_path_); | ||
| builder.SetOptions(options) | ||
| .WithStreamingMode(context->IsStreamingMode()) | ||
| .WithMemoryPool(context->GetMemoryPool()) | ||
| .WithExecutor(context->GetExecutor()) | ||
| .WithFileSystem(context->GetSpecificFileSystem()) | ||
| .WithCache(context->GetCache()); | ||
| if (context->GetLimit().has_value()) { | ||
| builder.SetLimit(context->GetLimit().value()); | ||
| } | ||
| if (context->GetScanFilters()) { | ||
| if (context->GetScanFilters()->GetBucketFilter().has_value()) { | ||
| builder.SetBucketFilter(context->GetScanFilters()->GetBucketFilter().value()); | ||
| } | ||
| builder.SetPartitionFilter(context->GetScanFilters()->GetPartitionFilters()); | ||
| builder.SetPredicate(context->GetScanFilters()->GetPredicate()); | ||
| } | ||
| if (context->GetGlobalIndexResult()) { | ||
| builder.SetGlobalIndexResult(context->GetGlobalIndexResult()); | ||
| } | ||
| if (context->GetSpecificTableSchema().has_value()) { | ||
| builder.SetTableSchema(context->GetSpecificTableSchema().value()); | ||
| } | ||
| PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<ScanContext> base_context, builder.Finish()); | ||
| return TableScan::Create(std::move(base_context)); | ||
| } | ||
|
|
||
| Result<std::unique_ptr<TableRead>> ReadOptimizedSystemTable::NewRead( | ||
| const std::shared_ptr<ReadContext>& context) const { | ||
| auto options = options_; | ||
| std::string branch = context->GetBranch(); | ||
| // SystemTableLoader injects Options::BRANCH when parsing paths such as `T$branch_dev$ro`. | ||
| auto branch_iter = options.find(Options::BRANCH); | ||
| if (branch_iter != options.end()) { | ||
| branch = branch_iter->second; | ||
| } | ||
| ReadContextBuilder builder(table_path_); | ||
| builder.SetOptions(options) | ||
| .WithBranch(branch) | ||
| .SetPredicate(context->GetPredicate()) | ||
| .EnablePredicateFilter(context->EnablePredicateFilter()) | ||
| .EnablePrefetch(context->EnablePrefetch()) | ||
| .SetPrefetchBatchCount(context->GetPrefetchBatchCount()) | ||
| .SetPrefetchMaxParallelNum(context->GetPrefetchMaxParallelNum()) | ||
| .EnableMultiThreadRowToBatch(context->EnableMultiThreadRowToBatch()) | ||
| .SetRowToBatchThreadNumber(context->GetRowToBatchThreadNumber()) | ||
| .WithMemoryPool(context->GetMemoryPool()) | ||
| .WithExecutor(context->GetExecutor()) | ||
| .WithFileSystem(context->GetSpecificFileSystem()) | ||
| .WithFileSystemSchemeToIdentifierMap(context->GetFileSystemSchemeToIdentifierMap()) | ||
| .SetPrefetchCacheMode(context->GetPrefetchCacheMode()) | ||
| .WithCacheConfig(context->GetCacheConfig()) | ||
| .WithCache(context->GetCache()) | ||
| .SetReadFieldNames(context->GetReadFieldNames()) | ||
| .SetReadFieldIds(context->GetReadFieldIds()); | ||
| if (context->GetSpecificTableSchema().has_value()) { | ||
| builder.SetTableSchema(context->GetSpecificTableSchema().value()); | ||
| } | ||
| PAIMON_ASSIGN_OR_RAISE(std::unique_ptr<ReadContext> base_context, builder.Finish()); | ||
| return TableRead::Create(std::move(base_context)); | ||
| } | ||
|
|
||
| } // namespace paimon |
51 changes: 51 additions & 0 deletions
51
src/paimon/core/table/system/read_optimized_system_table.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,51 @@ | ||
| /* | ||
| * 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 <map> | ||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "paimon/core/table/system/system_table.h" | ||
|
|
||
| namespace paimon { | ||
| class TableSchema; | ||
|
|
||
| /// System table for `T$ro`, exposing read-optimized data. | ||
| class ReadOptimizedSystemTable : public SystemTable { | ||
| public: | ||
| static constexpr const char* kName = "ro"; | ||
|
|
||
| ReadOptimizedSystemTable(std::string table_path, std::shared_ptr<TableSchema> table_schema, | ||
| std::map<std::string, std::string> options); | ||
|
|
||
| std::string Name() const override; | ||
| Result<std::shared_ptr<arrow::Schema>> ArrowSchema() const override; | ||
| Result<std::unique_ptr<TableScan>> NewScan( | ||
| const std::shared_ptr<ScanContext>& context) const override; | ||
| Result<std::unique_ptr<TableRead>> NewRead( | ||
| const std::shared_ptr<ReadContext>& context) const override; | ||
|
|
||
| private: | ||
| std::map<std::string, std::string> ReadOptimizedOptions() const; | ||
|
|
||
| std::string table_path_; | ||
| std::shared_ptr<TableSchema> table_schema_; | ||
| std::map<std::string, std::string> options_; | ||
| }; | ||
|
|
||
| } // namespace paimon |
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.
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.
Please keep this as-is — it is meant to notify users about the internal behavior.