Ejemplo n.º 1
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(),
                ),
            )
        ]
Ejemplo n.º 2
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(),
            ),
        )