def test_formatting() -> None:
    """
    Validates the formatting of the arrayFilter expressions.
    """
    assert tupleElement(
        "tags_key",
        arrayJoin(
            "snuba_all_tags",
            zip_columns(
                Column(None, None, "tags.key"), Column(None, None, "tags.value"),
            ),
        ),
        Literal(None, 1),
    ).accept(ClickhouseExpressionFormatter()) == (
        "(tupleElement((arrayJoin(arrayMap((x, y -> tuple(x, y)), "
        "tags.key, tags.value)) AS snuba_all_tags), 1) AS tags_key)"
    )

    assert tupleElement(
        "tags_key",
        arrayJoin(
            "snuba_all_tags",
            filter_key_values(
                zip_columns(
                    Column(None, None, "tags.key"), Column(None, None, "tags.value"),
                ),
                [Literal(None, "t1"), Literal(None, "t2")],
            ),
        ),
        Literal(None, 1),
    ).accept(ClickhouseExpressionFormatter()) == (
        "(tupleElement((arrayJoin(arrayFilter((pair -> in("
        "tupleElement(pair, 1), tuple('t1', 't2'))), "
        "arrayMap((x, y -> tuple(x, y)), tags.key, tags.value))) AS snuba_all_tags), 1) AS tags_key)"
    )
Exemplo n.º 2
0
     "aggregations": [],
     "groupby": [],
     "selected_columns": ["tags_key", "tags_value"],
     "conditions": [["col", "IN", ["t1", "t2"]]],
 },
 ClickhouseQuery(
     None,
     selected_columns=[
         SelectedExpression(
             name="tags_key",
             expression=tupleElement(
                 "_snuba_tags_key",
                 arrayJoin(
                     "snuba_all_tags",
                     zip_columns(
                         Column(None, None, "tags.key"),
                         Column(None, None, "tags.value"),
                     ),
                 ),
                 Literal(None, 1),
             ),
         ),
         SelectedExpression(
             name="tags_value",
             expression=tupleElement(
                 "_snuba_tags_value",
                 arrayJoin(
                     "snuba_all_tags",
                     zip_columns(
                         Column(None, None, "tags.key"),
                         Column(None, None, "tags.value"),
                     ),