[ 
https://issues.apache.org/jira/browse/CALCITE-7271?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18035772#comment-18035772
 ] 

Thomas Rebele commented on CALCITE-7271:
----------------------------------------

Depending on how this ticket is solved, it might make sense to add a test case 
to RexProgramTest. Something like this (I took a quick look how to create a 
safe cast, but couldn't find out how):
{code:java}
RelDataType nullableIntType = 
nullable(typeFactory.createSqlType(SqlTypeName.INTEGER));

checkSimplify(
    plus("safeCast"(nullInt, nullableIntType),
        "safeCast"(vVarchar(0), nullableIntType)),
    "null:INTEGER");

checkSimplify(
    isNull(plus("safeCast"(nullInt, nullableIntType),
        "safeCast"(vVarchar(0), nullableIntType))),
    "true");
{code}

> Prevent unsafe CAST pushdown in Druid
> -------------------------------------
>
>                 Key: CALCITE-7271
>                 URL: https://issues.apache.org/jira/browse/CALCITE-7271
>             Project: Calcite
>          Issue Type: Bug
>          Components: druid-adapter
>            Reporter: Stamatis Zampetakis
>            Priority: Minor
>
> Most of SQL queries are using the standard CAST operator that is unsafe and 
> should throw an error when the conversion is invalid. However, the [CAST 
> operation in 
> Druid|https://druid.apache.org/docs/latest/querying/sql-data-types/#standard-types]
>  returns null instead of throwing an error when the operation fails.
> Currently the Druid adapter ignores the "error handling" discrepancies of the 
> CAST operator when pushing down such expressions. Ideally, to avoid altering 
> the semantics of the query the regular CAST should not be pushed to Druid.
> SQL queries can use the SAFE_CAST operator instead of the standard CAST 
> operator and this can be pushed safely to Druid since the semantics are the 
> same with those offered by the engine.
> The 
> [DruidSqlCastConverter|https://github.com/apache/calcite/blob/8b5c17e51e0c9c3f8e3db17c8d449e67e4e2974a/druid/src/main/java/org/apache/calcite/adapter/druid/DruidSqlCastConverter.java]
>  and potentially other classes may need modifications to handle/push the CAST 
> variations properly in Druid.
> Related testcase: DruidAdapter2IT#testComplexExpressionsIsNull



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to