snuba icon indicating copy to clipboard operation
snuba copied to clipboard

draft(MQL): Parse multi-entity type formulas

Open enochtangg opened this issue 1 year ago • 4 comments

This is a draft PR for implementing what parsing multi-entity type formulas might look like in snuba.

Depends on:

  • https://github.com/getsentry/snuba-sdk/pull/169

This change breaks up the parsing pipeline into multiple sub-tasks:

  1. parse_mql_query_body(): Parses the MQL into the InitialParseResult tree
  2. populate_query_ast_initial(): Creates LogicalQuery | CompositeQuery objects with the appropriate expressions. If multi-type formula query, calls some processing function (process_table_names_in_selected_expressions()) which traverses AST and adds the appropriate join table names to the expressions.
  3. populate_query_from_mql_context Parses MQL Context and transforms fields into expressions that inject into the AST. If multi-type formula query, patch the appropriate join table names.

To see preview of CompositeQuery AST (with joins), run pytest tests/query/parser/test_formula_mql_query.py::test_multi_type_formula -s -vv

enochtangg avatar Feb 02 '24 22:02 enochtangg