Пример #1
0
def test_format_expressions(
    expression: Expression, expected_clickhouse: str, expected_anonymized: str
) -> None:
    visitor = ClickhouseExpressionFormatter()
    anonymized_visitor = ClickHouseExpressionFormatterAnonymized()
    assert expression.accept(visitor) == expected_clickhouse
    assert expression.accept(anonymized_visitor) == expected_anonymized
Пример #2
0
def test_expand_aliases(
    expression: Expression,
    lookup: Mapping[str, Expression],
    nested_resolution: bool,
    expected: Expression,
) -> None:
    assert (expression.accept(
        AliasExpanderVisitor(lookup, [], nested_resolution)) == expected)
Пример #3
0
def test_translation(
    mappings: TranslationMappers,
    expression: Expression,
    expected: ClickhouseExpression,
) -> None:
    translator = SnubaClickhouseMappingTranslator(mappings)
    translated = expression.accept(translator)

    assert translated == expected
Пример #4
0
def test_transaction_translation(
    expression: Expression, expected: ClickhouseExpression,
) -> None:
    translator = SnubaClickhouseMappingTranslator(
        transaction_translation_mappers.concat(null_function_translation_mappers)
    )
    translated = expression.accept(translator)

    assert translated == expected
Пример #5
0
def test_default_translation(expression: Expression) -> None:
    """
    Ensures that a translation that relies on the default translation rules
    produces a deep copy of the original expression.
    """

    translated = expression.accept(
        SnubaClickhouseMappingTranslator(TranslationMappers()))

    assert translated == expression
Пример #6
0
def _process_root(
    expression: Expression,
    subqueries: Mapping[str, SubqueryDraft],
    alias_generator: AliasGenerator,
) -> Expression:
    """
    Takes a root expression in the main query, runs the branch cutter
    and pushes down the subexpressions.
    """
    subexpressions = expression.accept(BranchCutter(alias_generator))
    return _push_down_branches(subexpressions, subqueries, alias_generator)
Пример #7
0
def test_branch_cutter(expression: Expression, expected: SubExpression,
                       main_expr: MainQueryExpression) -> None:
    def alias_generator() -> Generator[str, None, None]:
        i = 0
        while True:
            i += 1
            yield f"_snuba_gen_{i}"

    subexpression = expression.accept(BranchCutter(alias_generator()))
    assert subexpression == expected
    assert subexpression.cut_branch(alias_generator()) == main_expr
Пример #8
0
def test_escaping(expression: Expression, expected: str) -> None:
    visitor = ClickhouseExpressionFormatter()
    assert expression.accept(visitor) == expected
Пример #9
0
def test_format_expressions(expression: Expression, expected_clickhouse: str,
                            expected_tracing: TExpression) -> None:
    visitor = ClickhouseExpressionFormatter()
    assert expression.accept(visitor) == expected_clickhouse
    assert expression.accept(TracingExpressionFormatter()) == expected_tracing