[ 
https://issues.apache.org/jira/browse/CALCITE-6762?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

xiaochen.zhou updated CALCITE-6762:
-----------------------------------
    Description: 
In Calcite, if the dialect's `supportsImplicitTypeCoercion` is set to `true` 
(the default value is `true`), Calcite will remove the cast in the 
`SqlImplementor#stripCastFromString()` method. For example, the following SQL:

```
FROM applydata_bigdata.kafka_topic_cluster_user_dept_month_one_day_msg_info
WHERE ymd > CAST('20240801' AS INTEGER)
ORDER BY ymd DESC
```

will be transformed into:

```
FROM 
"hive"."applydata_bigdata"."kafka_topic_cluster_user_dept_month_one_day_msg_info"
WHERE "ymd" > '20240801'
ORDER BY "ymd" IS NULL DESC, "ymd" DESC LIMIT 200
```

Here, the `CAST` is removed.

However, in Presto, different data types cannot be directly compared, which 
will result in an error. 

!image-2025-01-05-02-16-32-718.png!

To avoid this issue, `supportsImplicitTypeCoercion` should be set to `false` in 
`PrestoSqlDialect`.

> Preserving the CAST conversion for operands in Presto




> ---------------------------------------------------------
>
>                 Key: CALCITE-6762
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6762
>             Project: Calcite
>          Issue Type: Improvement
>            Reporter: xiaochen.zhou
>            Priority: Major
>         Attachments: image-2025-01-05-02-16-32-718.png
>
>
> In Calcite, if the dialect's `supportsImplicitTypeCoercion` is set to `true` 
> (the default value is `true`), Calcite will remove the cast in the 
> `SqlImplementor#stripCastFromString()` method. For example, the following SQL:
> ```
> FROM applydata_bigdata.kafka_topic_cluster_user_dept_month_one_day_msg_info
> WHERE ymd > CAST('20240801' AS INTEGER)
> ORDER BY ymd DESC
> ```
> will be transformed into:
> ```
> FROM 
> "hive"."applydata_bigdata"."kafka_topic_cluster_user_dept_month_one_day_msg_info"
> WHERE "ymd" > '20240801'
> ORDER BY "ymd" IS NULL DESC, "ymd" DESC LIMIT 200
> ```
> Here, the `CAST` is removed.
> However, in Presto, different data types cannot be directly compared, which 
> will result in an error. 
> !image-2025-01-05-02-16-32-718.png!
> To avoid this issue, `supportsImplicitTypeCoercion` should be set to `false` 
> in `PrestoSqlDialect`.



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

Reply via email to