-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[spark] paimon-spark supports row id push down #6697
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
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
109 changes: 109 additions & 0 deletions
109
paimon-common/src/main/java/org/apache/paimon/predicate/RowIdPredicateVisitor.java
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,109 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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. | ||
| */ | ||
|
|
||
| package org.apache.paimon.predicate; | ||
|
|
||
| import org.apache.paimon.utils.Range; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| import static org.apache.paimon.table.SpecialFields.ROW_ID; | ||
|
|
||
| /** | ||
| * The {@link PredicateVisitor} to extract a list of row id ranges from predicates. The returned row | ||
| * id ranges can be pushed down to manifest readers and file readers to enable efficient random | ||
| * access. | ||
| * | ||
| * <p>Note that there is a significant distinction between returning {@code null} and returning an | ||
| * empty list: | ||
| * | ||
| * <ul> | ||
| * <li>{@code null} indicates that the predicate cannot be converted into a random-access pattern, | ||
| * meaning the filter is not consumable by this visitor. | ||
| * <li>An empty list indicates that no rows satisfy the predicate (e.g. {@code WHERE _ROW_ID = 3 | ||
| * AND _ROW_ID IN (1, 2)}). | ||
| * </ul> | ||
| */ | ||
| public class RowIdPredicateVisitor implements PredicateVisitor<List<Range>> { | ||
|
|
||
| @Override | ||
| public List<Range> visit(LeafPredicate predicate) { | ||
| if (ROW_ID.name().equals(predicate.fieldName())) { | ||
| LeafFunction function = predicate.function(); | ||
| if (function instanceof Equal || function instanceof In) { | ||
| ArrayList<Long> rowIds = new ArrayList<>(); | ||
| for (Object literal : predicate.literals()) { | ||
| rowIds.add((Long) literal); | ||
| } | ||
| // The list output by getRangesFromList is already sorted, | ||
| // and has no overlap | ||
| return Range.getRangesFromList(rowIds); | ||
| } | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Range> visit(CompoundPredicate predicate) { | ||
| CompoundPredicate.Function function = predicate.function(); | ||
| List<Range> rowIds = null; | ||
| // `And` means we should get the intersection of all children. | ||
| if (function instanceof And) { | ||
| for (Predicate child : predicate.children()) { | ||
| List<Range> childList = child.visit(this); | ||
| if (childList == null) { | ||
| continue; | ||
| } | ||
|
|
||
| if (rowIds == null) { | ||
| rowIds = childList; | ||
| } else { | ||
| rowIds = Range.and(rowIds, childList); | ||
| } | ||
|
|
||
| // shortcut for intersection | ||
| if (rowIds.isEmpty()) { | ||
| return rowIds; | ||
| } | ||
| } | ||
| } else if (function instanceof Or) { | ||
| // `Or` means we should get the union of all children | ||
| rowIds = new ArrayList<>(); | ||
| for (Predicate child : predicate.children()) { | ||
| List<Range> childList = child.visit(this); | ||
| if (childList == null) { | ||
| return null; | ||
| } | ||
|
|
||
| rowIds.addAll(childList); | ||
| rowIds = Range.sortAndMergeOverlap(rowIds, true); | ||
| } | ||
| } else { | ||
| // unexpected function type, just return null | ||
| return null; | ||
| } | ||
| return rowIds; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Range> visit(TransformPredicate predicate) { | ||
| // do not support transform predicate now. | ||
| return null; | ||
| } | ||
| } |
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
21 changes: 21 additions & 0 deletions
21
...spark/paimon-spark-3.2/src/test/scala/org/apache/paimon/spark/sql/RowIdPushDownTest.scala
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,21 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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. | ||
| */ | ||
|
|
||
| package org.apache.paimon.spark.sql | ||
|
|
||
| class RowIdPushDownTest extends RowIdPushDownTestBase {} |
21 changes: 21 additions & 0 deletions
21
...spark/paimon-spark-3.3/src/test/scala/org/apache/paimon/spark/sql/RowIdPushDownTest.scala
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,21 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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. | ||
| */ | ||
|
|
||
| package org.apache.paimon.spark.sql | ||
|
|
||
| class RowIdPushDownTest extends RowIdPushDownTestBase {} |
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.
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.
Remove this option, it is useless.
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 this option is necessary, it disables rowId pushdown for non-data-evolution tables. Currently, due to the issue in #6747, rowId pushdown should not be enabled for non-data-evolution tables.