diff --git a/src/Interpreters/ExpressionActions.cpp b/src/Interpreters/ExpressionActions.cpp index 845c1c789f7..32e3000a65d 100644 --- a/src/Interpreters/ExpressionActions.cpp +++ b/src/Interpreters/ExpressionActions.cpp @@ -323,8 +323,20 @@ void ExpressionAction::prepare(Block & sample_block, const Settings & settings, } } +void ExpressionAction::execute(Block & block, ExtraBlockPtr & not_processed) const +{ + switch (type) + { + case JOIN: + join->joinBlock(block, not_processed); + break; -void ExpressionAction::execute(Block & block, bool dry_run, ExtraBlockPtr & not_processed) const + default: + throw Exception("Unexpected expression call", ErrorCodes::LOGICAL_ERROR); + } +} + +void ExpressionAction::execute(Block & block, bool dry_run) const { size_t input_rows_count = block.rows(); @@ -362,10 +374,7 @@ void ExpressionAction::execute(Block & block, bool dry_run, ExtraBlockPtr & not_ } case JOIN: - { - join->joinBlock(block, not_processed); - break; - } + throw Exception("Unexpected JOIN expression call", ErrorCodes::LOGICAL_ERROR); case PROJECT: { @@ -681,7 +690,7 @@ void ExpressionActions::execute(Block & block, ExtraBlockPtr & not_processed) co if (actions.size() != 1) throw Exception("Continuation over multiple expressions is not supported", ErrorCodes::LOGICAL_ERROR); - actions[0].execute(block, false, not_processed); + actions[0].execute(block, not_processed); checkLimits(block); } diff --git a/src/Interpreters/ExpressionActions.h b/src/Interpreters/ExpressionActions.h index 89f10184bd8..9ec0047cc35 100644 --- a/src/Interpreters/ExpressionActions.h +++ b/src/Interpreters/ExpressionActions.h @@ -139,13 +139,8 @@ private: void executeOnTotals(Block & block) const; /// Executes action on block (modify it). Block could be splitted in case of JOIN. Then not_processed block is created. - void execute(Block & block, bool dry_run, ExtraBlockPtr & not_processed) const; - - void execute(Block & block, bool dry_run) const - { - ExtraBlockPtr extra; - execute(block, dry_run, extra); - } + void execute(Block & block, ExtraBlockPtr & not_processed) const; + void execute(Block & block, bool dry_run) const; }; diff --git a/src/Interpreters/InterpreterSelectQuery.cpp b/src/Interpreters/InterpreterSelectQuery.cpp index 6e36b06927c..695b9b87d52 100644 --- a/src/Interpreters/InterpreterSelectQuery.cpp +++ b/src/Interpreters/InterpreterSelectQuery.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -873,7 +874,8 @@ void InterpreterSelectQuery::executeImpl(QueryPlan & query_plan, const BlockInpu Block join_result_sample; JoinPtr join = expressions.join->getTableJoinAlgo(); - join_result_sample = ExpressionTransform::transformHeader(query_plan.getCurrentDataStream().header, expressions.join); + join_result_sample = InflatingExpressionTransform::transformHeader( + query_plan.getCurrentDataStream().header, expressions.join); QueryPlanStepPtr join_step = std::make_unique( query_plan.getCurrentDataStream(), diff --git a/src/Processors/QueryPlan/ExpressionStep.cpp b/src/Processors/QueryPlan/ExpressionStep.cpp index 75c07554318..534a25db65c 100644 --- a/src/Processors/QueryPlan/ExpressionStep.cpp +++ b/src/Processors/QueryPlan/ExpressionStep.cpp @@ -31,7 +31,7 @@ static void filterDistinctColumns(const Block & res_header, NameSet & distinct_c ExpressionStep::ExpressionStep(const DataStream & input_stream_, ExpressionActionsPtr expression_, bool default_totals_) : ITransformingStep( input_stream_, - ExpressionTransform::transformHeader(input_stream_.header, expression_), + Transform::transformHeader(input_stream_.header, expression_), getTraits(expression_)) , expression(std::move(expression_)) , default_totals(default_totals_) @@ -55,14 +55,14 @@ void ExpressionStep::transformPipeline(QueryPipeline & pipeline) pipeline.addSimpleTransform([&](const Block & header, QueryPipeline::StreamType stream_type) { bool on_totals = stream_type == QueryPipeline::StreamType::Totals; - return std::make_shared(header, expression, on_totals, add_default_totals); + return std::make_shared(header, expression, on_totals, add_default_totals); }); } InflatingExpressionStep::InflatingExpressionStep(const DataStream & input_stream_, ExpressionActionsPtr expression_, bool default_totals_) : ITransformingStep( input_stream_, - ExpressionTransform::transformHeader(input_stream_.header, expression_), + Transform::transformHeader(input_stream_.header, expression_), getTraits(expression_)) , expression(std::move(expression_)) , default_totals(default_totals_) @@ -84,7 +84,7 @@ void InflatingExpressionStep::transformPipeline(QueryPipeline & pipeline) pipeline.addSimpleTransform([&](const Block & header, QueryPipeline::StreamType stream_type) { bool on_totals = stream_type == QueryPipeline::StreamType::Totals; - return std::make_shared(header, expression, on_totals, add_default_totals); + return std::make_shared(header, expression, on_totals, add_default_totals); }); } diff --git a/src/Processors/QueryPlan/ExpressionStep.h b/src/Processors/QueryPlan/ExpressionStep.h index 4f268944c95..aef9f311d36 100644 --- a/src/Processors/QueryPlan/ExpressionStep.h +++ b/src/Processors/QueryPlan/ExpressionStep.h @@ -7,9 +7,14 @@ namespace DB class ExpressionActions; using ExpressionActionsPtr = std::shared_ptr; +class ExpressionTransform; +class InflatingExpressionTransform; + class ExpressionStep : public ITransformingStep { public: + using Transform = ExpressionTransform; + explicit ExpressionStep(const DataStream & input_stream_, ExpressionActionsPtr expression_, bool default_totals_ = false); String getName() const override { return "Expression"; } @@ -24,6 +29,8 @@ private: class InflatingExpressionStep : public ITransformingStep { public: + using Transform = InflatingExpressionTransform; + explicit InflatingExpressionStep(const DataStream & input_stream_, ExpressionActionsPtr expression_, bool default_totals_ = false); String getName() const override { return "Expression"; } diff --git a/src/Processors/Transforms/InflatingExpressionTransform.cpp b/src/Processors/Transforms/InflatingExpressionTransform.cpp index 5fc5bdc2304..167cf9e594f 100644 --- a/src/Processors/Transforms/InflatingExpressionTransform.cpp +++ b/src/Processors/Transforms/InflatingExpressionTransform.cpp @@ -5,9 +5,10 @@ namespace DB { -static Block transformHeader(Block header, const ExpressionActionsPtr & expression) +Block InflatingExpressionTransform::transformHeader(Block header, const ExpressionActionsPtr & expression) { - expression->execute(header, true); + ExtraBlockPtr tmp; + expression->execute(header, tmp); return header; } diff --git a/src/Processors/Transforms/InflatingExpressionTransform.h b/src/Processors/Transforms/InflatingExpressionTransform.h index ee77eaee19c..7cf472493d5 100644 --- a/src/Processors/Transforms/InflatingExpressionTransform.h +++ b/src/Processors/Transforms/InflatingExpressionTransform.h @@ -16,6 +16,8 @@ public: String getName() const override { return "InflatingExpressionTransform"; } + static Block transformHeader(Block header, const ExpressionActionsPtr & expression); + protected: void transform(Chunk & chunk) override; bool needInputData() const override { return !not_processed; }