-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Unwrap year in comparison also for IN predicate #18092
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
Conversation
{ | ||
Expression value = node.getValue(); | ||
Expression valueList = node.getValueList(); | ||
Expression inPredicate = treeRewriter.defaultRewrite((Expression) node, 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.
@ebyhr I am not sure I need this line. please advise.
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 it would be better to default-rewrite (recursive) first, then to extract the attributes, just in case they got rewritten or simplified (don't think it matters currently, matter of style/future-proofing)
InPredicate inPredicate = treeRewriter.defaultRewrite(node, null);
Expression value = inPredicate.getValue();
Expression valueList = inPredicate.getValueList();
@@ -124,6 +129,36 @@ public Expression rewriteComparisonExpression(ComparisonExpression node, Void co | |||
return unwrapYear(expression); | |||
} | |||
|
|||
@Override |
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.
we probably want similar change for UnwrapDateTruncInComparison and UnwrapCastInComparison?
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.
Follow-up #18138
// Convert each value to a comparison expression and try to unwrap it. | ||
// unwrap the InPredicate only in case we manage to unwrap the entire value list | ||
List<Expression> expressionsList = inListExpression.getValues(); | ||
ArrayList<Expression> comparisonExpressionsList = new ArrayList<>(expressionsList.size()); |
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.
use ImmutableList.Builder
(per style, but also to avoid copy when creating new LogicalExpression
)
{ | ||
Expression value = node.getValue(); | ||
Expression valueList = node.getValueList(); | ||
Expression inPredicate = treeRewriter.defaultRewrite((Expression) node, 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.
i think it would be better to default-rewrite (recursive) first, then to extract the attributes, just in case they got rewritten or simplified (don't think it matters currently, matter of style/future-proofing)
InPredicate inPredicate = treeRewriter.defaultRewrite(node, null);
Expression value = inPredicate.getValue();
Expression valueList = inPredicate.getValueList();
please avoid mixing changes with rebase. it's hard to notice what chaned. |
Expression value = node.getValue(); | ||
Expression valueList = node.getValueList(); |
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.
Expression value = node.getValue(); | |
Expression valueList = node.getValueList(); | |
Expression value = inPredicate.getValue(); | |
Expression valueList = inPredicate.getValueList(); |
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.
done. I wasn't sure that the returned expression from defaultRewriter
must be an InPredicate
so I also added a validation.
List<Expression> expressionsList = inListExpression.getValues(); | ||
ImmutableList.Builder<Expression> comparisonExpressionsListBuilder = ImmutableList.builder(); | ||
for (Expression currExpression : expressionsList) { |
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.
- avoid abbreviations ("curr")
comparisonExpressionsListBuilder
is a long name and the fact it's listbuilder is known from its typeexpressionsList
can be inlined
List<Expression> expressionsList = inListExpression.getValues(); | |
ImmutableList.Builder<Expression> comparisonExpressionsListBuilder = ImmutableList.builder(); | |
for (Expression currExpression : expressionsList) { | |
ImmutableList.Builder<Expression> comparisonExpressions = ImmutableList.builderWithExpectedSize(inListExpression.getValues().size()); | |
for (Expression rightExpression : inListExpression.getValues()) { | |
ComparisonExpression comparisonExpression = new ComparisonExpression(EQUAL, value, rightExpression); |
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.
done.
core/trino-main/src/test/java/io/trino/sql/planner/TestUnwrapYearInComparison.java
Outdated
Show resolved
Hide resolved
@kabunchi thanks, will merge when the build passes |
Description
Additional context and related issues
Release notes
(*) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
( ) Release notes are required, with the following suggested text: