def do_post_processing( self, project_ids: Sequence[int], query: Query, request_settings: RequestSettings, ) -> None: if not request_settings.get_turbo(): final, exclude_group_ids = get_projects_query_flags( project_ids, self.__replacer_state_name) if not final and exclude_group_ids: # If the number of groups to exclude exceeds our limit, the query # should just use final instead of the exclusion set. max_group_ids_exclude = get_config( "max_group_ids_exclude", settings.REPLACER_MAX_GROUP_IDS_TO_EXCLUDE) if len(exclude_group_ids) > max_group_ids_exclude: query.set_final(True) else: query.add_conditions([(["assumeNotNull", ["group_id"]], "NOT IN", exclude_group_ids)]) query.add_condition_to_ast( not_in_condition( None, FunctionCall(None, "assumeNotNull", (Column(None, "group_id", None), )), [Literal(None, p) for p in exclude_group_ids], )) else: query.set_final(final)
def test_format_clickhouse_specific_query() -> None: """ Adds a few of the Clickhosue specific fields to the query. """ query = Query( { "sample": 0.1, "totals": True, "limitby": (10, "environment") }, TableSource("my_table", ColumnSet([])), selected_columns=[ Column(None, "column1", None), Column(None, "column2", "table1"), ], condition=binary_condition( None, "eq", lhs=Column(None, "column1", None), rhs=Literal(None, "blabla"), ), groupby=[ Column(None, "column1", None), Column(None, "column2", "table1") ], having=binary_condition( None, "eq", lhs=Column(None, "column1", None), rhs=Literal(None, 123), ), order_by=[ OrderBy(OrderByDirection.ASC, Column(None, "column1", None)) ], array_join=Column(None, "column1", None), ) query.set_final(True) query.set_offset(50) query.set_limit(100) request_settings = HTTPRequestSettings() clickhouse_query = AstClickhouseQuery(query, request_settings) expected = ("SELECT column1, table1.column2 " "FROM my_table FINAL SAMPLE 0.1 " "ARRAY JOIN column1 " "WHERE eq(column1, 'blabla') " "GROUP BY (column1, table1.column2) WITH TOTALS " "HAVING eq(column1, 123) " "ORDER BY column1 ASC " "LIMIT 10 BY environment " "LIMIT 100 OFFSET 50") assert clickhouse_query.format_sql() == expected
def do_post_processing( self, project_ids: Sequence[int], query: Query, request_settings: RequestSettings, ) -> None: if not request_settings.get_turbo(): final, exclude_group_ids = get_projects_query_flags(project_ids) if not final and exclude_group_ids: # If the number of groups to exclude exceeds our limit, the query # should just use final instead of the exclusion set. max_group_ids_exclude = get_config('max_group_ids_exclude', settings.REPLACER_MAX_GROUP_IDS_TO_EXCLUDE) if len(exclude_group_ids) > max_group_ids_exclude: query.set_final(True) else: query.add_conditions([(['assumeNotNull', ['group_id']], 'NOT IN', exclude_group_ids)]) else: query.set_final(final)