Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARK-50870][SQL] Add the timezone when casting to timestamp in V2ScanRelationPushDown #49549

Closed
wants to merge 4 commits into from

Conversation

changgyoopark-db
Copy link
Contributor

What changes were proposed in this pull request?

Add the timezone information to a cast expression when the destination type requires it.

Why are the changes needed?

When current_timestamp() is materialized as a string, the timezone information is gone (e.g., 2024-12-27 10:26:27.684158) which prohibits further optimization rules from being applied to the affected data source.

For example,

Project [1735900357973433#10 AS current_timestamp()#6]
+- 'Project [cast(2025-01-03 10:32:37.973433#11 as timestamp) AS 1735900357973433#10]
   +- RelationV2[2025-01-03 10:32:37.973433#11] xxx

-> This query fails to execute because the injected cast expression lacks the timezone information.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Existing tests.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions bot added the SQL label Jan 17, 2025
@changgyoopark-db
Copy link
Contributor Author

@cloud-fan FYI

@MaxGekk MaxGekk changed the title [SPARK-50870][CORE] Add the timezone when casting to timestamp in V2ScanRelationPushDown [SPARK-50870][SQL] Add the timezone when casting to timestamp in V2ScanRelationPushDown Jan 20, 2025
@MaxGekk
Copy link
Member

MaxGekk commented Jan 20, 2025

This query fails to execute because the injected cast expression lacks the timezone information

BTW, @changgyoopark-db can you add a test for the case?

@cloud-fan
Copy link
Contributor

After v2 filter translation, ideally v2 sources won't evaluate the Spark Cast directly. I think it's only a problem for advanced Spark users who customize the V2ScanRelationPushDown rule. It's only a potential bug and I think it's fine to merge without a test.

Thanks, merging to master/4.0/3.5!

@cloud-fan cloud-fan closed this in 24abb0f Jan 21, 2025
cloud-fan pushed a commit that referenced this pull request Jan 21, 2025
…anRelationPushDown

### What changes were proposed in this pull request?

Add the timezone information to a cast expression when the destination type requires it.

### Why are the changes needed?

When current_timestamp() is materialized as a string, the timezone information is gone (e.g., 2024-12-27 10:26:27.684158) which prohibits further optimization rules from being applied to the affected data source.

For example,

```
Project [1735900357973433#10 AS current_timestamp()#6]
+- 'Project [cast(2025-01-03 10:32:37.973433#11 as timestamp) AS 1735900357973433#10]
   +- RelationV2[2025-01-03 10:32:37.973433#11] xxx
```

-> This query fails to execute because the injected cast expression lacks the timezone information.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Existing tests.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #49549 from changgyoopark-db/SPARK-50870.

Authored-by: changgyoopark-db <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit 24abb0f)
Signed-off-by: Wenchen Fan <[email protected]>
cloud-fan pushed a commit that referenced this pull request Jan 21, 2025
…anRelationPushDown

### What changes were proposed in this pull request?

Add the timezone information to a cast expression when the destination type requires it.

### Why are the changes needed?

When current_timestamp() is materialized as a string, the timezone information is gone (e.g., 2024-12-27 10:26:27.684158) which prohibits further optimization rules from being applied to the affected data source.

For example,

```
Project [1735900357973433#10 AS current_timestamp()#6]
+- 'Project [cast(2025-01-03 10:32:37.973433#11 as timestamp) AS 1735900357973433#10]
   +- RelationV2[2025-01-03 10:32:37.973433#11] xxx
```

-> This query fails to execute because the injected cast expression lacks the timezone information.

### Does this PR introduce _any_ user-facing change?

No.

### How was this patch tested?

Existing tests.

### Was this patch authored or co-authored using generative AI tooling?

No.

Closes #49549 from changgyoopark-db/SPARK-50870.

Authored-by: changgyoopark-db <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit 24abb0f)
Signed-off-by: Wenchen Fan <[email protected]>
@changgyoopark-db changgyoopark-db deleted the SPARK-50870 branch January 21, 2025 06:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants