dongjoon-hyun opened a new pull request, #60644:
URL: https://github.com/apache/spark/pull/60644
### What changes were proposed in this pull request?
This PR makes `StoredExpressionText.fixedConf` keep the session's value of
`spark.sql.timeType.enabled`, next to the session time zone, case sensitivity,
`spark.sql.timestampType` and `spark.sql.decimalOperations.allowPrecisionLoss`.
Every config that changes how a text reads still takes its default value.
It also lists the setting in the `StoredExpressionText.conf` Scaladoc and in
the Spark 4.4 migration guide entry of SPARK-60757, which names the settings
that follow the session of the write.
### Why are the changes needed?
`fixedConf` starts from `new SQLConf` and copies only the retained
resolution configs, ANSI mode and the settings above.
`spark.sql.timeType.enabled` is internal and has no binding policy, so it is
not retained, and it defaults to `Utils.isTesting`. Outside tests, the TIME
type is therefore always disabled under the fixed settings, even in a session
that enables it. Then `TimeExpression.checkInputDataTypes` and
`Cast.checkInputDataTypes` throw `UNSUPPORTED_TIME_TYPE`. The setting decides
whether the TIME type is supported, not how a text reads, so resetting it
protects nothing.
On `master`, a write to a Data Source V2 table with the
`GENERATE_COLUMN_VALUES_ON_WRITE` capability is affected when a generation
expression uses the TIME type:
- **SQL text**, such as `hour(t) + CAST(s AS INT)`: the analysis under the
fixed settings fails, so the write silently reads the text under its own
session. The expression does not get the reading of SPARK-60757. For example,
with `spark.sql.ansi.enabled=false` it stores `NULL`, where the same text
without `hour(t)` fails with `CAST_INVALID_INPUT`.
- **Modeled expression**, such as `CAST(s AS TIME(6))`: `analyzeStrict` has
no fallback, so both auto-fill and the validation of a provided value fail with
`INVALID_GENERATED_COLUMN_EXPRESSION`, caused by `UNSUPPORTED_TIME_TYPE`.
`CREATE TABLE` rejects a generation expression with the TIME type ("TIME
type is not supported in generated columns"). So, for generation expressions,
this affects only a table whose catalog exposes such a column, for example one
created through `TableCatalog.createTable`.
The following ran on `master` in a JVM where `Utils.isTesting` is false,
with `spark.sql.timeType.enabled=true`, `spark.sql.catalog.testcat` set to
`InMemoryCatalog`, and the tables created through `TableCatalog.createTable`.
```sql
-- sql_time: t TIME, s STRING, h INT GENERATED ALWAYS AS (hour(t) + CAST(s
AS INT))
SET spark.sql.ansi.enabled=false;
INSERT INTO testcat.sql_time (t, s) VALUES (TIME'12:34:56', 'x');
-- Issue 1: It should fail with CAST_INVALID_INPUT, as it does for
-- h INT GENERATED ALWAYS AS (CAST(s AS INT)), but it stores (12:34:56, x,
NULL).
-- modeled_time: s STRING, g TIME(6) with the modeled expression CAST(s AS
TIME(6))
SET spark.sql.ansi.enabled=true;
INSERT INTO testcat.modeled_time (s) VALUES ('12:34:56');
INSERT INTO testcat.modeled_time VALUES ('01:02:03', TIME'01:02:03');
-- Issue 2: They should store the rows, but both fail with
-- INVALID_GENERATED_COLUMN_EXPRESSION caused by UNSUPPORTED_TIME_TYPE.
```
### Does this PR introduce _any_ user-facing change?
Yes, within the unreleased `master` and `branch-4.x`, because SPARK-60757
and SPARK-61495 are not released yet. A write now reads a stored generation
expression that uses the TIME type under the fixed settings, like any other
generation expression. For SQL text, the write no longer falls back to its own
session. A modeled expression no longer fails. With this PR, the examples above
give:
```
sql_time: CAST_INVALID_INPUT
modeled_time: (12:34:56, 12:34:56), (01:02:03, 01:02:03)
```
Compared to Spark 4.3, the SPARK-60757 migration guide entry now covers
these expressions as well.
`spark.sql.legacy.useCurrentConfigsForGeneratedColumn` still reads SQL text
under the session of the write.
### How was this patch tested?
- Added a test to `GeneratedColumnWriteSuite`. It checks that the fixed
settings take the session value of `spark.sql.timeType.enabled` for both `true`
and `false`. A test cannot reproduce the production default, because
`Utils.isTesting` makes the setting `true`. The `false` case fails without this
fix.
- Ran the examples above before and after this fix in a JVM where
`Utils.isTesting` is false.
- Ran `GeneratedColumnExpressionSuite`, `GeneratedColumnWriteSuite` and
scalastyle.
apache/spark#60637 (SPARK-61893) reads table CHECK constraints under the
same fixed settings, and the TIME type is allowed there, for example `CHECK
(hour(start_t) BETWEEN 6 AND 22)`. It is still open. Whichever PR merges second
should also add `spark.sql.timeType.enabled` to the `Check.predicateSql()`
Javadoc and to the SPARK-61893 migration guide entry.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]