Пример #1
0
def test_column_curried_function_translation() -> None:
    assert ColumnToCurriedFunction(
        None,
        "duration_quantiles",
        FunctionCall(
            None,
            "quantilesIfMerge",
            (
                Literal(None, 0.5),
                Literal(None, 0.9),
            ),
        ),
        (Column(None, None, "duration_quantiles"),),
    ).attempt_map(
        Column("duration_quantiles", None, "duration_quantiles"),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    ) == CurriedFunctionCall(
        "duration_quantiles",
        FunctionCall(
            None,
            "quantilesIfMerge",
            (
                Literal(None, 0.5),
                Literal(None, 0.9),
            ),
        ),
        (Column(None, None, "duration_quantiles"),),
    )
Пример #2
0
def test_translation(
    mappings: TranslationMappers,
    expression: Expression,
    expected: ClickhouseExpression,
) -> None:
    translator = SnubaClickhouseMappingTranslator(mappings)
    translated = expression.accept(translator)

    assert translated == expected
Пример #3
0
def test_col_nullable_measurements_translation() -> None:
    translated = ColumnToMapping(
        None, "lcp", None, "measurements", "lcp", nullable=True
    ).attempt_map(
        Column("lcp", None, "lcp"),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    )

    assert translated == _get_nullable_expr("lcp")
Пример #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 test_nullable_nested_translation() -> None:
    translated = SubscriptableMapper(
        None, "measurements", None, "measurements", nullable=True
    ).attempt_map(
        SubscriptableReference(
            "measurements[lcp]",
            Column(None, None, "measurements"),
            Literal(None, "lcp"),
        ),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    )

    assert translated == _get_nullable_expr("measurements[lcp]")
Пример #7
0
def test_column_function_translation() -> None:
    assert ColumnToFunction(
        None,
        "ip_address",
        "coalesce",
        (Column(None, None, "ip_address_v4"), Column(None, None, "ip_address_v6")),
    ).attempt_map(
        Column("ip_address", None, "ip_address"),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    ) == FunctionCall(
        "ip_address",
        "coalesce",
        (Column(None, None, "ip_address_v4"), Column(None, None, "ip_address_v6")),
    )
Пример #8
0
def test_tag_translation() -> None:
    translated = SubscriptableMapper(None, "tags", None, "tags").attempt_map(
        SubscriptableReference(
            "tags[release]", Column(None, None, "tags"), Literal(None, "release")
        ),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    )

    assert translated == FunctionCall(
        "tags[release]",
        "arrayElement",
        (
            Column(None, None, "tags.value"),
            FunctionCall(
                None,
                "indexOf",
                (Column(None, None, "tags.key"), Literal(None, "release")),
            ),
        ),
    )
Пример #9
0
def test_col_tag_translation() -> None:
    translated = ColumnToMapping(
        None, "geo_country_code", None, "contexts", "geo.country_code"
    ).attempt_map(
        Column("geo_country_code", None, "geo_country_code"),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    )

    assert translated == FunctionCall(
        "geo_country_code",
        "arrayElement",
        (
            Column(None, None, "contexts.value"),
            FunctionCall(
                None,
                "indexOf",
                (Column(None, None, "contexts.key"), Literal(None, "geo.country_code")),
            ),
        ),
    )
Пример #10
0
 def __init__(self, mappers: TranslationMappers) -> None:
     self.__expression_translator = SnubaClickhouseMappingTranslator(
         mappers)
Пример #11
0
def test_column_literal_translation() -> None:
    assert ColumnToLiteral("table", "col", "my_literal").attempt_map(
        Column("c_alias", "table", "col"),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    ) == Literal("c_alias", "my_literal")
Пример #12
0
def test_column_translation() -> None:
    assert ColumnToColumn("table", "col", "table2", "col2").attempt_map(
        Column("table.col", "table", "col"),
        SnubaClickhouseMappingTranslator(TranslationMappers()),
    ) == Column("table.col", "table2", "col2")