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
feat(devexp): add ability to parse simple storage queries #5776
Conversation
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: snuba/query/snql/parser.py
Did you find this useful? React with a 👍 or 👎 |
Test Failures Detected: Due to failing tests, we cannot provide coverage reports at this time. ❌ Failed Test Results:Completed 1 tests with View the full list of failed tests
|
… make tag queries work tho
…dation PR to come in
@@ -23,18 +47,6 @@ def literal(value: OptionalScalarType, alias: str | None = None) -> Literal: | |||
return Literal(alias, value) | |||
|
|||
|
|||
def snuba_tags_raw(indexer_mapping: int) -> SubscriptableReference: |
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.
was not used
def equals( | ||
lhs: Expression | OptionalScalarType, rhs: Expression | OptionalScalarType | ||
) -> FunctionCall: |
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.
happy to change this but I found it useful to not have to specify literals
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.
i like it
@@ -81,3 +79,73 @@ def _transform_expressions_impl( | |||
|
|||
def _transform_impl(self, visitor: ExpressionVisitor[Expression]) -> None: | |||
pass | |||
|
|||
|
|||
class StorageQuery(ProcessableQuery[Storage]): |
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.
TODO: I think this type can be generalized
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.
Why did you decide to parse into a StorageQuery rather than a ClickhouseQuery?
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 question. The main thing is that the Table
datasaoure does not resemble the entity in any real way and it's only by the time we get to the StorageProcessing
stage that we can process the clickhouse query.
Ideally what I would do is remove Table
as a datasource and probably remove ClickhouseQuery
later.
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.
Why does it matter that Table doesn't resemble Entity?
@@ -1532,8 +1617,6 @@ def parse_snql_query( | |||
with sentry_sdk.start_span(op="processor", description="time_based_processing"): | |||
_post_process(query, [_replace_time_condition], settings) | |||
|
|||
# XXX: Select the entity to be used for the query. This step is temporary. Eventually |
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.
RIP this comment
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.
My biggest concern would be the introduction of a new StorageQuery class rather than going directly to a ClickhouseQuery.
@@ -81,3 +79,73 @@ def _transform_expressions_impl( | |||
|
|||
def _transform_impl(self, visitor: ExpressionVisitor[Expression]) -> None: | |||
pass | |||
|
|||
|
|||
class StorageQuery(ProcessableQuery[Storage]): |
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.
Why did you decide to parse into a StorageQuery rather than a ClickhouseQuery?
def equals( | ||
lhs: Expression | OptionalScalarType, rhs: Expression | OptionalScalarType | ||
) -> FunctionCall: |
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.
i like it
|
||
|
||
@pytest.mark.parametrize("query_body, expected_query", test_cases) | ||
def test_format_expressions(query_body: str, expected_query: StorageQuery) -> None: |
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.
nit: im not sure if this is what you meant to name it but i was expecting something more like test_parse_storage or something
try: | ||
return StorageKey(node.text) | ||
except Exception: | ||
raise ParsingException(f"{node.text} is not a valid Storage name") |
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.
unrelated to current PR, but one thought I have in general is that it might be nice to be able to parse StorageKey and EntityKey even if it doesnt exist. And then later on you get an error if you try to access one that doesnt exist. This would make using fake ones in testing easier.
|
||
assert isinstance(match, QueryEntity) # mypy | ||
assert isinstance(match, (QueryEntity, QueryStorage)) # mypy |
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.
random comment that you can ignore: if you care to read a relevant excerpt of the pragmatic programmer about "assertive programming" https://www.informit.com/articles/article.aspx?p=2982114&seqNum=3
if not isinstance(match, (QueryEntity, QueryStorage)): | ||
import pdb | ||
|
||
pdb.set_trace() | ||
print(match) |
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.
if not isinstance(match, (QueryEntity, QueryStorage)): | |
import pdb | |
pdb.set_trace() | |
print(match) |
query.transform_expressions(mangle_column_value) | ||
print(query) |
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.
print(query) |
This is the most simple version of this PR:
Work that is needed to make this really work:
required_time_column
to storages so we can do the date alignment logic we use for entities