Пример #1
0
def test_mand_conditions(table: str, mand_conditions: List[FunctionCall]) -> None:

    query = Query(
        Table(
            table,
            ColumnSet([]),
            final=False,
            sampling_rate=None,
            mandatory_conditions=mand_conditions,
        ),
        None,
        None,
        binary_condition(
            BooleanFunctions.AND,
            binary_condition(
                OPERATOR_TO_FUNCTION["="], Column("d", None, "d"), Literal(None, "1"),
            ),
            binary_condition(
                OPERATOR_TO_FUNCTION["="], Column("c", None, "c"), Literal(None, "3"),
            ),
        ),
    )

    query_ast_copy = copy.deepcopy(query)

    request_settings = HTTPRequestSettings(consistent=True)
    processor = MandatoryConditionApplier()
    processor.process_query(query, request_settings)

    query_ast_copy.add_condition_to_ast(combine_and_conditions(mand_conditions))

    assert query.get_condition_from_ast() == query_ast_copy.get_condition_from_ast()
Пример #2
0
def test_mand_conditions(table: str,
                         mand_conditions: List[MandatoryCondition]) -> None:

    body = {"conditions": [["d", "=", "1"], ["c", "=", "3"]]}

    query = Query(
        copy.deepcopy(body),
        TableSource(table, None, mand_conditions, ["c1"]),
        None,
        None,
        binary_condition(
            None,
            BooleanFunctions.AND,
            binary_condition(
                None,
                OPERATOR_TO_FUNCTION["="],
                Column("d", None, "d"),
                Literal(None, "1"),
            ),
            binary_condition(
                None,
                OPERATOR_TO_FUNCTION["="],
                Column("c", None, "c"),
                Literal(None, "3"),
            ),
        ),
    )

    query_ast_copy = copy.deepcopy(query)

    request_settings = HTTPRequestSettings(consistent=True)
    processor = MandatoryConditionApplier()
    processor.process_query(query, request_settings)

    body["conditions"].extend([c.legacy for c in mand_conditions])
    assert query.get_conditions() == body["conditions"]

    query_ast_copy.add_condition_to_ast(
        combine_and_conditions([c.ast for c in mand_conditions]))

    assert query.get_condition_from_ast(
    ) == query_ast_copy.get_condition_from_ast()
Пример #3
0
    def build_and_rank_plans(
        self, query: LogicalQuery, settings: RequestSettings
    ) -> Sequence[ClickhouseQueryPlan]:
        with sentry_sdk.start_span(
            op="build_plan.selected_storage", description="select_storage"
        ):
            storage, mappers = self.__selector.select_storage(query, settings)

        with sentry_sdk.start_span(
            op="build_plan.selected_storage", description="translate"
        ):
            # The QueryTranslator class should be instantiated once for each call to build_plan,
            # to avoid cache conflicts.
            clickhouse_query = QueryTranslator(mappers).translate(query)

        with sentry_sdk.start_span(
            op="build_plan.selected_storage", description="set_from_clause"
        ):
            clickhouse_query.set_from_clause(
                get_query_data_source(
                    storage.get_schema().get_data_source(),
                    final=query.get_final(),
                    sampling_rate=query.get_sample(),
                )
            )

        cluster = storage.get_cluster()

        db_query_processors = [
            *storage.get_query_processors(),
            *self.__post_processors,
            MandatoryConditionApplier(),
        ]

        return [
            ClickhouseQueryPlan(
                query=clickhouse_query,
                plan_query_processors=[],
                db_query_processors=db_query_processors,
                storage_set_key=storage.get_storage_set_key(),
                execution_strategy=SimpleQueryPlanExecutionStrategy(
                    cluster=cluster,
                    db_query_processors=db_query_processors,
                    splitters=storage.get_query_splitters(),
                ),
            )
        ]
Пример #4
0
    def build_plan(self, request: Request) -> ClickhouseQueryPlan:
        clickhouse_query = QueryTranslator(self.__mappers).translate(request.query)
        clickhouse_query.set_from_clause(self.__storage.get_schema().get_data_source())

        cluster = self.__storage.get_cluster()

        return ClickhouseQueryPlan(
            query=clickhouse_query,
            plan_processors=[],
            execution_strategy=SimpleQueryPlanExecutionStrategy(
                cluster=cluster,
                db_query_processors=[
                    *self.__storage.get_query_processors(),
                    *self.__post_processors,
                    MandatoryConditionApplier(),
                ],
                splitters=self.__storage.get_query_splitters(),
            ),
        )
Пример #5
0
             SelectedExpression(
                 "average",
                 FunctionCall(
                     "average", "avg",
                     (Column(None, None, "count_environment"), )),
             ),
         ],
     ),
     CompositeExecutionStrategy(get_cluster(StorageSetKey.EVENTS), [],
                                {}, []),
     StorageSetKey.EVENTS,
     SubqueryProcessors(
         [],
         [
             *events_storage.get_query_processors(),
             MandatoryConditionApplier(),
             MandatoryConditionEnforcer([]),
         ],
     ),
     None,
 ),
 CompositeQuery(
     from_clause=ClickhouseQuery(
         from_clause=events_table,
         selected_columns=[
             SelectedExpression("project_id",
                                Column(None, None, "project_id")),
             SelectedExpression(
                 "count_environment",
                 FunctionCall(
                     "count_environment",