rubenada commented on a change in pull request #2555:
URL: https://github.com/apache/calcite/pull/2555#discussion_r718702589



##########
File path: 
core/src/main/java/org/apache/calcite/sql/type/SqlTypeCoercionRule.java
##########
@@ -202,7 +202,8 @@ private SqlTypeCoercionRule(Map<SqlTypeName, 
ImmutableSet<SqlTypeName>> map) {
         coerceRules.copyValues(SqlTypeName.BOOLEAN)
             .add(SqlTypeName.CHAR)
             .add(SqlTypeName.VARCHAR)
-            .addAll(SqlTypeName.NUMERIC_TYPES)
+            .addAll(SqlTypeName.INT_TYPES)
+            .addAll(SqlTypeName.APPROX_TYPES)

Review comment:
       `SqlTypeName.APPROX_TYPES` include `FLOAT`, `REAL` and `DOUBLE`. Are we 
sure casting these types into boolean always work?
   It's strange, it seems that `SELECT CAST(CAST(0 AS float) AS BOOLEAN)` works 
fine (returns `false`). But if we try a more "complex" query: `select 
cast(cast(p0 as float) as boolean) from (values (0)) as t(p0)` ; it will fail 
at runtime with `CompileException: Line 21, Column 31: Cannot cast "double" to 
"boolean"`.
   This type of query will be generated if we add these tests into 
`SqlOperatorBaseTest#testCastToBoolean`:
   ```
   tester.checkBoolean("cast(cast(0 as float) as boolean)", Boolean.FALSE);
   tester.checkBoolean("cast(cast(0 as real) as boolean)", Boolean.FALSE);
   tester.checkBoolean("cast(cast(0 as double) as boolean)", Boolean.FALSE);
   ```
   which, if I am not mistaken, will fail if we add them to 
`SqlOperatorBaseTest#testCastToBoolean`. Therefore, perhaps we should consider 
`FLOAT`, `REAL` and `DOUBLE` (together with `DECIMAL`) as non-castable into 
boolean?




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


Reply via email to