コード例 #1
0
ファイル: project_extension.py プロジェクト: ruezetle/snuba
 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)
コード例 #2
0
 def process_query(self, query: Query,
                   extension_data: ExtensionData) -> None:
     from_date, to_date = self.get_time_limit(extension_data)
     query.add_conditions([
         (self.__timestamp_column, '>=', from_date.isoformat()),
         (self.__timestamp_column, '<', to_date.isoformat()),
     ])
コード例 #3
0
def test_edit_query():
    query = Query({
        "selected_columns": ["c1", "c2", "c3"],
        "conditions": [["c1", "=", "a"]],
        "groupby": ["project_id"],
        "aggregations": [["count()", "", "count"]],
        "orderby": "event_id",
        "sample": 10,
        "limit": 100,
        "offset": 50,
    })

    query.set_selected_columns(["c4"])
    assert query.get_selected_columns() == ["c4"]

    query.set_aggregations([["different_agg()", "", "something"]])
    assert query.get_aggregations() == [["different_agg()", "", "something"]]

    query.add_groupby(["more", "more2"])
    assert query.get_groupby() == ["project_id", "more", "more2"]

    query.add_conditions([["c5", "=", "9"]])
    assert query.get_conditions() == [
        ["c1", "=", "a"],
        ["c5", "=", "9"],
    ]

    query.set_conditions([["c6", "=", "10"]])
    assert query.get_conditions() == [
        ["c6", "=", "10"],
    ]
コード例 #4
0
 def process_query(
     self,
     query: Query,
     extension_data: ExtensionData,
     request_settings: RequestSettings,
 ) -> None:
     from_date, to_date = self.get_time_limit(extension_data)
     query.set_granularity(extension_data["granularity"])
     query.add_conditions(
         [
             (self.__timestamp_column, ">=", from_date.isoformat()),
             (self.__timestamp_column, "<", to_date.isoformat()),
         ]
     )
     query.add_condition_to_ast(
         binary_condition(
             None,
             BooleanFunctions.AND,
             binary_condition(
                 None,
                 ConditionFunctions.GTE,
                 Column(None, self.__timestamp_column, None),
                 Literal(None, from_date),
             ),
             binary_condition(
                 None,
                 ConditionFunctions.LT,
                 Column(None, self.__timestamp_column, None),
                 Literal(None, to_date),
             ),
         )
     )
コード例 #5
0
 def process_query(
     self,
     query: Query,
     extension_data: ExtensionData,
     request_settings: RequestSettings,
 ) -> None:
     organization_id = extension_data["organization"]
     query.add_conditions([("org_id", "=", organization_id)])
コード例 #6
0
 def process_query(
     self,
     query: Query,
     extension_data: ExtensionData,
     request_settings: RequestSettings,
 ) -> None:
     from_date, to_date = self.get_time_limit(extension_data)
     query.set_granularity(extension_data["granularity"])
     query.add_conditions([
         (self.__timestamp_column, '>=', from_date.isoformat()),
         (self.__timestamp_column, '<', to_date.isoformat()),
     ])
コード例 #7
0
    def process_query(
            self,
            query: Query,
            extension_data: ExtensionData,
            request_settings: RequestSettings,
    ) -> None:
        project_ids = util.to_list(extension_data['project'])

        if project_ids:
            query.add_conditions([('project_id', 'IN', project_ids)])

        request_settings.add_rate_limit(self._get_rate_limit_params(project_ids))

        self.do_post_processing(project_ids, query, request_settings)
コード例 #8
0
 def process_query(
     self,
     query: Query,
     extension_data: ExtensionData,
     request_settings: RequestSettings,
 ) -> None:
     organization_id = extension_data["organization"]
     query.add_conditions([("org_id", "=", organization_id)])
     query.add_condition_to_ast(
         binary_condition(
             None,
             ConditionFunctions.EQ,
             Column(None, "org_id", None),
             Literal(None, organization_id),
         ))
コード例 #9
0
ファイル: test_query.py プロジェクト: jiankunking/snuba
def test_edit_query():
    query = Query(
        {
            "selected_columns": ["c1", "c2", "c3"],
            "conditions": [["c1", "=", "a"]],
            "arrayjoin": "tags",
            "having": [["c4", "=", "c"]],
            "groupby": ["project_id"],
            "aggregations": [["count()", "", "count"]],
            "orderby": "event_id",
            "limitby": (100, "environment"),
            "sample": 10,
            "limit": 100,
            "offset": 50,
            "totals": True,
        },
        TableSource("my_table", ColumnSet([])),
    )

    query.set_selected_columns(["c4"])
    assert query.get_selected_columns() == ["c4"]

    query.set_aggregations([["different_agg()", "", "something"]])
    assert query.get_aggregations() == [["different_agg()", "", "something"]]

    query.add_groupby(["more", "more2"])
    assert query.get_groupby() == ["project_id", "more", "more2"]

    query.add_conditions([["c5", "=", "9"]])
    assert query.get_conditions() == [
        ["c1", "=", "a"],
        ["c5", "=", "9"],
    ]

    query.set_conditions([["c6", "=", "10"]])
    assert query.get_conditions() == [
        ["c6", "=", "10"],
    ]

    query.set_arrayjoin("not_tags")
    assert query.get_arrayjoin() == "not_tags"

    query.set_granularity(7200)
    assert query.get_granularity() == 7200

    query.set_prewhere([["pc6", "=", "10"]])
    assert query.get_prewhere() == [["pc6", "=", "10"]]
コード例 #10
0
 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)
コード例 #11
0
ファイル: project_extension.py プロジェクト: ruezetle/snuba
    def process_query(
        self,
        query: Query,
        extension_data: ExtensionData,
        request_settings: RequestSettings,
    ) -> None:
        project_ids = util.to_list(extension_data["project"])

        if project_ids:
            query.add_conditions([(self.__project_column, "IN", project_ids)])
            query.add_condition_to_ast(
                in_condition(
                    None,
                    Column(None, self.__project_column, None),
                    [Literal(None, p) for p in project_ids],
                ))

        request_settings.add_rate_limit(
            self._get_rate_limit_params(project_ids))

        self.do_post_processing(project_ids, query, request_settings)