Skip to content
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

fix(parsing): Group By clause in AST is now a List #2284

Merged
merged 5 commits into from
Dec 16, 2021

Conversation

rahul-kumar-saini
Copy link
Contributor

Overview

  • Parser building the AST from a query creates a map() for the "group by" clause of a query
  • This map is a kind of generator, which means if turned into a list somewhere down the line, the generator is drained and query.get_group_by() returns an empty map

Example

>>> from snuba.query.snql.parser import parse_snql_query_initial
>>> body = "MATCH (...) SELECT ... BY xyz ..."
>>> query = parse_snql_query_initial(body)
>>> print(query.get_groupby())
<map object at 0x110d21a60>
>>> print(list(query.get_groupby()))
[xyz]
>>> print(list(query.get_groupby()))
[]
  • If at any time the map gets cast to a list, we lose the group by clause entirely in the AST

Changes

  • Replaced map with list in the SnQL visitor when parsing group by clause

@rahul-kumar-saini rahul-kumar-saini requested a review from a team as a code owner December 15, 2021 17:45
Copy link
Member

@volokluev volokluev left a comment

Choose a reason for hiding this comment

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

can you add a test that would've broken before this change?

@codecov-commenter
Copy link

codecov-commenter commented Dec 15, 2021

Codecov Report

Merging #2284 (d8e75e0) into master (6388143) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #2284   +/-   ##
=======================================
  Coverage   93.06%   93.06%           
=======================================
  Files         553      553           
  Lines       25238    25244    +6     
=======================================
+ Hits        23487    23493    +6     
  Misses       1751     1751           
Impacted Files Coverage Δ
snuba/query/snql/parser.py 96.12% <100.00%> (ø)
tests/query/test_query_ast.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6388143...d8e75e0. Read the comment docs.

@rahul-kumar-saini rahul-kumar-saini enabled auto-merge (squash) December 16, 2021 15:35
@rahul-kumar-saini rahul-kumar-saini merged commit f1f5ead into master Dec 16, 2021
@rahul-kumar-saini rahul-kumar-saini deleted the fix/map-to-list-groupby branch December 16, 2021 15:48
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.

4 participants