Skip to content

ref(reader): Improve abstractions around column transformation - #800

Merged
tkaemming merged 3 commits into
masterfrom
result-structure
Mar 3, 2020
Merged

tkaemming merged 3 commits into
masterfrom
result-structure

Conversation

@tkaemming

Copy link
Copy Markdown
Contributor

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.

@tkaemming
tkaemming requested a review from a team February 28, 2020 22:24
@tkaemming

Copy link
Copy Markdown
Contributor Author

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.

Comment thread snuba/reader.py


def build_result_transformer(
column_transformations: Mapping[str, Callable[[Any], Any]],

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.)

Comment thread snuba/reader.py

def transform_result(result: Result) -> None:
for column in result["meta"]:
transformer = column_transformations.get(column["type"])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 fpacifici left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok, with this, though please double check the potential double formatting in snuba/reader at line 54

Comment thread snuba/clickhouse/native.py Resolved
Comment thread snuba/clickhouse/native.py Resolved
Comment thread snuba/reader.py Resolved
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 this pull request may close these issues.

2 participants