[
https://issues.apache.org/jira/browse/SPARK-60451?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
ASF GitHub Bot updated SPARK-60451:
-----------------------------------
Labels: pull-request-available (was: )
> Cast.contextIndependentFoldable is true for a special datetime string cast to
> DATE or TIMESTAMP_NTZ
> ---------------------------------------------------------------------------------------------------
>
> Key: SPARK-60451
> URL: https://issues.apache.org/jira/browse/SPARK-60451
> Project: Spark
> Issue Type: Bug
> Components: SQL
> Affects Versions: 5.0.0
> Reporter: Yang Jie
> Priority: Major
> Labels: pull-request-available
>
> Cast.contextIndependentFoldable decides from the types alone
> (Cast.scala:716-718). A string cast to DATE or TIMESTAMP_NTZ needs no time
> zone, so it counts as foldable without external context. But a special
> datetime value such as 'today', 'now' or 'epoch' is replaced only by the
> optimizer rule SpecialDatetimeValues, and an ordinary Cast.eval does not know
> it.
> V2ExpressionBuilder folds every contextIndependentFoldable sub-expression, so
> building a V2 expression from an analyzed expression evaluates such a cast as
> an ordinary cast. On a V2 catalog:
> {noformat}
> CREATE TABLE t (id INT, d DATE, CONSTRAINT c CHECK (d <= CAST('today' AS
> DATE)));
> -- ANSI on: fails with CAST_INVALID_INPUT
> -- ANSI off: stores the predicate d <= NULL, so INSERT INTO t VALUES (1,
> DATE'9999-12-31') passes
> CREATE TABLE t (id INT, d DATE DEFAULT CAST('today' AS DATE));
> -- ANSI on: fails with CAST_INVALID_INPUT
> -- ANSI off: INSERT INTO t(id) VALUES (1) writes NULL instead of the current
> date
> {noformat}
> The implicit cast in CHECK (d <= 'today') behaves the same. REPLACE TABLE
> converts its constraints the same way as CREATE TABLE, and
> GeneratedColumnExpression.toV2 runs the same builder on its analyzed
> expression.
> A fix could make contextIndependentFoldable false for a foldable string child
> whose value is a special datetime value. DateTimeUtils.extractSpecialValue
> recognizes these values; it is private now.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]