You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Dongjoon Hyun (Jira)" <ji...@apache.org> on 2023/12/27 19:43:00 UTC

[jira] [Resolved] (SPARK-46502) Support timestamp types in UnwrapCastInBinaryComparison

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

Dongjoon Hyun resolved SPARK-46502.
-----------------------------------
    Fix Version/s: 4.0.0
       Resolution: Fixed

Issue resolved by pull request 44480
[https://github.com/apache/spark/pull/44480]

> Support timestamp types in UnwrapCastInBinaryComparison
> -------------------------------------------------------
>
>                 Key: SPARK-46502
>                 URL: https://issues.apache.org/jira/browse/SPARK-46502
>             Project: Spark
>          Issue Type: Improvement
>          Components: SQL
>    Affects Versions: 4.0.0
>            Reporter: L. C. Hsieh
>            Assignee: L. C. Hsieh
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 4.0.0
>
>
> We have an optimization rule `UnwrapCastInBinaryComparison` that handles similar cases but it doesn't cover timestamp types.
> For a query plan like
> ```
> == Analyzed Logical Plan ==
> batch: timestamp
> Project [batch#26466]
> +- Filter (batch#26466 >= cast(2023-12-21 10:00:00 as timestamp))
>    +- SubqueryAlias spark_catalog.default.timestamp_view
>       +- View (`spark_catalog`.`default`.`timestamp_view`, [batch#26466])
>          +- Project [cast(batch#26467 as timestamp) AS batch#26466]
>             +- Project [cast(batch#26463 as timestamp) AS batch#26467]
>                +- SubqueryAlias spark_catalog.default.table_timestamp
>                   +- Relation spark_catalog.default.table_timestamp[batch#26463] parquet
> == Optimized Logical Plan ==
> Project [cast(batch#26463 as timestamp) AS batch#26466]
> +- Filter (isnotnull(batch#26463) AND (cast(batch#26463 as timestamp) >= 2023-12-21 10:00:00))
>    +- Relation spark_catalog.default.table_timestamp[batch#26463] parquet
> ```
> The predicate compares a timestamp_ntz column with a literal value. As the column is wrapped in a cast expression to timestamp type, the literal (string) is wrapped with a cast to timestamp type. The literal with cast is foldable so it is evaluated to literal of timestamp earlier. So the predicate becomes `cast(batch#26463 as timestamp) >= 2023-12-21 10:00:00`. As the cast is in column side, it cannot be pushed down to data source/table.



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

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org