-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-49756][SQL][FOLLOWUP] Use correct pgsql datetime fields when pushing down EXTRACT #50101
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,12 +303,24 @@ private case class PostgresDialect() | |
|
|
||
| class PostgresSQLBuilder extends JDBCSQLBuilder { | ||
| override def visitExtract(field: String, source: String): String = { | ||
| field match { | ||
| case "DAY_OF_YEAR" => s"EXTRACT(DOY FROM $source)" | ||
| case "YEAR_OF_WEEK" => s"EXTRACT(YEAR FROM $source)" | ||
| case "DAY_OF_WEEK" => s"EXTRACT(DOW FROM $source)" | ||
| case _ => super.visitExtract(field, source) | ||
| // SECOND, MINUTE, HOUR, DAY, MONTH, QUARTER, YEAR are identical on postgres and spark for | ||
| // both datetime and interval types. | ||
| // DAY_OF_WEEK is DOW, day of week is full compatible with postgres, | ||
| // but in V2ExpressionBuilder they converted DAY_OF_WEEK to DAY_OF_WEEK_ISO, | ||
| // so we need to push down ISODOW | ||
| // (ISO and standard day of weeks differs in starting day, | ||
| // Sunday is 0 on standard DOW extraction, while in ISO it's 7) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Thank you for the explanation. |
||
| // DAY_OF_YEAR have same semantic, but different name (On postgres, it is DOY) | ||
| // WEEK is a little bit specific function, but both spark and postgres uses ISO week | ||
| // YEAR_OF_WEEK is ISO year actually. First few days of a calendar year can belong to the | ||
| // past year by ISO standard of week counting. | ||
| val postgresField = field match { | ||
| case "DAY_OF_WEEK" => "ISODOW" | ||
| case "DAY_OF_YEAR" => "DOY" | ||
| case "YEAR_OF_WEEK" => "ISOYEAR" | ||
| case _ => field | ||
| } | ||
| super.visitExtract(postgresField, source) | ||
| } | ||
|
|
||
| override def visitBinaryArithmetic(name: String, l: String, r: String): String = { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A better idea is probably having a test infra that automatically checks the result between JDBC pushdown on and off. I'll leave it to followups.