pytest.param(
     build_query(
         [],
         binary_condition(
             "notEquals",
             FunctionCall(
                 None,
                 "ifNull",
                 (
                     FunctionCall(
                         None,
                         "arrayElement",
                         (
                             Column(None, None, "tags.value"),
                             FunctionCall(
                                 None,
                                 "indexOf",
                                 (
                                     Column(None, None, "tags.key"),
                                     Literal(None, "query.error_reason"),
                                 ),
                             ),
                         ),
                     ),
                     Literal(None, ""),
                 ),
             ),
             Literal(None, ""),
         ),
     ),
     FunctionCall(
    return FunctionCall(None, "or", (op1, op2))


def and_exp(op1: Expression, op2: Expression) -> FunctionCall:
    return FunctionCall(None, "and", (op1, op2))


noop = FunctionCall(None, "eq", (Literal(None, "foo"), Literal(None, "foo")))
noop_and = and_exp(Literal(None, True), Literal(None, True))
noop_or = or_exp(Literal(None, True), Literal(None, True))

TEST_CASES = [
    pytest.param(
        build_query(
            selected_columns=[Column("count", None, "count")],
            condition=and_exp(tag_existence_expression(),
                              tag_equality_expression()),
        ),
        build_query(
            selected_columns=[Column("count", None, "count")],
            condition=optimized_tag_expression(),
        ),
        id="simplest happy path",
    ),
    pytest.param(
        build_query(
            selected_columns=[Column("count", None, "count")],
            condition=or_exp(tag_existence_expression(),
                             tag_equality_expression()),
        ),
        build_query(
Esempio n. 3
0
spans_op_group_col = FunctionCall(
    None,
    "tuple",
    (spans_op_col, spans_group_col),
)

spans_exclusive_time_col = FunctionCall(
    "spans_exclusive_time",
    "arrayJoin",
    (Column(None, None, "spans.exclusive_time"), ),
)

spans_op_filter_tests = [
    pytest.param(
        build_query(),
        set(),
        id="no op filter",
    ),
    pytest.param(
        build_query(condition=binary_condition(
            ConditionFunctions.EQ,
            spans_op_col,
            Literal(None, "db"),
        ), ),
        {"db"},
        id="simple equality",
    ),
    pytest.param(
        build_query(condition=in_condition(
            spans_op_col,
Esempio n. 4
0
def some_tuple(alias: str | None):
    return literals_tuple(alias,
                          [Literal(None, "duration"),
                           Literal(None, 300)])


def identity(expression: Expression) -> Expression:
    return dsl_identity(expression, None)


TEST_QUERIES = [
    pytest.param(
        build_query(selected_columns=[
            some_tuple(alias="foo"),
            equals(
                tupleElement(None, some_tuple(alias="doo"), Literal(None, 1)),
                Literal(None, 300),
            ),
        ]),
        build_query(selected_columns=[
            # top level tuple alias persists
            some_tuple(alias="foo"),
            equals(
                # alias of the tuple of internal function is removed (it is not useful)
                tupleElement(None, some_tuple(alias=None), Literal(None, 1)),
                Literal(None, 300),
            ),
        ]),
        id="simple happy path",
    ),
    pytest.param(
from snuba.query.expressions import Column, Expression, FunctionCall, Literal
from snuba.query.processors.mapping_optimizer import MappingOptimizer
from snuba.request.request_settings import HTTPRequestSettings
from snuba.state import set_config
from tests.query.processors.query_builders import (
    build_query,
    column,
    nested_condition,
    nested_expression,
)

TEST_CASES = [
    pytest.param(
        build_query(
            selected_columns=[column("event_id"), nested_expression("tags", "my_tag")],
            condition=binary_condition(
                ConditionFunctions.EQ, column("event_id"), Literal(None, "123123")
            ),
        ),
        binary_condition(
            ConditionFunctions.EQ, column("event_id"), Literal(None, "123123")
        ),
        id="No tag condition",
    ),
    pytest.param(
        build_query(
            selected_columns=[column("event_id")],
            condition=nested_condition(
                "contexts", "my_ctx", ConditionFunctions.EQ, "a"
            ),
        ),
        nested_condition("contexts", "my_ctx", ConditionFunctions.EQ, "a"),
Esempio n. 6
0
    return FunctionCall(
        None,
        "greater",
        (
            FunctionCall(alias, "uniq", (Column(None, None, column_name),)),
            Literal(None, 1),
        ),
    )


INVALID_QUERY_CASES = [
    pytest.param(
        build_query(
            selected_columns=[
                Column("_snuba_project_id", None, "project_id"),
                Column(None, None, "transaction_name"),
            ],
            condition=None,
            having=uniq_expression(),
        ),
        id="uniq in having, not in select",
    ),
    pytest.param(
        build_query(
            selected_columns=[
                Column("_snuba_project_id", None, "project_id"),
                Column(None, None, "transaction_name"),
                uniq_expression(alias="my_alias", column_name="some_column"),
            ],
            condition=None,
            having=uniq_expression(alias="my_alias", column_name="some_other_column"),
        ),