-
Notifications
You must be signed in to change notification settings - Fork 188
Support variable precision time timestamp #300
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
Support variable precision time timestamp #300
Conversation
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.
LGTM % comments.
Also there is a merge commit, could you instead rebase on current master?
trino/client.py
Outdated
@@ -912,6 +919,7 @@ def round_to(self, precision: int) -> TemporalType: | |||
In case the supplied value exceeds the specified precision, | |||
the value needs to be rounded. | |||
""" | |||
precision = min(precision, 6) |
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.
Please create a constant with a descriptive name for the max python temporal precision.
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.
Done
c237202
to
d254794
Compare
trino/client.py
Outdated
@@ -66,6 +66,7 @@ | |||
PROXIES = {} | |||
|
|||
_HEADER_EXTRA_CREDENTIAL_KEY_REGEX = re.compile(r'^\S[^\s=]*$') | |||
PYTHON_MAX_DECIMAL_PRECISION = 6 |
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.
Rename to MAX_PYTHON_TEMPORAL_PRECISION_POWER
, move to line 77 and reuse in constant MAX_PYTHON_TEMPORAL_PRECISION
.
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.
Done
trino/client.py
Outdated
@@ -747,7 +748,14 @@ def execute(self, additional_http_headers=None) -> TrinoResult: | |||
if self.cancelled: | |||
raise exceptions.TrinoUserError("Query has been cancelled", self.query_id) | |||
|
|||
response = self._request.post(self._sql, additional_http_headers) | |||
if self._experimental_python_types: |
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.
Actually you can always enable PARAMETRIC_DATETIME
. This is also how the JDBC driver works. Please also adjust the commit message and PR description.
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.
Shouldn't this be part of another PR?
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.
Done
@lpoulain: Please squash the commits, also adapt PR description and commit message (remove the experimental_python_types reference). |
bcd075a
to
37bcf0d
Compare
@@ -461,6 +461,7 @@ def test_time_query_param(trino_connection): | |||
rows = cur.fetchall() | |||
|
|||
assert rows[0][0] == params | |||
assert cur.description[0][1] == "time(6)" |
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.
same for time with time zone
?
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.
Added similar assertion to test_time_with_time_zone_negative_offset()
and test_time_with_time_zone_positive_offset()
.add_field( | ||
sql="TIME '00:00:00.000100'", |
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.
where did this case go?
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.
Do we still need this considering there is no rounding involved here?
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.
Good catch, the rounding only happenned when parametric timestamp was not implemented. 00:00:00.000100
has 1
at 4th decimal digit and without parametric timestamp support it gets rounded to 00:00:00
.
sql="TIME '00:00:00.0000001'", | ||
python=time(0, 0, 0)) # PARAMETRIC_DATETIME not enabled |
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.
where did this go?
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.
Isn't this moved a few lines below (233)?
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.
Yeah, the diff on GitHub looked a bit wacky. I've re-reviewed locally in IDE and everything looks good.
trino/client.py
Outdated
http_headers = {constants.HEADER_CLIENT_CAPABILITIES: 'PARAMETRIC_DATETIME'} | ||
if additional_http_headers: | ||
http_headers.update(additional_http_headers) |
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.
this must go into the http_headers
method instead where we already do the request header setting logic.
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.
Fixed
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.
LGTM % move header setting code to http_headers
method
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.
Please rebase/squash and resolve conflict. LGTM otherwise.
f4b1103
to
18fdea1
Compare
This change starts sending the PARAMETRIC_DATETIME client capability in the X-Trino-Client-Capabilities request headers so that Trino sends back temporal types in their original precision instead of always sending back results with millisecond precision.
18fdea1
to
8d5e9d0
Compare
rebased and reworded |
Description
Set X-Trino-Client-Capabilities to PARAMETRIC_DATETIME. Update the unit and integration tests accordingly.
Non-technical explanation
When querying Trino, set the X-Trino-Client-Capabilities HTTP header to PARAMETRIC_DATETIME. This instructs Trino to return full-precision datetimes and times.
Release notes
( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(X) Release notes are required, with the following suggested text:
* The client is now requesting PARAMETRIC_DATETIME, leading Trino to return full-precision datetimes and times.