clintropolis commented on a change in pull request #10429:
URL: https://github.com/apache/druid/pull/10429#discussion_r494696636
##########
File path: core/src/main/java/org/apache/druid/math/expr/ExprType.java
##########
@@ -216,11 +226,44 @@ public static ExprType
functionAutoTypeConversion(@Nullable ExprType type, @Null
return STRING;
}
- return numericAutoTypeConversion(type, other);
+ return doubleNumericAutoTypeConversion(type, other);
}
+ /**
+ * Given 2 'input' types, choose the most appropriate combined type, if
possible
+ *
+ * arrays must be the same type
+ * if either type is {@link #STRING}, the output type will be preserved as
string
+ * any number will be coerced to {@link #LONG}
+ */
+ @Nullable
+ public static ExprType integerMathFunctionAutoTypeConversion(@Nullable
ExprType type, @Nullable ExprType other)
+ {
+ if (type == null || other == null) {
+ // cannot auto conversion unknown types
+ return null;
+ }
+ // arrays cannot be auto converted
+ if (isArray(type) || isArray(other)) {
+ if (!type.equals(other)) {
+ throw new IAE("Cannot implicitly cast %s to %s", type, other);
+ }
+ return type;
+ }
+ // if either argument is a string, type becomes a string
+ if (STRING.equals(type) || STRING.equals(other)) {
+ return STRING;
+ }
+
+ // any number is long
+ return LONG;
+ }
+
+ /**
+ * If both types are {@link #LONG}, returns {@link #LONG}, else {@link
#DOUBLE}
+ */
@Nullable
Review comment:
oops, will fix (this whole area in general needs some improvement, but I
think maybe will save for a future PR)
----------------------------------------------------------------
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]