From ca01094f4b7dbdb18c2bc4b16e595fc946ed13b4 Mon Sep 17 00:00:00 2001 From: Nikolai Kochetov Date: Wed, 24 Jun 2020 15:09:01 +0300 Subject: [PATCH] More actions description. --- src/Core/SortDescription.cpp | 41 ++++++++++++ src/Core/SortDescription.h | 3 + src/Core/ya.make | 1 + src/Interpreters/AggregateDescription.cpp | 62 ++++++++++--------- src/Interpreters/Aggregator.cpp | 24 +++++-- src/Interpreters/InterpreterSelectQuery.cpp | 4 +- src/Processors/QueryPlan/ConvertingStep.cpp | 30 +++++++++ src/Processors/QueryPlan/ConvertingStep.h | 2 + src/Processors/QueryPlan/CreatingSetsStep.cpp | 17 +++++ src/Processors/QueryPlan/CreatingSetsStep.h | 2 + src/Processors/QueryPlan/DistinctStep.cpp | 14 +++++ src/Processors/QueryPlan/DistinctStep.h | 2 + src/Processors/QueryPlan/ExpressionStep.cpp | 20 ++++++ src/Processors/QueryPlan/ExpressionStep.h | 4 ++ src/Processors/QueryPlan/FillingStep.cpp | 5 ++ src/Processors/QueryPlan/FillingStep.h | 2 + src/Processors/QueryPlan/FilterStep.cpp | 12 ++++ src/Processors/QueryPlan/FilterStep.h | 2 + .../QueryPlan/FinishSortingStep.cpp | 13 ++++ src/Processors/QueryPlan/FinishSortingStep.h | 2 + src/Processors/QueryPlan/LimitByStep.cpp | 19 ++++++ src/Processors/QueryPlan/LimitByStep.h | 2 + src/Processors/QueryPlan/LimitStep.cpp | 26 ++++++++ src/Processors/QueryPlan/LimitStep.h | 2 + src/Processors/QueryPlan/MergeSortingStep.cpp | 11 ++++ src/Processors/QueryPlan/MergeSortingStep.h | 2 + .../QueryPlan/MergingAggregatedStep.cpp | 5 ++ .../QueryPlan/MergingAggregatedStep.h | 2 + .../QueryPlan/MergingSortedStep.cpp | 10 +++ src/Processors/QueryPlan/MergingSortedStep.h | 2 + .../{OffsetsStep.cpp => OffsetStep.cpp} | 11 +++- .../QueryPlan/{OffsetsStep.h => OffsetStep.h} | 8 ++- .../QueryPlan/PartialSortingStep.cpp | 10 +++ src/Processors/QueryPlan/PartialSortingStep.h | 2 + src/Processors/QueryPlan/QueryPlan.cpp | 13 +--- src/Processors/QueryPlan/TotalsHavingStep.cpp | 31 ++++++++++ src/Processors/QueryPlan/TotalsHavingStep.h | 2 + .../Transforms/ConvertingTransform.h | 2 + src/Processors/ya.make | 2 +- 39 files changed, 368 insertions(+), 56 deletions(-) create mode 100644 src/Core/SortDescription.cpp rename src/Processors/QueryPlan/{OffsetsStep.cpp => OffsetStep.cpp} (70%) rename src/Processors/QueryPlan/{OffsetsStep.h => OffsetStep.h} (51%) diff --git a/src/Core/SortDescription.cpp b/src/Core/SortDescription.cpp new file mode 100644 index 0000000000..e27c39dbb5 --- /dev/null +++ b/src/Core/SortDescription.cpp @@ -0,0 +1,41 @@ +#include +#include + +namespace DB +{ + +String dumpSortDescription(const SortDescription & description, const Block & header) +{ + String res; + + for (const auto & desc : description) + { + if (!res.empty()) + res += ", "; + + if (!desc.column_name.empty()) + res += desc.column_name; + else + { + if (desc.column_number < header.columns()) + res += header.getByPosition(desc.column_number).name; + else + res += "?"; + + res += " (pos " + std::to_string(desc.column_number) + ")"; + } + + if (desc.direction > 0) + res += " ASC"; + else + res += " DESC"; + + if (desc.with_fill) + res += " WITH FILL"; + } + + return res; +} + +} + diff --git a/src/Core/SortDescription.h b/src/Core/SortDescription.h index 86e4bb573e..a155032edf 100644 --- a/src/Core/SortDescription.h +++ b/src/Core/SortDescription.h @@ -71,4 +71,7 @@ struct SortColumnDescription /// Description of the sorting rule for several columns. using SortDescription = std::vector; +class Block; +String dumpSortDescription(const SortDescription & description, const Block & header); + } diff --git a/src/Core/ya.make b/src/Core/ya.make index 06fed2dc25..14d609dfa9 100644 --- a/src/Core/ya.make +++ b/src/Core/ya.make @@ -20,6 +20,7 @@ SRCS( NamesAndTypes.cpp Settings.cpp SettingsCollection.cpp + SortDescription.cpp ) END() diff --git a/src/Interpreters/AggregateDescription.cpp b/src/Interpreters/AggregateDescription.cpp index ed737bd4fa..53ecd3159e 100644 --- a/src/Interpreters/AggregateDescription.cpp +++ b/src/Interpreters/AggregateDescription.cpp @@ -7,34 +7,8 @@ namespace DB Strings AggregateDescription::explain() const { Strings res; - String arguments_pos_str; - for (auto arg : arguments) - { - if (!arguments_pos_str.empty()) - arguments_pos_str += ", "; - arguments_pos_str += std::to_string(arg); - } - - if (arguments_pos_str.empty()) - arguments_pos_str = "none"; - - res.emplace_back("argument positions: " + arguments_pos_str); - - String arguments_names_str; - for (const auto & arg : argument_names) - { - if (!arguments_names_str.empty()) - arguments_names_str += ", "; - - arguments_names_str += arg; - } - - if (arguments_names_str.empty()) - arguments_names_str = "none"; - - res.emplace_back("arguments: " + arguments_names_str); - res.emplace_back("column_name: " + column_name); + res.emplace_back(column_name); auto get_params_string = [](const Array & arr) { @@ -65,14 +39,42 @@ Strings AggregateDescription::explain() const if (!params_str.empty()) params_str = "(" + params_str + ")"; - res.emplace_back("function: " + function->getName() + params_str + '(' + types_str + ") -> " + + res.emplace_back(" Function: " + function->getName() + params_str + '(' + types_str + ") -> " + function->getReturnType()->getName()); } else - res.emplace_back("function: nullptr"); + res.emplace_back(" Function: nullptr"); if (!parameters.empty()) - res.emplace_back("parameters: " + get_params_string(parameters)); + res.emplace_back(" Parameters: " + get_params_string(parameters)); + + String arguments_names_str; + for (const auto & arg : argument_names) + { + if (!arguments_names_str.empty()) + arguments_names_str += ", "; + + arguments_names_str += arg; + } + + if (arguments_names_str.empty()) + arguments_names_str = "none"; + + res.emplace_back(" Arguments: " + arguments_names_str); + + String arguments_pos_str; + for (auto arg : arguments) + { + if (!arguments_pos_str.empty()) + arguments_pos_str += ", "; + + arguments_pos_str += std::to_string(arg); + } + + if (arguments_pos_str.empty()) + arguments_pos_str = "none"; + + res.emplace_back(" Argument positions: " + arguments_pos_str); return res; } diff --git a/src/Interpreters/Aggregator.cpp b/src/Interpreters/Aggregator.cpp index c30c8faac1..8c20698f42 100644 --- a/src/Interpreters/Aggregator.cpp +++ b/src/Interpreters/Aggregator.cpp @@ -158,21 +158,33 @@ Strings Aggregator::Params::explain() const String keys_str; for (auto key : keys) { - if (keys_str.empty()) + if (!keys_str.empty()) keys_str += ", "; if (key >= header.columns()) keys_str += "unknown position " + std::to_string(key); else - keys_str += src_header.getByPosition(key).name; + keys_str += header.getByPosition(key).name; } - res.emplace_back("keys: " + std::move(keys_str)); + res.emplace_back("Keys: " + std::move(keys_str)); - for (const auto & aggregate : aggregates) + if (!aggregates.empty()) { - auto aggregate_strings = aggregate.explain(); - res.insert(res.end(), aggregate_strings.begin(), aggregate_strings.end()); + bool first = true; + for (const auto & aggregate : aggregates) + { + auto aggregate_strings = aggregate.explain(); + for (const auto & aggregate_str : aggregate_strings) + { + if (first) + res.emplace_back("Aggregates: " + aggregate_str); + else + res.emplace_back(" " + aggregate_str); + + first = false; + } + } } return res; diff --git a/src/Interpreters/InterpreterSelectQuery.cpp b/src/Interpreters/InterpreterSelectQuery.cpp index 7fbfdf2395..401e558385 100644 --- a/src/Interpreters/InterpreterSelectQuery.cpp +++ b/src/Interpreters/InterpreterSelectQuery.cpp @@ -53,7 +53,7 @@ #include #include #include -#include +#include #include #include @@ -1792,7 +1792,7 @@ void InterpreterSelectQuery::executeOffset(QueryPlan & query_plan) UInt64 limit_offset; std::tie(limit_length, limit_offset) = getLimitLengthAndOffset(query, *context); - auto offsets_step = std::make_unique(query_plan.getCurrentDataStream(), limit_offset); + auto offsets_step = std::make_unique(query_plan.getCurrentDataStream(), limit_offset); query_plan.addStep(std::move(offsets_step)); } } diff --git a/src/Processors/QueryPlan/ConvertingStep.cpp b/src/Processors/QueryPlan/ConvertingStep.cpp index 99287c50b9..3c5238d4fd 100644 --- a/src/Processors/QueryPlan/ConvertingStep.cpp +++ b/src/Processors/QueryPlan/ConvertingStep.cpp @@ -46,4 +46,34 @@ void ConvertingStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings ConvertingStep::describeActions() const +{ + const auto & header = input_streams[0].header; + auto conversion = ConvertingTransform(header, result_header, ConvertingTransform::MatchColumnsMode::Name) + .getConversion(); + + Strings res; + + auto get_description = [](const ColumnWithTypeAndName & elem, bool is_const) + { + return elem.name + " " + elem.type->getName() + (is_const ? " Const" : ""); + }; + + for (size_t i = 0; i < conversion.size(); ++i) + { + const auto & from = header.getByPosition(conversion[i]); + const auto & to = result_header.getByPosition(i); + + bool from_const = from.column && isColumnConst(*from.column); + bool to_const = to.column && isColumnConst(*to.column); + + if (from.name == to.name && from.type->equals(*to.type) && from_const == to_const) + res.emplace_back(get_description(from, from_const)); + else + res.emplace_back(get_description(to, to_const) + " <- " + get_description(from, from_const)); + } + + return res; +} + } diff --git a/src/Processors/QueryPlan/ConvertingStep.h b/src/Processors/QueryPlan/ConvertingStep.h index 540deece24..bf0840b1f9 100644 --- a/src/Processors/QueryPlan/ConvertingStep.h +++ b/src/Processors/QueryPlan/ConvertingStep.h @@ -13,6 +13,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: Block result_header; }; diff --git a/src/Processors/QueryPlan/CreatingSetsStep.cpp b/src/Processors/QueryPlan/CreatingSetsStep.cpp index 4480fd53f3..2f47c7abbb 100644 --- a/src/Processors/QueryPlan/CreatingSetsStep.cpp +++ b/src/Processors/QueryPlan/CreatingSetsStep.cpp @@ -35,4 +35,21 @@ void CreatingSetsStep::transformPipeline(QueryPipeline & pipeline) pipeline.addCreatingSetsTransform(std::move(creating_sets)); } +Strings CreatingSetsStep::describeActions() const +{ + Strings res; + for (const auto & set : subqueries_for_sets) + { + String str; + if (set.second.set) + str += "Set: "; + else if (set.second.join) + str += "Join: "; + + str += set.first; + } + + return res; +} + } diff --git a/src/Processors/QueryPlan/CreatingSetsStep.h b/src/Processors/QueryPlan/CreatingSetsStep.h index d3c4db3050..7f05de4b88 100644 --- a/src/Processors/QueryPlan/CreatingSetsStep.h +++ b/src/Processors/QueryPlan/CreatingSetsStep.h @@ -19,6 +19,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: SubqueriesForSets subqueries_for_sets; SizeLimits network_transfer_limits; diff --git a/src/Processors/QueryPlan/DistinctStep.cpp b/src/Processors/QueryPlan/DistinctStep.cpp index 0e1cab637f..1a55866928 100644 --- a/src/Processors/QueryPlan/DistinctStep.cpp +++ b/src/Processors/QueryPlan/DistinctStep.cpp @@ -65,4 +65,18 @@ void DistinctStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings DistinctStep::describeActions() const +{ + String res; + for (const auto & column : columns) + { + if (!res.empty()) + res += ", "; + + res += column; + } + + return {"Columns: " + res}; +} + } diff --git a/src/Processors/QueryPlan/DistinctStep.h b/src/Processors/QueryPlan/DistinctStep.h index 5ec6e683bb..8af909c60d 100644 --- a/src/Processors/QueryPlan/DistinctStep.h +++ b/src/Processors/QueryPlan/DistinctStep.h @@ -19,6 +19,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: SizeLimits set_size_limits; UInt64 limit_hint; diff --git a/src/Processors/QueryPlan/ExpressionStep.cpp b/src/Processors/QueryPlan/ExpressionStep.cpp index 75c0755431..5d765c6fd3 100644 --- a/src/Processors/QueryPlan/ExpressionStep.cpp +++ b/src/Processors/QueryPlan/ExpressionStep.cpp @@ -59,6 +59,21 @@ void ExpressionStep::transformPipeline(QueryPipeline & pipeline) }); } +static Strings getActionsDescription(const ExpressionActionsPtr & expression) +{ + Strings res; + for (const auto & action : expression->getActions()) + res.emplace_back((res.empty() ? "Actions: " + : " ") + action.toString()); + + return res; +} + +Strings ExpressionStep::describeActions() const +{ + return getActionsDescription(expression); +} + InflatingExpressionStep::InflatingExpressionStep(const DataStream & input_stream_, ExpressionActionsPtr expression_, bool default_totals_) : ITransformingStep( input_stream_, @@ -88,4 +103,9 @@ void InflatingExpressionStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings InflatingExpressionStep::describeActions() const +{ + return getActionsDescription(expression); +} + } diff --git a/src/Processors/QueryPlan/ExpressionStep.h b/src/Processors/QueryPlan/ExpressionStep.h index 4f268944c9..c6685e5e86 100644 --- a/src/Processors/QueryPlan/ExpressionStep.h +++ b/src/Processors/QueryPlan/ExpressionStep.h @@ -15,6 +15,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: ExpressionActionsPtr expression; bool default_totals; /// See ExpressionTransform @@ -29,6 +31,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: ExpressionActionsPtr expression; bool default_totals; /// See ExpressionTransform diff --git a/src/Processors/QueryPlan/FillingStep.cpp b/src/Processors/QueryPlan/FillingStep.cpp index 80dba79494..b4a2a6d296 100644 --- a/src/Processors/QueryPlan/FillingStep.cpp +++ b/src/Processors/QueryPlan/FillingStep.cpp @@ -27,4 +27,9 @@ void FillingStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings FillingStep::describeActions() const +{ + return {"Sort description: " + dumpSortDescription(sort_description, input_streams.front().header)}; +} + } diff --git a/src/Processors/QueryPlan/FillingStep.h b/src/Processors/QueryPlan/FillingStep.h index e7ec7ab17d..80f7e00dcf 100644 --- a/src/Processors/QueryPlan/FillingStep.h +++ b/src/Processors/QueryPlan/FillingStep.h @@ -14,6 +14,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: SortDescription sort_description; }; diff --git a/src/Processors/QueryPlan/FilterStep.cpp b/src/Processors/QueryPlan/FilterStep.cpp index 38ab4471e5..7bef168cd9 100644 --- a/src/Processors/QueryPlan/FilterStep.cpp +++ b/src/Processors/QueryPlan/FilterStep.cpp @@ -55,4 +55,16 @@ void FilterStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings FilterStep::describeActions() const +{ + Strings res; + res.emplace_back("Filter column: " + filter_column_name); + + for (const auto & action : expression->getActions()) + res.emplace_back((res.size() == 1 ? "Actions: " + : " ") + action.toString()); + + return res; +} + } diff --git a/src/Processors/QueryPlan/FilterStep.h b/src/Processors/QueryPlan/FilterStep.h index faadd41a58..3f2f8b431f 100644 --- a/src/Processors/QueryPlan/FilterStep.h +++ b/src/Processors/QueryPlan/FilterStep.h @@ -19,6 +19,8 @@ public: String getName() const override { return "Filter"; } void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: ExpressionActionsPtr expression; String filter_column_name; diff --git a/src/Processors/QueryPlan/FinishSortingStep.cpp b/src/Processors/QueryPlan/FinishSortingStep.cpp index 4b0e6d6a66..bb0b081637 100644 --- a/src/Processors/QueryPlan/FinishSortingStep.cpp +++ b/src/Processors/QueryPlan/FinishSortingStep.cpp @@ -69,4 +69,17 @@ void FinishSortingStep::transformPipeline(QueryPipeline & pipeline) } } +Strings FinishSortingStep::describeActions() const +{ + Strings res = { + "Prefix sort description: " + dumpSortDescription(prefix_description, input_streams.front().header), + "Result sort description: " + dumpSortDescription(result_description, input_streams.front().header) + }; + + if (limit) + res.emplace_back("Limit " + std::to_string(limit)); + + return res; +} + } diff --git a/src/Processors/QueryPlan/FinishSortingStep.h b/src/Processors/QueryPlan/FinishSortingStep.h index 43bdf261e9..cc7dfe1388 100644 --- a/src/Processors/QueryPlan/FinishSortingStep.h +++ b/src/Processors/QueryPlan/FinishSortingStep.h @@ -19,6 +19,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: SortDescription prefix_description; SortDescription result_description; diff --git a/src/Processors/QueryPlan/LimitByStep.cpp b/src/Processors/QueryPlan/LimitByStep.cpp index e18df84258..05d346f9ae 100644 --- a/src/Processors/QueryPlan/LimitByStep.cpp +++ b/src/Processors/QueryPlan/LimitByStep.cpp @@ -37,4 +37,23 @@ void LimitByStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings LimitByStep::describeActions() const +{ + Strings res; + String columns_str; + for (const auto & column : columns) + { + if (!columns_str.empty()) + columns_str += ", "; + + columns_str += column; + } + + return { + "Columns: " + columns_str, + "Length " + std::to_string(group_length), + "Offset " + std::to_string(group_offset), + }; +} + } diff --git a/src/Processors/QueryPlan/LimitByStep.h b/src/Processors/QueryPlan/LimitByStep.h index 744918cb83..b12c85b917 100644 --- a/src/Processors/QueryPlan/LimitByStep.h +++ b/src/Processors/QueryPlan/LimitByStep.h @@ -15,6 +15,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: size_t group_length; size_t group_offset; diff --git a/src/Processors/QueryPlan/LimitStep.cpp b/src/Processors/QueryPlan/LimitStep.cpp index 4b7928bfc5..f6c2c2dee4 100644 --- a/src/Processors/QueryPlan/LimitStep.cpp +++ b/src/Processors/QueryPlan/LimitStep.cpp @@ -35,4 +35,30 @@ void LimitStep::transformPipeline(QueryPipeline & pipeline) pipeline.addPipe({std::move(transform)}); } +Strings LimitStep::describeActions() const +{ + Strings res; + res.emplace_back("Limit " + std::to_string(limit)); + res.emplace_back("Offset " + std::to_string(offset)); + + if (with_ties || always_read_till_end) + { + String str; + if (with_ties) + str += "WITH TIES"; + + if (always_read_till_end) + { + if (!str.empty()) + str += ", "; + + str += "Reads all data"; + } + + res.emplace_back(str); + } + + return res; +} + } diff --git a/src/Processors/QueryPlan/LimitStep.h b/src/Processors/QueryPlan/LimitStep.h index 4a12e8f670..2bb0f53781 100644 --- a/src/Processors/QueryPlan/LimitStep.h +++ b/src/Processors/QueryPlan/LimitStep.h @@ -20,6 +20,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: size_t limit; size_t offset; diff --git a/src/Processors/QueryPlan/MergeSortingStep.cpp b/src/Processors/QueryPlan/MergeSortingStep.cpp index 4c8f265c2c..d61a6e721e 100644 --- a/src/Processors/QueryPlan/MergeSortingStep.cpp +++ b/src/Processors/QueryPlan/MergeSortingStep.cpp @@ -48,4 +48,15 @@ void MergeSortingStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings MergeSortingStep::describeActions() const +{ + Strings res = {"Sort description: " + dumpSortDescription(description, input_streams.front().header)}; + + if (limit) + res.emplace_back("Limit " + std::to_string(limit)); + + return res; +} + + } diff --git a/src/Processors/QueryPlan/MergeSortingStep.h b/src/Processors/QueryPlan/MergeSortingStep.h index 3d12bda313..49645180cf 100644 --- a/src/Processors/QueryPlan/MergeSortingStep.h +++ b/src/Processors/QueryPlan/MergeSortingStep.h @@ -24,6 +24,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: SortDescription description; size_t max_merged_block_size; diff --git a/src/Processors/QueryPlan/MergingAggregatedStep.cpp b/src/Processors/QueryPlan/MergingAggregatedStep.cpp index 459a0b9004..de085c44b8 100644 --- a/src/Processors/QueryPlan/MergingAggregatedStep.cpp +++ b/src/Processors/QueryPlan/MergingAggregatedStep.cpp @@ -63,4 +63,9 @@ void MergingAggregatedStep::transformPipeline(QueryPipeline & pipeline) pipeline.enableQuotaForCurrentStreams(); } +Strings MergingAggregatedStep::describeActions() const +{ + return params->params.explain(); +} + } diff --git a/src/Processors/QueryPlan/MergingAggregatedStep.h b/src/Processors/QueryPlan/MergingAggregatedStep.h index 51a907285d..8b22495b5a 100644 --- a/src/Processors/QueryPlan/MergingAggregatedStep.h +++ b/src/Processors/QueryPlan/MergingAggregatedStep.h @@ -22,6 +22,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: AggregatingTransformParamsPtr params; bool memory_efficient_aggregation; diff --git a/src/Processors/QueryPlan/MergingSortedStep.cpp b/src/Processors/QueryPlan/MergingSortedStep.cpp index 9c4bf87451..a362a2b0c2 100644 --- a/src/Processors/QueryPlan/MergingSortedStep.cpp +++ b/src/Processors/QueryPlan/MergingSortedStep.cpp @@ -46,4 +46,14 @@ void MergingSortedStep::transformPipeline(QueryPipeline & pipeline) } } +Strings MergingSortedStep::describeActions() const +{ + Strings res = {"Sort description: " + dumpSortDescription(sort_description, input_streams.front().header)}; + + if (limit) + res.emplace_back("Limit " + std::to_string(limit)); + + return res; +} + } diff --git a/src/Processors/QueryPlan/MergingSortedStep.h b/src/Processors/QueryPlan/MergingSortedStep.h index 920073da8c..40803cef0c 100644 --- a/src/Processors/QueryPlan/MergingSortedStep.h +++ b/src/Processors/QueryPlan/MergingSortedStep.h @@ -20,6 +20,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: SortDescription sort_description; size_t max_block_size; diff --git a/src/Processors/QueryPlan/OffsetsStep.cpp b/src/Processors/QueryPlan/OffsetStep.cpp similarity index 70% rename from src/Processors/QueryPlan/OffsetsStep.cpp rename to src/Processors/QueryPlan/OffsetStep.cpp index e09a169f4b..27da67c2be 100644 --- a/src/Processors/QueryPlan/OffsetsStep.cpp +++ b/src/Processors/QueryPlan/OffsetStep.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include @@ -13,13 +13,13 @@ static ITransformingStep::DataStreamTraits getTraits() }; } -OffsetsStep::OffsetsStep(const DataStream & input_stream_, size_t offset_) +OffsetStep::OffsetStep(const DataStream & input_stream_, size_t offset_) : ITransformingStep(input_stream_, input_stream_.header, getTraits()) , offset(offset_) { } -void OffsetsStep::transformPipeline(QueryPipeline & pipeline) +void OffsetStep::transformPipeline(QueryPipeline & pipeline) { pipeline.addSimpleTransform([&](const Block & header, QueryPipeline::StreamType stream_type) -> ProcessorPtr { @@ -30,4 +30,9 @@ void OffsetsStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings OffsetStep::describeActions() const +{ + return {"Offset " + std::to_string(offset)}; +} + } diff --git a/src/Processors/QueryPlan/OffsetsStep.h b/src/Processors/QueryPlan/OffsetStep.h similarity index 51% rename from src/Processors/QueryPlan/OffsetsStep.h rename to src/Processors/QueryPlan/OffsetStep.h index 83f0c43dd7..167b65f6fd 100644 --- a/src/Processors/QueryPlan/OffsetsStep.h +++ b/src/Processors/QueryPlan/OffsetStep.h @@ -5,15 +5,17 @@ namespace DB { -class OffsetsStep : public ITransformingStep +class OffsetStep : public ITransformingStep { public: - OffsetsStep(const DataStream & input_stream_, size_t offset_); + OffsetStep(const DataStream & input_stream_, size_t offset_); - String getName() const override { return "Offsets"; } + String getName() const override { return "Offset"; } void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: size_t offset; }; diff --git a/src/Processors/QueryPlan/PartialSortingStep.cpp b/src/Processors/QueryPlan/PartialSortingStep.cpp index c8be58eb32..767eebf6f0 100644 --- a/src/Processors/QueryPlan/PartialSortingStep.cpp +++ b/src/Processors/QueryPlan/PartialSortingStep.cpp @@ -50,4 +50,14 @@ void PartialSortingStep::transformPipeline(QueryPipeline & pipeline) }); } +Strings PartialSortingStep::describeActions() const +{ + Strings res = {"Sort description: " + dumpSortDescription(sort_description, input_streams.front().header)}; + + if (limit) + res.emplace_back("Limit " + std::to_string(limit)); + + return res; +} + } diff --git a/src/Processors/QueryPlan/PartialSortingStep.h b/src/Processors/QueryPlan/PartialSortingStep.h index c4967e8ec3..fd2526c23a 100644 --- a/src/Processors/QueryPlan/PartialSortingStep.h +++ b/src/Processors/QueryPlan/PartialSortingStep.h @@ -19,6 +19,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: SortDescription sort_description; UInt64 limit; diff --git a/src/Processors/QueryPlan/QueryPlan.cpp b/src/Processors/QueryPlan/QueryPlan.cpp index 65b0fc6b33..035216abb2 100644 --- a/src/Processors/QueryPlan/QueryPlan.cpp +++ b/src/Processors/QueryPlan/QueryPlan.cpp @@ -207,7 +207,7 @@ static void explainStep( for (const auto & elem : step.getOutputStream().header) { if (!first) - buffer << ",\n" << prefix << " "; + buffer << "\n" << prefix << " "; first = false; elem.dumpStructure(buffer, true); @@ -222,17 +222,8 @@ static void explainStep( auto actions = step.describeActions(); if (!actions.empty()) { - buffer << "Actions: "; - bool first = true; - for (auto & action : actions) - { - if (!first) - buffer << ",\n" << prefix << " "; - - first = false; - buffer << action; - } + buffer << prefix << action << '\n'; } } } diff --git a/src/Processors/QueryPlan/TotalsHavingStep.cpp b/src/Processors/QueryPlan/TotalsHavingStep.cpp index ec3788bc7d..70b35ee7f9 100644 --- a/src/Processors/QueryPlan/TotalsHavingStep.cpp +++ b/src/Processors/QueryPlan/TotalsHavingStep.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace DB { @@ -44,4 +45,34 @@ void TotalsHavingStep::transformPipeline(QueryPipeline & pipeline) pipeline.addTotalsHavingTransform(std::move(totals_having)); } +static String totalsModeToString(TotalsMode totals_mode, double auto_include_threshold) +{ + switch (totals_mode) + { + case TotalsMode::BEFORE_HAVING: + return "before_having"; + case TotalsMode::AFTER_HAVING_INCLUSIVE: + return "after_having_inclusive"; + case TotalsMode::AFTER_HAVING_EXCLUSIVE: + return "after_having_exclusive"; + case TotalsMode::AFTER_HAVING_AUTO: + return "after_having_auto threshold " + std::to_string(auto_include_threshold); + } + + __builtin_unreachable(); +} + +Strings TotalsHavingStep::describeActions() const +{ + Strings res; + res.emplace_back("Filter column: " + filter_column_name); + res.emplace_back("Mode: " + totalsModeToString(totals_mode, auto_include_threshold)); + + for (const auto & action : expression->getActions()) + res.emplace_back((res.size() == 2 ? "Actions: " + : " ") + action.toString()); + + return res; +} + } diff --git a/src/Processors/QueryPlan/TotalsHavingStep.h b/src/Processors/QueryPlan/TotalsHavingStep.h index 52cc936f62..e2dd2f4dd5 100644 --- a/src/Processors/QueryPlan/TotalsHavingStep.h +++ b/src/Processors/QueryPlan/TotalsHavingStep.h @@ -25,6 +25,8 @@ public: void transformPipeline(QueryPipeline & pipeline) override; + Strings describeActions() const override; + private: bool overflow_row; ExpressionActionsPtr expression; diff --git a/src/Processors/Transforms/ConvertingTransform.h b/src/Processors/Transforms/ConvertingTransform.h index 45a6688c07..b4b42dcb6e 100644 --- a/src/Processors/Transforms/ConvertingTransform.h +++ b/src/Processors/Transforms/ConvertingTransform.h @@ -35,6 +35,8 @@ public: String getName() const override { return "Converting"; } + const ColumnNumbers & getConversion() const { return conversion; } + protected: void transform(Chunk & chunk) override; diff --git a/src/Processors/ya.make b/src/Processors/ya.make index 4e6ec2372d..550aa9ad7d 100644 --- a/src/Processors/ya.make +++ b/src/Processors/ya.make @@ -157,7 +157,7 @@ SRCS( QueryPlan/MergeSortingStep.cpp QueryPlan/MergingAggregatedStep.cpp QueryPlan/MergingSortedStep.cpp - QueryPlan/OffsetsStep.cpp + QueryPlan/OffsetStep.cpp QueryPlan/PartialSortingStep.cpp QueryPlan/UnionStep.cpp QueryPlan/ReadFromPreparedSource.cpp -- GitLab