-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,12 +303,27 @@ 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, QUARTER, YEAR, DAY are identical on postgres and spark | ||
| // MONTH is different, postgres returns 0-11, spark returns 1-12. | ||
|
||
| // Postgres also returns 1-12 but just for interval columns, so without source | ||
| // data type, we cannot know how to push down it | ||
|
||
| // 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 calendar year are actually past year | ||
| // by ISO standard of week counting, 1st january is actually 52nd week of year | ||
| val postgresField = field match { | ||
| case "MONTH" => throw new UnsupportedOperationException("Month is not currently supported") | ||
| 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 = { | ||
|
|
||

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.