-
Notifications
You must be signed in to change notification settings - Fork 996
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
[core] Introduce InPredicateVisitor to refactor Predicate handle #4486
Changes from 4 commits
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,53 @@ | ||
/* | ||
* 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 java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
/** A utils to handle {@link Predicate}. */ | ||
public class InPredicateVisitor { | ||
|
||
/** | ||
* Method for handling with CompoundPredicate. | ||
* | ||
* @param predicate CompoundPredicate to traverse handle | ||
* @param leafName LeafPredicate name | ||
*/ | ||
public static Optional<List<Object>> extractInElements(Predicate predicate, String leafName) { | ||
if (!(predicate instanceof CompoundPredicate)) { | ||
return Optional.empty(); | ||
} | ||
|
||
CompoundPredicate compoundPredicate = (CompoundPredicate) predicate; | ||
List<Object> leafValues = new ArrayList<>(); | ||
List<Predicate> children = compoundPredicate.children(); | ||
for (Predicate leaf : children) { | ||
if (leaf instanceof LeafPredicate | ||
&& (((LeafPredicate) leaf).function() instanceof Equal) | ||
&& leaf.visit(LeafPredicateExtractor.INSTANCE).get(leafName) != null) { | ||
leafValues.add(((LeafPredicate) leaf).literals().get(0)); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
return Optional.of(leafValues); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import org.apache.paimon.predicate.Equal; | ||
import org.apache.paimon.predicate.GreaterOrEqual; | ||
import org.apache.paimon.predicate.GreaterThan; | ||
import org.apache.paimon.predicate.InPredicateVisitor; | ||
import org.apache.paimon.predicate.LeafPredicate; | ||
import org.apache.paimon.predicate.LeafPredicateExtractor; | ||
import org.apache.paimon.predicate.LessOrEqual; | ||
|
@@ -229,17 +230,11 @@ public InnerTableRead withFilter(Predicate predicate) { | |
|
||
// optimize for IN filter | ||
if ((compoundPredicate.function()) instanceof Or) { | ||
List<Predicate> children = compoundPredicate.children(); | ||
for (Predicate leaf : children) { | ||
if (leaf instanceof LeafPredicate | ||
&& (((LeafPredicate) leaf).function() instanceof Equal) | ||
&& leaf.visit(LeafPredicateExtractor.INSTANCE).get(leafName) | ||
!= null) { | ||
schemaIds.add((Long) ((LeafPredicate) leaf).literals().get(0)); | ||
} else { | ||
schemaIds.clear(); | ||
break; | ||
} | ||
Optional<List<Object>> leafs = | ||
InPredicateVisitor.extractInElements(predicate, leafName); | ||
if (leafs.isPresent()) { | ||
leafs.get().stream() | ||
.forEach(leaf -> schemaIds.add(Long.parseLong(leaf.toString()))); | ||
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.
|
||
} | ||
} | ||
} else { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,11 +32,11 @@ | |
import org.apache.paimon.predicate.Equal; | ||
import org.apache.paimon.predicate.GreaterOrEqual; | ||
import org.apache.paimon.predicate.GreaterThan; | ||
import org.apache.paimon.predicate.InPredicateVisitor; | ||
import org.apache.paimon.predicate.LeafPredicate; | ||
import org.apache.paimon.predicate.LeafPredicateExtractor; | ||
import org.apache.paimon.predicate.LessOrEqual; | ||
import org.apache.paimon.predicate.LessThan; | ||
import org.apache.paimon.predicate.Or; | ||
import org.apache.paimon.predicate.Predicate; | ||
import org.apache.paimon.reader.RecordReader; | ||
import org.apache.paimon.table.FileStoreTable; | ||
|
@@ -231,18 +231,11 @@ public InnerTableRead withFilter(Predicate predicate) { | |
} | ||
|
||
// optimize for IN filter | ||
if ((compoundPredicate.function()) instanceof Or) { | ||
for (Predicate leaf : children) { | ||
if (leaf instanceof LeafPredicate | ||
&& (((LeafPredicate) leaf).function() instanceof Equal) | ||
&& leaf.visit(LeafPredicateExtractor.INSTANCE).get(leafName) | ||
!= null) { | ||
snapshotIds.add((Long) ((LeafPredicate) leaf).literals().get(0)); | ||
} else { | ||
snapshotIds.clear(); | ||
break; | ||
} | ||
} | ||
Optional<List<Object>> leafs = | ||
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. Why here has no judge of : (compoundPredicate.function() instanceof Or) ? |
||
InPredicateVisitor.extractInElements(predicate, leafName); | ||
if (leafs.isPresent()) { | ||
leafs.get().stream() | ||
.forEach(leaf -> snapshotIds.add(Long.parseLong(leaf.toString()))); | ||
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. InPredicateVisitor.extractInElements(predicate, leafName) |
||
} | ||
} else { | ||
handleLeafPredicate(predicate, leafName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
import org.apache.paimon.fs.Path; | ||
import org.apache.paimon.predicate.CompoundPredicate; | ||
import org.apache.paimon.predicate.Equal; | ||
import org.apache.paimon.predicate.InPredicateVisitor; | ||
import org.apache.paimon.predicate.LeafPredicate; | ||
import org.apache.paimon.predicate.LeafPredicateExtractor; | ||
import org.apache.paimon.predicate.Or; | ||
|
@@ -239,25 +240,18 @@ public RecordReader<InternalRow> createReader(Split split) { | |
CompoundPredicate compoundPredicate = (CompoundPredicate) predicate; | ||
// optimize for IN filter | ||
if ((compoundPredicate.function()) instanceof Or) { | ||
List<Predicate> children = compoundPredicate.children(); | ||
for (Predicate leaf : children) { | ||
if (leaf instanceof LeafPredicate | ||
&& (((LeafPredicate) leaf).function() instanceof Equal | ||
&& ((LeafPredicate) leaf).literals().get(0) | ||
instanceof BinaryString) | ||
&& predicate | ||
.visit(LeafPredicateExtractor.INSTANCE) | ||
.get(TAG_NAME) | ||
!= null) { | ||
String equalValue = | ||
((LeafPredicate) leaf).literals().get(0).toString(); | ||
if (tagManager.tagExists(equalValue)) { | ||
predicateMap.put(equalValue, tagManager.tag(equalValue)); | ||
} | ||
} else { | ||
predicateMap.clear(); | ||
break; | ||
} | ||
Optional<List<Object>> leafs = | ||
InPredicateVisitor.extractInElements(predicate, TAG_NAME); | ||
if (leafs.isPresent()) { | ||
leafs.get().stream() | ||
.forEach( | ||
leaf -> { | ||
if (tagManager.tagExists(leaf.toString())) { | ||
predicateMap.put( | ||
leaf.toString(), | ||
tagManager.tag(leaf.toString())); | ||
} | ||
}); | ||
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.
|
||
} | ||
} | ||
} | ||
|
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.
Method for handling with In CompoundPredicate