xiedeyantu commented on code in PR #4512:
URL: https://github.com/apache/calcite/pull/4512#discussion_r2312736424
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlTimestampDiffFunction.java:
##########
@@ -112,4 +115,51 @@ private static RelDataType
inferReturnType2(SqlOperatorBinding opBinding) {
validator.validateTimeFrame(call.operand(0));
}
}
+
+ @Override public boolean checkOperandTypes(SqlCallBinding callBinding,
boolean throwOnFailure) {
+ // Coerce type first.
+ SqlValidator validator = callBinding.getValidator();
+ SqlCall call = callBinding.getCall();
+ int leftIndex = 1;
+ int rightIndex = 2;
+ if (call.operand(2) instanceof SqlIntervalQualifier) {
+ leftIndex = 0;
+ rightIndex = 1;
+ }
+
+ RelDataType left = callBinding.getOperandType(leftIndex);
+ RelDataType right = callBinding.getOperandType(rightIndex);
+
+ if (left.getSqlTypeName() == right.getSqlTypeName()) {
+ return super.checkOperandTypes(callBinding, throwOnFailure);
+ }
+ if (SqlTypeName.INTERVAL_TYPES.contains(right.getSqlTypeName())) {
+ return super.checkOperandTypes(callBinding, throwOnFailure);
+ }
+
+ if (left.getSqlTypeName() == SqlTypeName.DATE && right.getSqlTypeName() ==
SqlTypeName.TIME) {
+ // Subtraction between DATE and TIME; cast DATE operands to TIMESTAMP.
Review Comment:
I suggest that it might be better to move this comment above the if.
--
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]