Support variable precision time timestamp#300
Conversation
mdesmet
left a comment
There was a problem hiding this comment.
LGTM % comments.
Also there is a merge commit, could you instead rebase on current master?
trino/client.py
Outdated
| 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.
Please create a constant with a descriptive name for the max python temporal precision.
c237202 to
d254794
Compare
trino/client.py
Outdated
| PROXIES = {} | ||
|
|
||
| _HEADER_EXTRA_CREDENTIAL_KEY_REGEX = re.compile(r'^\S[^\s=]*$') | ||
| PYTHON_MAX_DECIMAL_PRECISION = 6 |
There was a problem hiding this comment.
Rename to MAX_PYTHON_TEMPORAL_PRECISION_POWER, move to line 77 and reuse in constant MAX_PYTHON_TEMPORAL_PRECISION.
trino/client.py
Outdated
| 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.
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.
Shouldn't this be part of another PR?
|
@lpoulain: Please squash the commits, also adapt PR description and commit message (remove the experimental_python_types reference). |
bcd075a to
37bcf0d
Compare
| rows = cur.fetchall() | ||
|
|
||
| assert rows[0][0] == params | ||
| assert cur.description[0][1] == "time(6)" |
There was a problem hiding this comment.
Added similar assertion to test_time_with_time_zone_negative_offset() and test_time_with_time_zone_positive_offset()
| # python=time(0, 0, 0)) # PARAMETRIC_DATETIME not enabled | ||
| # round down | ||
| .add_field( | ||
| sql="TIME '00:00:00.000100'", |
There was a problem hiding this comment.
Do we still need this considering there is no rounding involved here?
There was a problem hiding this comment.
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.
Isn't this moved a few lines below (233)?
There was a problem hiding this comment.
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.
this must go into the http_headers method instead where we already do the request header setting logic.
hashhar
left a comment
There was a problem hiding this comment.
LGTM % move header setting code to http_headers method
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.