soumyakanti3578 commented on code in PR #5494: URL: https://github.com/apache/hive/pull/5494#discussion_r1803801855
########## ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/jdbc/JDBCExpandExpressionsRule.java: ########## @@ -178,6 +177,9 @@ protected static class RexTransformIntoOrAndClause extends RexShuttle { @Override public RexNode visitCall(RexCall inputCall) { RexNode node = super.visitCall(inputCall); + if (!RexUtil.isFlat(node)) { + node = RexUtil.flatten(rexBuilder, node); + } Review Comment: I think this is the right place to flatten. This `visitCall(RexCall inputCall)` method will be called for all `RexCall`s in the expression recursively through `RexShuttle#visitList`. When `inputCall` is `OR(=($0, 0), IN(ROW($0, $2), ROW(1, 11), ROW(2, 22)))`, we will call `super.visitCall` on it, and then we will build `RexNode node` recursively, first `=($0, 0)`, then each of the `ROW`s, and then finally we will call this same method for `IN(ROW($0, $2), ROW(1, 11), ROW(2, 22))` down the line. Then we will go into the `case IN` and return `OR(AND(=($0, 1), =($2, 11)), AND(=($0, 2), =($2, 22)))` (but at this point the expr is flat), which will finally yield `OR(=($0, 0), OR(AND(=($0, 1), =($2, 11)), AND(=($0, 2), =($2, 22))))`, which is not flat. What I am trying to say is `RexNode node = super.visitCall(inputCall);` will be called recursively and it will build the expression bottom up. The expression returned by `transformIntoOrAndClause(rexBuilder, call);` will always be flat since it is just calling `rexBuilder.makeCall(SqlStdOperatorTable.OR, disjuncts)`, so we shouldn't call `RexUtil.flatten` in the `case IN` block. We should allow it to return, and then it will transform the parent expression, which will be the value present in the `node` of the stack above, and we need to flatten it if it is not flat. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org