liyafan82 commented on a change in pull request #2282:
URL: https://github.com/apache/calcite/pull/2282#discussion_r532346549
##########
File path: core/src/main/java/org/apache/calcite/rex/RexSimplify.java
##########
@@ -329,6 +336,93 @@ private RexNode simplifyGenericNode(RexCall e) {
return rexBuilder.makeCall(e.getType(), e.getOperator(), operands);
}
+ /**
+ * Try to find a literal with the given value in the input list.
+ */
+ private int findLiteralIndex(List<RexNode> operands, long value) {
+ for (int i = 0; i < operands.size(); i++) {
+ if (operands.get(i).isA(SqlKind.LITERAL)) {
+ Comparable comparable = ((RexLiteral) operands.get(i)).getValue();
+ if (comparable instanceof BigDecimal && ((BigDecimal)
comparable).longValue() == value) {
+ return i;
+ }
+ }
+ }
+ return -1;
+ }
+
+ private RexNode simplifyArithmetic(RexCall e) {
+ if (e.getType().getSqlTypeName().getFamily() != SqlTypeFamily.NUMERIC
+ || e.getOperands().stream()
+ .anyMatch(o -> e.getType().getSqlTypeName().getFamily() !=
SqlTypeFamily.NUMERIC)) {
+ // we only support simplifying numeric types
+ return simplifyGenericNode(e);
+ }
+
+ assert e.getOperands().size() == 2;
+
+ // if any operand is null, the result will be null
+ if (RexUtil.isNullLiteral(e.operands.get(0), true)
+ || RexUtil.isNullLiteral(e.operands.get(1), true)) {
+ return rexBuilder.makeNullLiteral(e.type);
+ }
Review comment:
Thanks for your feedback. It makes sense. This logic is removed.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]