CompositeQuery( from_clause=JoinClause( left_node=IndividualNode( "e", QueryEntity( EntityKey.EVENTS, get_entity(EntityKey.EVENTS).get_data_model(), ), ), right_node=IndividualNode( "t", QueryEntity( EntityKey.TRANSACTIONS, get_entity(EntityKey.TRANSACTIONS).get_data_model(), ), ), keys=[ JoinCondition( JoinConditionExpression("e", "event_id"), JoinConditionExpression("t", "event_id"), ) ], join_type=JoinType.INNER, ), selected_columns=[ SelectedExpression( "4-5", FunctionCall(None, "minus", (Literal(None, 4), Literal(None, 5))), ), SelectedExpression("e.c", Column("_snuba_e.c", "e", "c")), ], ),
CompositeQuery( from_clause=Query( Table("my_table", ColumnSet([])), selected_columns=[ SelectedExpression("column1", Column(None, None, "column1")), SelectedExpression( "sub_average", FunctionCall( "sub_average", "avg", (Column(None, None, "column2"),) ), ), SelectedExpression("column3", Column(None, None, "column3")), ], condition=binary_condition( "eq", lhs=Column("al", None, "column3"), rhs=Literal(None, "blabla"), ), groupby=[Column(None, None, "column2")], ), selected_columns=[ SelectedExpression( "average", FunctionCall( "average", "avg", (Column(None, None, "sub_average"),) ), ), SelectedExpression("alias", Column("alias", None, "column3")), ], groupby=[Column(None, None, "alias")], ),
clickhouse_assignees_node, clickhouse_events_node, clickhouse_groups_node, events_groups_join, ) TEST_CASES = [ pytest.param( CompositeQuery( from_clause=events_groups_join( clickhouse_events_node([ SelectedExpression( "_snuba_group_id", Column("_snuba_group_id", None, "group_id"), ), ]), clickhouse_groups_node([ SelectedExpression("_snuba_id", Column("_snuba_id", None, "id")) ], ), ), selected_columns=[], ), {"gr": JoinModifier.ANY}, id="Simple two table query with no reference. Semi join", ), pytest.param( CompositeQuery( from_clause=events_groups_join( clickhouse_events_node([ SelectedExpression(
TEST_CASES = [ pytest.param( SIMPLE_QUERY, 3, {"errors_local"}, True, 0.1, id="Simple Query", ), pytest.param( CompositeQuery( from_clause=SIMPLE_QUERY, selected_columns=[ SelectedExpression( "alias", FunctionCall("alias", "something", (Column(None, None, "alias"), )), ) ], ), 3, {"errors_local"}, True, None, id="Nested query. Count the inner query", ), pytest.param( CompositeQuery( from_clause=JoinClause( left_node=IndividualNode(alias="err", data_source=SIMPLE_QUERY),
CompositeQuery( from_clause=events_groups_join( clickhouse_events_node( [ SelectedExpression( "_snuba_group_id", Column("_snuba_group_id", None, "group_id"), ), ], binary_condition( BooleanFunctions.AND, binary_condition( BooleanFunctions.AND, binary_condition( ConditionFunctions.GTE, Column(None, None, "timestamp"), Literal(None, datetime(2020, 8, 1)), ), binary_condition( ConditionFunctions.LT, Column(None, None, "timestamp"), Literal(None, datetime(2020, 9, 1)), ), ), binary_condition( ConditionFunctions.EQ, build_mapping_expr( "tags[asd]", None, "tags", Literal(None, "asd"), ), Literal(None, "sdf"), ), ), [Column("_snuba_group_id", None, "group_id")], ), clickhouse_groups_node([ SelectedExpression("_snuba_id", Column("_snuba_id", None, "id")) ], ), ), selected_columns=[], ),
CompositeQuery( from_clause=LogicalQuery( from_clause=events_ent, selected_columns=[ SelectedExpression("project_id", Column(None, None, "project_id")), SelectedExpression( "count_environment", FunctionCall( "count_environment", "uniq", (SubscriptableReference( None, Column(None, None, "tags"), Literal(None, "environment"), ), ), ), ), ], groupby=[Column(None, None, "project_id")], condition=binary_condition( BooleanFunctions.AND, binary_condition( ConditionFunctions.EQ, Column(None, None, "project_id"), Literal(None, 1), ), binary_condition( ConditionFunctions.GTE, Column(None, None, "timestamp"), Literal(None, datetime(2020, 1, 1, 12, 0)), ), ), ), selected_columns=[ SelectedExpression( "average", FunctionCall("average", "avg", (Column(None, None, "count_environment"), )), ), ], ),
CompositeQuery( from_clause=LogicalQuery( QueryEntity( EntityKey.EVENTS, get_entity(EntityKey.EVENTS).get_data_model(), ), selected_columns=[ SelectedExpression("title", Column("_snuba_title", None, "title")), SelectedExpression( "count", FunctionCall("_snuba_count", "count", tuple())), ], groupby=[Column("_snuba_title", None, "title")], condition=binary_condition( "and", binary_condition( "equals", Column("_snuba_project_id", None, "project_id"), Literal(None, 1), ), binary_condition( "and", binary_condition( "greaterOrEquals", Column("_snuba_timestamp", None, "timestamp"), Literal(None, datetime.datetime(2021, 1, 15, 0, 0)), ), binary_condition( "less", Column("_snuba_timestamp", None, "timestamp"), Literal(None, datetime.datetime(2021, 1, 20, 0, 0)), ), ), ), ), selected_columns=[ SelectedExpression( "max_count", FunctionCall( "_snuba_max_count", "max", (Column("_snuba_count", None, "_snuba_count"), ), ), ), ], limit=1000, offset=0, ),