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

[CALCITE-6252] BigQuery FORMAT_DATE uses the wrong calendar for Julian dates #3680

Merged
merged 1 commit into from
Feb 27, 2024

Conversation

mihaibudiu
Copy link
Contributor

This was much trickier to fix than I expected.
I think that it's because of some bugs in the Java Calendar/SimpleDateFormatter implementation.
Using the LocalDate class provides correct results.

I have also changed the return type of FORMAT_DATE from VARCHAR(2000) to VARCHAR, because it can really return results longer than 2000 characters, if the format string is long.

// The Calendar and SimpleDateFormatter do not seem to give correct results
// for the day of the week prior to the Julian to Gregorian date change.
// So we resort to using a LocalDate representation.
LocalDate ld =
Copy link
Contributor

Choose a reason for hiding this comment

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

Can use java.sql.Date directly?
((java.sql.Date) date).toLocalDate()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't know this trick, I will try it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it doesn't work, the subclass relationship goes the other way. sql.date extends util.date.
The calendar-based conversion seems to do the right thing and it's not too complicated.

final DateFormat eeeFormat = new SimpleDateFormat(DY.javaFmt, Locale.ROOT);
final DateFormat mmmFormat = new SimpleDateFormat(MON.javaFmt, Locale.ROOT);
final DateFormat mmmmFormat = new SimpleDateFormat(MONTH.javaFmt, Locale.ROOT);
final DateFormat eeeFormat = new SimpleDateFormat(DY.javaFmt, Locale.US);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why use Locale.US?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

SQL requires the output to be in English. Using Locale.ROOT gives the wrong result for the eeeeFormat at least (Mon instead of Monday).

Copy link
Member

Choose a reason for hiding this comment

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

It looks good to me

@@ -281,9 +301,9 @@ static Work get() {

/** Uses Locale.US instead of Locale.ROOT to fix formatting in Java 11 */
Copy link
Member

@caicancai caicancai Feb 11, 2024

Choose a reason for hiding this comment

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

Hello, Should we change or add comments here?

Copy link
Member

Choose a reason for hiding this comment

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

There are only Locale.ROOT comments here

Copy link
Member

@caicancai caicancai left a comment

Choose a reason for hiding this comment

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

LGTM

…n dates

Signed-off-by: Mihai Budiu <mbudiu@feldera.com>
@mihaibudiu mihaibudiu force-pushed the issue6252 branch 2 times, most recently from b202d5a to c3eeec9 Compare February 24, 2024 02:48
Copy link

sonarcloud bot commented Feb 24, 2024

@mihaibudiu mihaibudiu merged commit 3bce232 into apache:main Feb 27, 2024
17 checks passed
@mihaibudiu mihaibudiu deleted the issue6252 branch February 27, 2024 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants