Repository navigation
Conversation
zabetak
left a comment
There was a problem hiding this comment.
My first attempt would be to try to fix the AND(=(1, 1), =(1, 1)) at the very source which occurs. Having simpler expressions to begin with is generally desired. Please check where the expression is created in the first place and if there is a meaningful way to fix it there. If that becomes too intrusive or complicated then we can leave it as a follow-up.
Tentatively approving this assuming that the minor suggestions are incorporated in the next commit.
| return ExprNodeDescUtils.or(args); | ||
| // Flattening/deduplication may collapse the operand list; | ||
| // OR require at least two operands (GenericUDFOPOr#initialize enforces this), so unwrapping trivial cases. | ||
| return unwrapSingleOperand(ExprNodeDescUtils.or(args)); |
There was a problem hiding this comment.
Its better to put the unwrap logic inside ExprNodeDescUtils.or and ExprNodeDescUtils.and to avoid having the same problem appearing in a different place where these methods are called. Moreover this new method is more of a utility rather than something belonging to ExprNodeConverter so the utils is a more appropriate place.
There was a problem hiding this comment.
Here ExprNodeDescUtils.or and ExprNodeDescUtils.and are returning ExprNodeGenericFuncDesc so here we need to change the return type of these functions to ExprNodeDesc which results in more changes so if required we can do it in another PR. Also current unwrapSingleOperand API specific to AND/OR functions so moving it to ExprNodeDescUtils requires more check so currently not moving it.
There was a problem hiding this comment.
@mdayakar I have attached in the Jira a patch that introduces the fix inside ExprNodeDescUtils.or and ExprNodeDescUtils.and, changing the return type and propagating the necessary adjustments in cascade to all relevant files (just code change, no test included); in case we want to consider this solution.
There was a problem hiding this comment.
The patch attached by @rubenada makes sense and given that we have a bit more time for landing this I would say that it's worth going into this direction.
There was a problem hiding this comment.
Once we adopt the patch that makes the fix inside ExprNodeDescUtils all the comments about unrapping should become part of the Javadoc of the respective methods.
| return ExprNodeDescUtils.or(args); | ||
| // Flattening/deduplication may collapse the operand list; | ||
| // OR require at least two operands (GenericUDFOPOr#initialize enforces this), so unwrapping trivial cases. | ||
| return unwrapSingleOperand(ExprNodeDescUtils.or(args)); |
There was a problem hiding this comment.
Once we adopt the patch that makes the fix inside ExprNodeDescUtils all the comments about unrapping should become part of the Javadoc of the respective methods.
| } | ||
|
|
||
| @Test | ||
| public void testAndWithDuplicateColumnOperandsIsUnwrapped() { |
There was a problem hiding this comment.
The name is bit misleading. The operands are duplicate but they are not columns; they are equality expressions. Compared to the previous test case just above not sure if it increases coverage.
| assertEquals(1, reduced.size()); | ||
| assertTrue(reduced.get(0) instanceof RexLiteral); | ||
| assertEquals(Boolean.TRUE, ((RexLiteral) reduced.get(0)).getValueAs(Boolean.class)); |
There was a problem hiding this comment.
Again assertion on the string representation of the result would be easier to read.
| assertSpecifiedOperatorWithDuplicateConstantOperands(SqlStdOperatorTable.OR); | ||
| } | ||
|
|
||
| private void assertSpecifiedOperatorWithDuplicateConstantOperands(SqlBinaryOperator operator) { |
There was a problem hiding this comment.
This very specific assert method is unlikely to be used by anyone else writing tests in this class in the future. Generalizing it a bit and taking the expression under test outside of the method would increase the likelihood of others taking advantage of it.
| private void assertSpecifiedOperatorWithDuplicateConstantOperands(SqlBinaryOperator operator) { | |
| private void assertReduce(String expected, RexNode node) { |
5df08e6 to
c4fcb27
Compare
Done the changes accordingly. |
|
@mdayakar there are several "Unused import" warnings detected by Sonar which should be handled before the merge, sorry if the came from my patch |
276c296 to
2bd1fde
Compare
|
LGTM |
1e5a2d1 to
a7cbb44
Compare
a7cbb44 to
c0e2108
Compare
@rubenada |
|
zabetak
left a comment
There was a problem hiding this comment.
I understand why instanceof and casting was introduced but the new code also appears a bit shaky and possibly more risky than the original solution. I raised #6989 to test the impact of changing Kryo serde which would help to get rid of the extra checks and casts.
However, if we want to advance the resolution of this bug that is independent of Kryo and the general refactoring I am wondering if we can replace:
ExprNodeDescUtils#andwithExprNodeDescUtils#conjunctionExprNodeDescUtils#orwithExprNodeDescUtils#disjunction
The latter seem to handle expression flattening and also the case where input is one operand. They don't remove duplicate expressions but this may not be necessary at this point.
| ExprNodeDesc combinedExpr = ExprNodeDescUtils.and(filterExpr, pruningExpr); | ||
| if (combinedExpr instanceof ExprNodeGenericFuncDesc combinedFuncExpr) { | ||
| filterExpr = combinedFuncExpr; | ||
| } |
There was a problem hiding this comment.
If the instanceof fails then we are going to ignore the pruningExpr. Not sure if its possible now but it may silently fail if something changes in the future.
| sjTargetTable.getConf() | ||
| .setFilterExpr((ExprNodeGenericFuncDesc) and(sjTargetTable.getConf().getFilterExpr(), sjPredicate)); |
There was a problem hiding this comment.
Requiring casts increases the risk of ClassCastException so the new code does not seem better.
| explain cbo select t1.id, t2.name, (case when (t1.id = 1 or t2.id = 1) then 'One' else null end) mycase | ||
| from mytable t1 join mytable t2 on t1.name = t2.name where t1.id = 1 and t2.id = 1; No newline at end of file |



HIVE-30201: UDFArgumentLengthException error while compiling the statement
What changes were proposed in this pull request?
As a part of HIVE-28911 some improvements done for
SEARCHoperator which involves the code changes inExprNodeConverter.visitCall(), AND/OR calls get converted withExprNodeDescUtils.and(args)/ExprNodeDescUtils.or(args)(to flatten nested ANDs/ORs produced by SearchTransformer). Those helpers internally useExprNodeDescUtils.split(...), which also removes duplicate operands (indexOf(current, splitted) < 0).So for the current query(mentioned in the JIRA issue),
AND(=(1, 1), =(1, 1))expression is flattened toAND(=(1,1))but AND/OR require at least two operands (GenericUDFOPAnd/Or#initialize enforces this) so throwingorg.apache.hadoop.hive.ql.exec.UDFArgumentLengthException.As a part of fix, without changing flattening logic, when the flattened AND/OR ends up with one operand, return that operand
directly (AND(x) == x, OR(x) == x).
Why are the changes needed?
To fix HIVE-28911 issue.
Does this PR introduce any user-facing change?
No
How was this patch tested?
Unit and q file tests are added.