kasakrisz commented on code in PR #4237:
URL: https://github.com/apache/hive/pull/4237#discussion_r1168377479


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/calcite/rules/HivePointLookupOptimizerRule.java:
##########
@@ -669,6 +670,22 @@ private static RexNode handleAND(RexBuilder rexBuilder, 
RexCall call) {
       return RexUtil.composeConjunction(rexBuilder, newOperands, false);
     }
 
+    private static void retainAll(Collection<RexNode> elementsToRetain, 
Collection<RexNode> collection) {
+      collection.removeIf(rexNode -> elementsToRetain.stream().noneMatch(
+              rexNodeToRetain -> equalsWithSimilarType(rexNode, 
rexNodeToRetain)));
+    }
+
+    private static boolean equalsWithSimilarType(RexNode rexNode1, RexNode 
rexNode2) {
+      if (!(rexNode1 instanceof RexLiteral) || !(rexNode2 instanceof 
RexLiteral)) {
+        return rexNode1.equals(rexNode2);
+      }
+
+      RexLiteral rexLiteral1 = (RexLiteral) rexNode1;
+      RexLiteral rexLiteral2 = (RexLiteral) rexNode2;
+      return rexLiteral1.getValue().compareTo(rexLiteral2.getValue()) == 0 &&
+              
rexLiteral1.getType().getSqlTypeName().equals(rexLiteral2.getType().getSqlTypeName());

Review Comment:
   `SqlTypeName` comparison is used in two methods:
   * `shareSameType`: used for checking whether all constants in both 
collections are has the same sql type.
   * `retainAll`: removes all elements from the 2nd collection which is not 
present in the first one. The original `collection.retainAll` method uses the 
`Object.equals` method for comparing elements but in this case it is too strict 
and this customization of the method uses the `equalsWithSimilarType`.
   
   I can combine the two but it would result a 20-30 lines code with nested 
loops harder to understand.
   
   If your concern is performance we are comparing Enum constants here it 
should be fast.
   
https://github.com/apache/calcite/blob/68b02dfd4af15bc94a91a0cd2a30655d04439555/core/src/main/java/org/apache/calcite/sql/type/SqlTypeName.java#L52
   



-- 
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]

Reply via email to