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-47501][SQL] Add convertDateToDate like the existing convertTimestampToTimestamp for JdbcDialect #45638

Closed
wants to merge 1 commit into from

Conversation

yaooqinn
Copy link
Member

What changes were proposed in this pull request?

Add convertDateToDate like the existing convertTimestampToTimestamp for JdbcDialect

Why are the changes needed?

The date '±infinity' values cause overflows like timestamp '±infinity' in #41843

Does this PR introduce any user-facing change?

fix expected overflow for dates to align with the timestamps of PostgreSQL

How was this patch tested?

new tests

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

no

@github-actions github-actions bot added the SQL label Mar 21, 2024
@@ -307,24 +307,23 @@ private object PostgresDialect extends JdbcDialect with SQLConfHelper {
override def convertJavaTimestampToTimestamp(t: Timestamp): Timestamp = {
// Variable names come from PostgreSQL "constant field docs":
// https://jdbc.postgresql.org/documentation/publicapi/index.html?constant-values.html
val POSTGRESQL_DATE_NEGATIVE_INFINITY = -9223372036832400000L
val POSTGRESQL_DATE_NEGATIVE_SMALLER_INFINITY = -185543533774800000L
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*_SMALLER_INFINITYs are for PgResultSet to identify date infinities internally, they are supplanted with the larger abs-values to clients

@yaooqinn
Copy link
Member Author

cc @cloud-fan @dongjoon-hyun @mingkangli-db, thanks

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, LGTM. Merged to master.

@yaooqinn
Copy link
Member Author

Thank you @dongjoon-hyun

@yaooqinn yaooqinn deleted the SPARK-47501 branch March 21, 2024 15:00
* @return the date value after conversion
*/
@Since("4.0.0")
def convertDateToDate(d: Date): Date = d
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for name consistency, should this be convertJavaDateToDate?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, thanks. +1 for the above new name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for being so careful. And sorry for my carelessness

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix my mistake, I sent #45656. Please help review when you have some time

sweisdb pushed a commit to sweisdb/spark that referenced this pull request Apr 1, 2024
…estampToTimestamp for JdbcDialect

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

Add convertDateToDate like the existing convertTimestampToTimestamp for JdbcDialect

### Why are the changes needed?

The date '±infinity' values cause overflows like timestamp '±infinity' in apache#41843

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

fix expected overflow for dates to align with the timestamps of PostgreSQL

### How was this patch tested?
new tests

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

no

Closes apache#45638 from yaooqinn/SPARK-47501.

Authored-by: Kent Yao <yao@apache.org>
Signed-off-by: Dongjoon Hyun <dhyun@apple.com>
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.

3 participants