ref(reader): Return date and datetimes instead of strings#414
Merged
Conversation
manuzope
reviewed
Aug 14, 2019
| DATETIME_TYPE_RE = re.compile(r"(Nullable\()?DateTime\b") | ||
|
|
||
|
|
||
| def transform_date_columns(result: Result) -> Result: |
Contributor
There was a problem hiding this comment.
How do you feel about having some tests for this function?
Contributor
Author
There was a problem hiding this comment.
There should be general coverage via the API tests, but a unit test wouldn't be a bad thing either. At the same time, this is all pretty likely going to go through another round of changes in the near future so I'm hesitant to invest too much time in it.
Contributor
Author
There was a problem hiding this comment.
There will probably be a change soon to change the type of Result, I promise to add them at that point (and fix the bug with non-scalar values noted here.)
I'm putting this in writing so you can hold me to it. 🙂
Contributor
Author
|
Out of scope for this change (not a regression), but there is also a bug here: >>> import pprint
>>> from snuba import settings
>>> from snuba.api import clickhouse_ro
>>> from snuba.reader import NativeDriverReader
>>>
>>> native = NativeDriverReader(clickhouse_ro)
>>> pprint.pprint(native.execute('SELECT now() FORMAT JSON'))
{'data': [{'now()': datetime.datetime(2019, 8, 14, 18, 22, 54, tzinfo=tzutc())}],
'meta': [{'name': 'now()', 'type': 'DateTime'}]}
>>> pprint.pprint(native.execute('SELECT [now()] FORMAT JSON'))
{'data': [{'array(now())': (datetime.datetime(2019, 8, 14, 18, 22, 54),)}],
'meta': [{'name': 'array(now())', 'type': 'Array(DateTime)'}]} |
manuzope
approved these changes
Aug 14, 2019
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This code will need to be shared between the HTTP (JSON) reader (#406) and the native reader, so this extracts it from the
NativeDriverReader.Formatting the datetime is object is already handled as part of the JSON serializer in the API:
snuba/snuba/api.py
Line 156 in 4b36a88
It makes more sense to pass around a datetime object than a string, since this avoids unnecessary type conversions in components such as the splitter.