Skip to content

Commit

Permalink
got formula mql test passing with optimizer update
Browse files Browse the repository at this point in the history
  • Loading branch information
kylemumma committed Mar 21, 2024
1 parent 63aaf84 commit b980c51
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 8 deletions.
35 changes: 27 additions & 8 deletions tests/query/parser/test_formula_mql_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
)
from snuba.query.logical import Query
from snuba.query.mql.parser import parse_mql_query
from tests.query.processors.test_filter_in_select_optimizer import (
expected_optimize_condition,
)

# Commonly used expressions
from_distributions = QueryEntity(
Expand Down Expand Up @@ -259,7 +262,9 @@ def test_simple_formula() -> None:
),
],
groupby=[time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down Expand Up @@ -304,7 +309,9 @@ def test_simple_formula_with_leading_literals() -> None:
),
],
groupby=[time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down Expand Up @@ -349,7 +356,9 @@ def test_groupby() -> None:
),
],
groupby=[tag_column("transaction"), time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down Expand Up @@ -424,7 +433,9 @@ def test_curried_aggregate() -> None:
),
],
groupby=[tag_column("transaction"), time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down Expand Up @@ -469,7 +480,9 @@ def test_bracketing_rules() -> None:
),
],
groupby=[time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down Expand Up @@ -533,7 +546,9 @@ def test_formula_filters() -> None:
),
],
groupby=[time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down Expand Up @@ -588,7 +603,9 @@ def test_formula_groupby() -> None:
),
],
groupby=[tag_column("transaction"), time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down Expand Up @@ -630,7 +647,9 @@ def test_formula_scalar_value() -> None:
),
],
groupby=[time_expression],
condition=formula_condition,
condition=binary_condition(
"and", expected_optimize_condition[query_body], formula_condition
),
order_by=[
OrderBy(
direction=OrderByDirection.ASC,
Expand Down
18 changes: 18 additions & 0 deletions tests/query/processors/test_filter_in_select_optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,24 @@ def _in(lhs: Expression, rhs: Expression) -> FunctionCall:
Column("_snuba_metric_id", None, "metric_id"),
Literal(None, 123456),
),
"1 + sum(`d:transactions/duration@millisecond`){status_code:200} / sum(`d:transactions/duration@millisecond`)": _or(
equals(
Column("_snuba_metric_id", None, "metric_id"),
Literal(None, 123456),
),
_and(
equals(
subscriptable_reference(
"tags_raw", str(mql_context["indexer_mappings"]["status_code"])
),
Literal(None, "200"),
),
equals(
Column("_snuba_metric_id", None, "metric_id"),
Literal(None, 123456),
),
),
),
}

""" TESTING """
Expand Down

0 comments on commit b980c51

Please sign in to comment.