diff --git a/src/Storages/MergeTree/MergeTreeData.cpp b/src/Storages/MergeTree/MergeTreeData.cpp index 6eb979e5959..3a944ffada7 100644 --- a/src/Storages/MergeTree/MergeTreeData.cpp +++ b/src/Storages/MergeTree/MergeTreeData.cpp @@ -6118,6 +6118,7 @@ std::optional MergeTreeData::getQueryProcessingStageWithAgg { ProjectionCandidate candidate{}; candidate.desc = &projection; + candidate.context = select.getContext(); auto sample_block = projection.sample_block; auto sample_block_for_keys = projection.sample_block_for_keys; diff --git a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp index 65f54495b3c..1ca1779e4b0 100644 --- a/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp +++ b/src/Storages/MergeTree/MergeTreeDataSelectExecutor.cpp @@ -466,6 +466,7 @@ QueryPlanPtr MergeTreeDataSelectExecutor::read( fmt::format("MergeTree(with {} projection {})", query_info.projection->desc->type, query_info.projection->desc->name), query_info.storage_limits); plan->addStep(std::move(step)); + plan->addInterpreterContext(query_info.projection->context); return plan; } diff --git a/src/Storages/SelectQueryInfo.h b/src/Storages/SelectQueryInfo.h index c93531973b8..d997b60da24 100644 --- a/src/Storages/SelectQueryInfo.h +++ b/src/Storages/SelectQueryInfo.h @@ -163,6 +163,9 @@ struct ProjectionCandidate SortDescription group_by_elements_order_descr; MergeTreeDataSelectAnalysisResultPtr merge_tree_projection_select_result_ptr; MergeTreeDataSelectAnalysisResultPtr merge_tree_normal_select_result_ptr; + + /// Becasue projection analysis uses a separate interpreter. + ContextPtr context; }; /** Query along with some additional data,