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

Timestamp milliseconds wrongly interpreted if milliseconds start with zeros #175

Open
mirafranc opened this issue Nov 10, 2020 · 1 comment · May be fixed by #177
Open

Timestamp milliseconds wrongly interpreted if milliseconds start with zeros #175

mirafranc opened this issue Nov 10, 2020 · 1 comment · May be fixed by #177

Comments

@mirafranc
Copy link

Timestamp milliseconds wrongly interpreted if milliseconds start with zeros:

This issue occurred during Athena database testing (only 3 digits are supported for milliseconds). The timestamp type is recognised as 6 digits (but 3 digits set in the DB):
('endtime', DBAPITypeObject('TIMESTAMP'), 23, 23, 23, 6, 1)

  • Millisecond values starting 0 are wrongly interpreted to 3 digit format:
    2020-01-05 11:02:14.080 -> 2020-01-05 11:02:14.800
  • Millisecond values starting numeric value are interpreted to 6 digit format:
    2020-01-07 03:25:20.743 -> 2020-01-07 03:25:20.743000
@mirafranc
Copy link
Author

can be easily fixed by following code update:

def _to_datetime(rs, col):
    java_val = rs.getTimestamp(col)
    if not java_val:
        return
    d = datetime.datetime.strptime(str(java_val)[:19], "%Y-%m-%d %H:%M:%S")
    d = d.replace(microsecond=int(str(java_val.getNanos()).zfill(9)[:6]))
    return str(d)

I tested the code using Athena, Oracle, Sap - milliseconds are correctly evaluated for timestamps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant