Skip to content

Bugfix: Timestamps sometimes converted to Dates in legacy engine #3613

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Swiddis
Copy link
Collaborator

@Swiddis Swiddis commented May 8, 2025

Description

Another Legacy-V2 mismatch issue, something in Legacy sometimes converts timestamps to dates, causing prod breakage for some JDBC users. I couldn't find the root cause of the inconsistent conversion, so I just threw a hack on Protocol instead. (By my understanding, Protocol is only called in Legacy.)

We should be able to remove all this when Calcite happens.

I invite reviewers to find a better way to do this.

Related Issues

Resolves #1545
Resolves #3159

Check List

  • New functionality includes testing.
  • New functionality has been documented.
  • New functionality has javadoc added.
  • New functionality has a user manual doc added.
  • API changes companion pull request created.
  • Commits are signed per the DCO using --signoff.
  • Public documentation issue/PR created.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@@ -3,6 +3,6 @@
{"index":{"_id":"2"}}
{"login_time":"2015-01-01T12:10:30Z"}
{"index":{"_id":"3"}}
{"login_time":"1585882955"}
{"login_time":"1585882955000"}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I found while writing the reproducers that this was getting parsed as milliseconds instead of seconds, despite the magnitude. That gets sent to January 19, 1970 instead of (probably intended) April 3, 2020. I decided to update the row.

Signed-off-by: Simeon Widdis <[email protected]>
@Swiddis Swiddis added legacy Issues related to legacy query engine to be deprecated backport 2.x backport 2.19 labels May 8, 2025
// breakage for consumers like JDBC. Until Calcite's done and we can delete legacy, just reset
// the type.
String t = column.getType();
if (t.equals("date")) {
Copy link
Member

Choose a reason for hiding this comment

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

Is it always true that we need to convert date to timestamp?

Copy link
Collaborator Author

@Swiddis Swiddis May 8, 2025

Choose a reason for hiding this comment

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

Probably not, but I haven't figured out the smart way to do this. It's better to overconvert to timestamp than underconvert since date has less info according to JDBC.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Passes all the tests, so if there's a case where overconverting causes issues, it isn't tracked

Copy link
Collaborator

Choose a reason for hiding this comment

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

So the hack is to replace the column type name only, but the value is not touched?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You can see in the bug reports that even when the column was date, the value still holds time information, so it's sufficient to just rename the column.

@@ -0,0 +1,8 @@
{"index":{"_id":"1"}}
Copy link
Collaborator

Choose a reason for hiding this comment

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

leverage YamlRestTest in future, avoid unncessary mapping and data files.

// TODO currently out of scope due to V1/V2 engine feature mismatch. Should be fixed with Calcite.
@Test
@Ignore
public void joinTimestampComparison() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

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

have u try enable calcite, issue still exist?

Copy link
Collaborator

@dai-chen dai-chen left a comment

Choose a reason for hiding this comment

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

Does this previous PR linked in the issue indicate any root cause or better fix? #3160

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x backport 2.19 bug Something isn't working legacy Issues related to legacy query engine to be deprecated SQL
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] timestamp data type handling is inconsistent [BUG] Inconsistent behaviour for date field in nested collection queries
4 participants