Simplify coalesce expressions#12192
Conversation
presto-main/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java
Outdated
Show resolved
Hide resolved
presto-main/src/test/java/com/facebook/presto/sql/TestExpressionInterpreter.java
Outdated
Show resolved
Hide resolved
0cb5678 to
7f0e4ad
Compare
|
@kokosing Have added support for nested coalesce expressions. |
7f0e4ad to
3dd19a7
Compare
|
@sopel39 Would you like to take a look also? |
There was a problem hiding this comment.
what if there are more levels of recursion? Make it recursive
There was a problem hiding this comment.
But the current model is recursive right. We have added tests with more levels of coalesce and it passed it.
There was a problem hiding this comment.
It only supports one level of recursion.
There was a problem hiding this comment.
Won't ExpressionInterpreter#processWithExceptionHandling will call other levels ? We just need to check if one of argument is of CoalesceExpression If yes we will extract its arguments and push it to the outer expression and processWithExceptionHandling will ideally handle at more levels
If I am not wrong recursive implementation will simplify
coalesce(coalesce(unbound_long, coalesce(unbound_long, 1)), unbound_long2) to coalesce(unbound_long, 1)
There was a problem hiding this comment.
Sorry I have replaced it with isDeterministic((CoalesceExpression) expression)
There was a problem hiding this comment.
I mean I think that isDeterministic((CoalesceExpression) expression) can be removed completely. We don't need to check if nested coalesce is deterministic
There was a problem hiding this comment.
But in that case it will simplify coalesce(unbound_long, coalesce(random(), 1) to coalesce(unbound_long, random(), 1).
There was a problem hiding this comment.
@sopel39 Removed the deterministic check as it is not required now
There was a problem hiding this comment.
Thank you. Ping us when release is done to land it
presto-main/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java
Outdated
Show resolved
Hide resolved
|
@Praveen2112 this will help a bit with #12155 (as per #12155 (comment)). Nice |
3dd19a7 to
fe3ef94
Compare
presto-main/src/main/java/com/facebook/presto/sql/planner/ExpressionInterpreter.java
Outdated
Show resolved
Hide resolved
6f1e657 to
0993125
Compare
b843fa2 to
8fc124b
Compare
8fc124b to
2803ca6
Compare
|
Merged |
For coalesce expression like
coalesce(colA, colA)can be simplified tocolAand for expressions likecoalesce('1', colA)can be simplified to'1'. This patch captures those pattern and simplifies them. Also updated the test for the above changes