Skip to content

Commit

Permalink
Revert "feat: filter in select optimizer rewrite (#5676)"
Browse files Browse the repository at this point in the history
This reverts commit f746e1d.

Co-authored-by: kylemumma <24424170+kylemumma@users.noreply.github.com>
  • Loading branch information
getsentry-bot and kylemumma committed Mar 28, 2024
1 parent f746e1d commit af29c13
Show file tree
Hide file tree
Showing 8 changed files with 365 additions and 509 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,6 @@ jobs:
tests/sentry/event_manager \
tests/sentry/api/endpoints/test_organization_profiling_functions.py \
tests/snuba/api/endpoints/test_organization_events_stats_mep.py \
tests/sentry/sentry_metrics/querying \
tests/snuba/test_snql_snuba.py \
tests/snuba/test_metrics_layer.py \
-vv --cov . --cov-report="xml:.artifacts/snuba.coverage.xml"
Expand Down
5 changes: 1 addition & 4 deletions snuba/query/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,7 @@ def is_not_in_condition_pattern(lhs: Pattern[Expression]) -> FunctionCallPattern
def binary_condition(
function_name: str, lhs: Expression, rhs: Expression
) -> FunctionCall:
"""This function is deprecated please use snuba.query.dsl.binary_condition"""
from snuba.query.dsl import binary_condition as dsl_binary_condition

return dsl_binary_condition(function_name, lhs, rhs)
return FunctionCall(None, function_name, (lhs, rhs))


binary_condition_patterns = {
Expand Down
23 changes: 0 additions & 23 deletions snuba/query/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,6 @@ def divide(
return FunctionCall(alias, "divide", (lhs, rhs))


# boolean functions
def binary_condition(
function_name: str, lhs: Expression, rhs: Expression
) -> FunctionCall:
return FunctionCall(None, function_name, (lhs, rhs))


def equals(lhs: Expression, rhs: Expression) -> FunctionCall:
return binary_condition("equals", lhs, rhs)


def and_cond(lhs: FunctionCall, rhs: FunctionCall) -> FunctionCall:
return binary_condition("and", lhs, rhs)


def or_cond(lhs: FunctionCall, rhs: FunctionCall) -> FunctionCall:
return binary_condition("or", lhs, rhs)


def in_cond(lhs: Expression, rhs: Expression) -> FunctionCall:
return binary_condition("in", lhs, rhs)


# aggregate functions
def count(column: Optional[Column] = None, alias: Optional[str] = None) -> FunctionCall:
return FunctionCall(alias, "count", (column,) if column else ())
Expand Down
22 changes: 9 additions & 13 deletions snuba/query/mql/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from snuba.query.processors.logical.filter_in_select_optimizer import (
FilterInSelectOptimizer,
)
from snuba.query.query_settings import HTTPQuerySettings, QuerySettings
from snuba.query.query_settings import QuerySettings
from snuba.query.snql.anonymize import format_snql_anonymized
from snuba.query.snql.parser import (
MAX_LIMIT,
Expand All @@ -49,7 +49,7 @@
_replace_time_condition,
_treeify_or_and_conditions,
)
from snuba.state import explain_meta, get_int_config
from snuba.state import explain_meta
from snuba.util import parse_datetime
from snuba.utils.constants import GRANULARITIES_AVAILABLE

Expand Down Expand Up @@ -1064,12 +1064,19 @@ def transform(exp: Expression) -> Expression:
query.transform_expressions(transform)


def optimize_filter_in_select(
query: CompositeQuery[QueryEntity] | LogicalQuery,
) -> None:
FilterInSelectOptimizer().process_mql_query(query)


CustomProcessors = Sequence[
Callable[[Union[CompositeQuery[QueryEntity], LogicalQuery]], None]
]

MQL_POST_PROCESSORS: CustomProcessors = POST_PROCESSORS + [
quantiles_to_quantile,
optimize_filter_in_select,
]


Expand Down Expand Up @@ -1109,17 +1116,6 @@ def parse_mql_query(
settings,
)

# Filter in select optimizer
feat_flag = get_int_config("enable_filter_in_select_optimizer", default=1)
if feat_flag:
with sentry_sdk.start_span(
op="processor", description="filter_in_select_optimize"
):
if settings is None:
FilterInSelectOptimizer().process_query(query, HTTPQuerySettings())
else:
FilterInSelectOptimizer().process_query(query, settings)

# Custom processing to tweak the AST before validation
with sentry_sdk.start_span(op="processor", description="custom_processing"):
if custom_processing is not None:
Expand Down
Loading

0 comments on commit af29c13

Please sign in to comment.