https://github.com/apache/spark
Revision d7534a3ec1eab53bbd349f9ae31684337c734958 authored by Aleksandar Tomic on 21 December 2023, 07:58:15 UTC, committed by Wenchen Fan on 21 December 2023, 08:00:09 UTC
With this PR proposal is to do inline table resolution in two phases:
1) If there are no expressions that depend on current context (e.g. expressions that depend on CURRENT_DATABASE, CURRENT_USER, CURRENT_TIME etc.) they will be evaluated as part of ResolveInlineTable rule.
2) Expressions that do depend on CURRENT_* evaluation will be kept as expressions and they evaluation will be delayed to post analysis phase.

This PR aims to solve two problems with inline tables.

Example1:
```sql
SELECT COUNT(DISTINCT ct) FROM VALUES
(CURRENT_TIMESTAMP()),
(CURRENT_TIMESTAMP()),
(CURRENT_TIMESTAMP()) as data(ct)
```
Prior to this change this example would return 3 (i.e. all CURRENT_TIMESTAMP expressions would return different value since they would be evaluated individually as part of inline table evaluation). After this change result is 1.

Example 2:
```sql
CREATE VIEW V as (SELECT * FROM VALUES(CURRENT_TIMESTAMP())
```
In this example VIEW would be saved with literal evaluated during VIEW creation. After this change CURRENT_TIMESTAMP() will eval during VIEW execution.

See section above.

New test that validates this behaviour is introduced.

No.

Closes #44316 from dbatomic/inline_tables_curr_time_fix.

Lead-authored-by: Aleksandar Tomic <aleksandar.tomic@databricks.com>
Co-authored-by: Aleksandar Tomic <150942779+dbatomic@users.noreply.github.com>
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
(cherry picked from commit 5fe963f8560ef05925d127e82ab7ef28d6a1d7bc)
Signed-off-by: Wenchen Fan <wenchen@databricks.com>
1 parent 0c00c54
History
Tip revision: d7534a3ec1eab53bbd349f9ae31684337c734958 authored by Aleksandar Tomic on 21 December 2023, 07:58:15 UTC
[SPARK-46380][SQL] Replace current time/date prior to evaluating inline table expressions
Tip revision: d7534a3

README.md

back to top