soma-mondal commented on a change in pull request #1437: [CALCITE-3318]
Preserving CAST of STRING operands in comparison operator
URL: https://github.com/apache/calcite/pull/1437#discussion_r336386361
##########
File path:
core/src/main/java/org/apache/calcite/sql/dialect/BigQuerySqlDialect.java
##########
@@ -99,6 +103,14 @@ public BigQuerySqlDialect(SqlDialect.Context context) {
return emulateNullDirectionWithIsNull(node, nullsFirst, desc);
}
+ @Override public boolean supportsImplicitTypeCoercion(RexCall node) {
+ if (!super.supportsImplicitTypeCoercion(node)) {
+ return false;
+ }
+ RexNode operand = node.getOperands().get(0);
+ return operand instanceof RexLiteral &&
!SqlTypeFamily.NUMERIC.contains(node.type);
+ }
+
Review comment:
From the stripCastFromString method we are passing only the operands that
has explicit cast applied. So it can be any of the operands. Now, the above
code means, we can strip the cast for BigQuery if :
- The RexNode on which we have applied the cast is a STRING LITERAL.
- We are trying to cast it to anything apart from NUMERIC type.
We are not comparing between datatypes of operands of the comparison
operators.
I have checked the type coercion rules for the above conditions you have
mentioned (except IS NOT DISTINCT FROM, BiqQuery doesn't have this operator
yet) . This is my observation, you can check this
[sheet](https://docs.google.com/spreadsheets/d/1GJ_VuDY7GQS-aPbWf4EKj73dYCqaRaEqPTjmXLkPW_g/edit#gid=0)
.
For example,
hire_date = '1996-01-01 00:00:00' is valid in BiqQuery. But,
hire_date = concat('1996-01-01 ','00:00:00') is not valid. Need casting.
(hire_date is a TIMESTAMP column here)
and
For Numeric datatype,
employee_id = '10' not valid
employee_id = concat('1','2') not valid
10 = '10' is not valid.
----------------------------------------------------------------
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]
With regards,
Apache Git Services