mdayakar commented on code in PR #6082:
URL: https://github.com/apache/hive/pull/6082#discussion_r2361839492
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java:
##########
@@ -659,14 +658,17 @@ private static RexNode handleAND(RexBuilder rexBuilder,
RexCall call) {
} else {
inLHSExprToRHSExprs.put(c.exprNode, new
SimilarRexNodeElement(c.constNode));
}
- operands.remove(i);
- --i;
+ ++eqExpressionCount;
+ } else {
+ newOperands.add(operand);
}
}
+ if (inExpressionCount + eqExpressionCount ==
inLHSExprToRHSExprs.keySet().size()) {
Review Comment:
Here why can't we use `inLHSExprToRHSExprs .size()` instead of
`inLHSExprToRHSExprs.keySet().size()`?
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java:
##########
@@ -599,15 +599,15 @@ private static RexNode handleAND(RexBuilder rexBuilder,
RexCall call) {
// into a null value.
final Multimap<RexNode,RexNode> inLHSExprToRHSNullableExprs =
LinkedHashMultimap.create();
final List<RexNode> operands = new
ArrayList<>(RexUtil.flattenAnd(call.getOperands()));
-
- for (int i = 0; i < operands.size(); i++) {
- RexNode operand = operands.get(i);
- if (operand instanceof RexCall && HiveIn.INSTANCE.equals(((RexCall)
operand).op)) {
- RexCall inCall = (RexCall) operand;
- if (!HiveCalciteUtil.isDeterministic(inCall.getOperands().get(0))) {
+ final List<RexNode> newOperands = new ArrayList<>(operands.size());
+ int inExpressionCount = 0;
+ int eqExpressionCount = 0;
+ for (RexNode operand : operands) {
+ if (operand instanceof RexCall inCall &&
HiveIn.INSTANCE.equals(inCall.op)) {
+ if
(!HiveCalciteUtil.isDeterministic(inCall.getOperands().getFirst())) {
continue;
}
- RexNode ref = inCall.getOperands().get(0);
+ RexNode ref = inCall.getOperands().getFirst();
Review Comment:
`RexNode ref = inCall.getOperands().getFirst();` local variable creation can
be moved up to
[607](https://github.com/apache/hive/pull/6082/files#diff-0400ba8e7a318a20ac5a3abdb58ab1d639813cd5212a64bf108898929035b4e0R607)
line so that it can be used there also.
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java:
##########
@@ -734,26 +736,30 @@ private static boolean shareSameType(
private static RexNode handleOR(RexBuilder rexBuilder, RexCall call) {
// IN clauses need to be combined by keeping all elements
final List<RexNode> operands = new
ArrayList<>(RexUtil.flattenOr(call.getOperands()));
+ final List<RexNode> newOperands = new ArrayList<>(operands.size());
final Multimap<RexNode,SimilarRexNodeElement> inLHSExprToRHSExprs =
LinkedHashMultimap.create();
- for (int i = 0; i < operands.size(); i++) {
- RexNode operand = operands.get(i);
- if (operand instanceof RexCall && HiveIn.INSTANCE.equals(((RexCall)
operand).op)) {
- RexCall inCall = (RexCall) operand;
- if (!HiveCalciteUtil.isDeterministic(inCall.getOperands().get(0))) {
+ int inExpressionCount = 0;
+ for (RexNode operand : operands) {
+ if (operand instanceof RexCall inCall &&
HiveIn.INSTANCE.equals(inCall.op)) {
+ if
(!HiveCalciteUtil.isDeterministic(inCall.getOperands().getFirst())) {
continue;
}
- RexNode ref = inCall.getOperands().get(0);
+ RexNode ref = inCall.getOperands().getFirst();
Review Comment:
Here also `RexNode ref = inCall.getOperands().getFirst();` can be moved up
so that it can be used in the `if
(!HiveCalciteUtil.isDeterministic(inCall.getOperands().getFirst()))` check.
##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java:
##########
@@ -734,26 +736,30 @@ private static boolean shareSameType(
private static RexNode handleOR(RexBuilder rexBuilder, RexCall call) {
// IN clauses need to be combined by keeping all elements
final List<RexNode> operands = new
ArrayList<>(RexUtil.flattenOr(call.getOperands()));
+ final List<RexNode> newOperands = new ArrayList<>(operands.size());
final Multimap<RexNode,SimilarRexNodeElement> inLHSExprToRHSExprs =
LinkedHashMultimap.create();
- for (int i = 0; i < operands.size(); i++) {
- RexNode operand = operands.get(i);
- if (operand instanceof RexCall && HiveIn.INSTANCE.equals(((RexCall)
operand).op)) {
- RexCall inCall = (RexCall) operand;
- if (!HiveCalciteUtil.isDeterministic(inCall.getOperands().get(0))) {
+ int inExpressionCount = 0;
+ for (RexNode operand : operands) {
+ if (operand instanceof RexCall inCall &&
HiveIn.INSTANCE.equals(inCall.op)) {
+ if
(!HiveCalciteUtil.isDeterministic(inCall.getOperands().getFirst())) {
continue;
}
- RexNode ref = inCall.getOperands().get(0);
+ RexNode ref = inCall.getOperands().getFirst();
for (int j = 1; j < inCall.getOperands().size(); j++) {
inLHSExprToRHSExprs.put(ref, new
SimilarRexNodeElement(inCall.getOperands().get(j)));
}
- operands.remove(i);
- --i;
+ ++inExpressionCount;
+ } else {
+ newOperands.add(operand);
}
}
+ if (inExpressionCount == inLHSExprToRHSExprs.keySet().size()) {
Review Comment:
Here also, `inLHSExprToRHSExprs.size()` can be used instead of
`inLHSExprToRHSExprs.keySet().size()`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]