-
Notifications
You must be signed in to change notification settings - Fork 48
feat: support RowRangeIndex for DataEvolutionBatchScan #255
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
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| /* | ||
| * 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 <vector> | ||
|
|
||
| #include "paimon/result.h" | ||
| #include "paimon/utils/range.h" | ||
| #include "paimon/visibility.h" | ||
|
|
||
| namespace paimon { | ||
|
|
||
| /// Index for row ranges. Provides efficient intersection queries over a sorted, non-overlapping | ||
| /// collection of ranges using binary search. | ||
| class PAIMON_EXPORT RowRangeIndex { | ||
| public: | ||
| /// Creates a RowRangeIndex from the given ranges. The ranges will be sorted and merged | ||
| /// (overlapping and adjacent ranges are combined) before indexing. | ||
| static Result<RowRangeIndex> Create(const std::vector<Range>& ranges); | ||
|
|
||
| /// Returns the sorted, non-overlapping ranges held by this index. | ||
| const std::vector<Range>& Ranges() const; | ||
|
|
||
| /// Returns true if any range in this index intersects with the interval [start, end]. | ||
| bool Intersects(int64_t start, int64_t end) const; | ||
|
|
||
| /// Returns the sub-ranges of this index that intersect with the interval [start, end]. | ||
| /// Each returned range is clipped to lie within [start, end]. | ||
| std::vector<Range> IntersectedRanges(int64_t start, int64_t end) const; | ||
|
|
||
| private: | ||
| explicit RowRangeIndex(std::vector<Range> ranges); | ||
|
|
||
| /// Finds the first index in `ends_` whose value is >= target (lower bound). | ||
| int32_t LowerBound(int64_t target) const; | ||
|
|
||
| private: | ||
| std::vector<Range> ranges_; | ||
| std::vector<int64_t> starts_; | ||
| std::vector<int64_t> ends_; | ||
| }; | ||
|
|
||
| } // 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| /* | ||
| * 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/utils/row_range_index.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <cassert> | ||
|
lxy-9602 marked this conversation as resolved.
|
||
|
|
||
| namespace paimon { | ||
|
|
||
| RowRangeIndex::RowRangeIndex(std::vector<Range> ranges) : ranges_(std::move(ranges)) { | ||
| starts_.reserve(ranges_.size()); | ||
| ends_.reserve(ranges_.size()); | ||
| for (const auto& range : ranges_) { | ||
| starts_.push_back(range.from); | ||
| ends_.push_back(range.to); | ||
| } | ||
| } | ||
|
|
||
| Result<RowRangeIndex> RowRangeIndex::Create(const std::vector<Range>& ranges) { | ||
| if (ranges.empty()) { | ||
| return Status::Invalid("Ranges cannot be empty in RowRangeIndex"); | ||
| } | ||
| return RowRangeIndex(Range::SortAndMergeOverlap(ranges, /*adjacent=*/true)); | ||
| } | ||
|
|
||
| const std::vector<Range>& RowRangeIndex::Ranges() const { | ||
| return ranges_; | ||
| } | ||
|
|
||
| bool RowRangeIndex::Intersects(int64_t start, int64_t end) const { | ||
| int32_t candidate = LowerBound(start); | ||
| return candidate < static_cast<int32_t>(starts_.size()) && starts_[candidate] <= end; | ||
| } | ||
|
|
||
| std::vector<Range> RowRangeIndex::IntersectedRanges(int64_t start, int64_t end) const { | ||
|
lxy-9602 marked this conversation as resolved.
|
||
| int32_t left = LowerBound(start); | ||
| if (left >= static_cast<int32_t>(ranges_.size())) { | ||
| return {}; | ||
| } | ||
|
|
||
| int32_t right = LowerBound(end); | ||
| if (right >= static_cast<int32_t>(ranges_.size())) { | ||
| right = static_cast<int32_t>(ranges_.size()) - 1; | ||
| } | ||
|
|
||
|
lxy-9602 marked this conversation as resolved.
|
||
| if (starts_[left] > end) { | ||
| return {}; | ||
| } | ||
|
|
||
| std::vector<Range> expected; | ||
|
|
||
| // Add the first intersecting range, clipped to [start, end]. | ||
| const Range& first_range = ranges_[left]; | ||
| expected.emplace_back(std::max(start, first_range.from), std::min(end, first_range.to)); | ||
|
|
||
| // Add all fully contained ranges between first and last. | ||
| for (int32_t i = left + 1; i < right; ++i) { | ||
| expected.push_back(ranges_[i]); | ||
| } | ||
|
|
||
| // Add the last intersecting range (if different from the first), clipped to [start, end]. | ||
| if (right != left) { | ||
| const Range& last_range = ranges_[right]; | ||
| if (last_range.from <= end) { | ||
| expected.emplace_back(std::max(start, last_range.from), std::min(end, last_range.to)); | ||
| } | ||
| } | ||
|
|
||
| return expected; | ||
|
lxy-9602 marked this conversation as resolved.
|
||
| } | ||
|
|
||
| int32_t RowRangeIndex::LowerBound(int64_t target) const { | ||
| int32_t left = 0; | ||
| auto right = static_cast<int32_t>(ends_.size()); | ||
| while (left < right) { | ||
| int32_t mid = left + (right - left) / 2; | ||
| if (ends_[mid] < target) { | ||
| left = mid + 1; | ||
| } else { | ||
| right = mid; | ||
| } | ||
| } | ||
| return left; | ||
| } | ||
|
|
||
| } // namespace paimon | ||
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.