-
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 PredicateUtils to refactor Predicate handle #4469
Conversation
Preconditions.checkState( | ||
predicate instanceof CompoundPredicate, | ||
"PredicateUtils##handleCompoundPredicate should handle with a CompoundPredicate."); | ||
|
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.
PredicateUtils.traverseCompoundPredicate only supports processing Predicates of CompoundPredicate type
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.
addressed
leafName, | ||
(Predicate p) -> { | ||
handleLeafPredicate(p, leafName); | ||
}, |
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.
Can handleLeafPredicate
method also be extracted to the util?
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 had considered about it,this method common logic is less,extract may cost more codes,so keep as current maybe better. Thanks~ @LinMingQiang
+1 |
snapshotIds.add((Long) ((LeafPredicate) p).literals().get(0)); | ||
} | ||
}, | ||
(Predicate p) -> { |
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.
(Predicate p) -> snapshotIds = null
String leafName, | ||
Consumer<Predicate> matchConsumer, | ||
Consumer<Predicate> unMatchConsumer) { | ||
Preconditions.checkState( |
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.
May be use Preconditions.checkArgument instead better?
schemaIds.add((Long) ((LeafPredicate) p).literals().get(0)); | ||
} | ||
}, | ||
(Predicate p) -> { |
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.
(Predicate p) -> schemaIds = null
PredicateUtils.traverseCompoundPredicate( | ||
predicate, | ||
leafName, | ||
(Predicate p) -> { |
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.
May replaced with expression lambda better?
(Predicate p) -> handleLeafPredicate(p, leafName)
} | ||
}, | ||
(Predicate p) -> { | ||
schemaIds = null; |
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.
Why not schemaIds.clear()?
} | ||
}, | ||
(Predicate p) -> { | ||
snapshotIds = null; |
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.
Why not snapshotIds.clear()?
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.
had just set to null which more efficient.
} | ||
}, | ||
(Predicate p) -> { | ||
predicateMap = null; |
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.
Why not predicateMap.clear();
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.
had just set to null which more efficient.
@wwj6591812 had addressed, Thanks for review. |
import java.util.function.Consumer; | ||
|
||
/** A utils to handle {@link Predicate}. */ | ||
public class PredicateUtils { |
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.
InPredicateVisitor?
* @param matchConsumer leafName matched handle | ||
* @param unMatchConsumer leafName unmatched handle | ||
*/ | ||
public static void traverseCompoundPredicate( |
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.
extractInElements
String leafName, | ||
Consumer<Predicate> matchConsumer, | ||
Consumer<Predicate> unMatchConsumer) { | ||
Preconditions.checkArgument( |
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.
if (predicate is in predicate): just get elements from it.
* @param matchConsumer leafName matched handle | ||
* @param unMatchConsumer leafName unmatched handle | ||
*/ | ||
public static void traverseCompoundPredicate( |
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.
Just return Optional<List<Object>>
, elements of in.
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.
Get it, would modify as suggestion,Thanks @JingsongLi
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'm traveling outside, would modify it in these two days.
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.
move the pr to a new pr #4486 close it first.
Purpose
Linked issue: close #xxx
Tests
API and Format
Documentation