Repository navigation
ref(reader): Improve abstractions around column transformation - #800
Conversation
|
The earlier approach was here: https://github.com/getsentry/snuba/pull/406/files#diff-391650a426d8346e225dfd3356e5fdd9 This was not ideal to begin with, and subsequent changes after that initial implementation (dealing with nullable fields, UUID types) made it more apparent to me that this should be broken up by reader type. |
|
|
||
|
|
||
| def build_result_transformer( | ||
| column_transformations: Mapping[str, Callable[[Any], Any]], |
There was a problem hiding this comment.
This approach also should map more cleanly to streaming results, since this only requires knowledge of the schema upfront and then each row can be transformed independently. (I didn't update this implementation to transform on a per-row basis instead of a per-result basis to minimize the complexity here, but it would be a pretty straightforward change.)
|
|
||
| def transform_result(result: Result) -> None: | ||
| for column in result["meta"]: | ||
| transformer = column_transformations.get(column["type"]) |
There was a problem hiding this comment.
Note that this still doesn't handle tuples (not a regression), e.g. if argMax((timestamp, value)) was provided in the aggregations, the query would succeed but it would fail to be serialized (either into the cache, or into the HTTP response buffer.)
fpacifici
left a comment
There was a problem hiding this comment.
I am ok, with this, though please double check the potential double formatting in snuba/reader at line 54
This transformation logic is going to need to be shared between the native reader and the HTTP reader, but the actual transformation logic for these types will be different since the native reader is dealing with Python objects, and the HTTP reader will be dealing with strings. This splits the transformation functions themselves from the code that manages the result mutation.