Update json description for other steps.

This commit is contained in:
Nikolai Kochetov 2021-04-16 19:36:59 +03:00
parent 8f969ec063
commit 1bf420cbcf
34 changed files with 212 additions and 3 deletions

View File

@ -1,6 +1,7 @@
#include <Core/SortDescription.h>
#include <Core/Block.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -37,6 +38,22 @@ void dumpSortDescription(const SortDescription & description, const Block & head
}
}
void SortColumnDescription::explain(JSONBuilder::JSONMap & map, const Block & header) const
{
if (!column_name.empty())
map.add("Column", column_name);
else
{
if (column_number < header.columns())
map.add("Column", header.getByPosition(column_number).name);
map.add("Position", column_number);
}
map.add("Ascending", direction > 0);
map.add("With Fill", with_fill);
}
std::string dumpSortDescription(const SortDescription & description)
{
WriteBufferFromOwnString wb;
@ -44,5 +61,17 @@ std::string dumpSortDescription(const SortDescription & description)
return wb.str();
}
JSONBuilder::ItemPtr explainSortDescription(const SortDescription & description, const Block & header)
{
auto json_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & descr : description)
{
auto json_map = std::make_unique<JSONBuilder::JSONMap>();
descr.explain(*json_map, header);
json_array->add(std::move(json_map));
}
return json_array;
}
}

View File

@ -12,6 +12,15 @@ class Collator;
namespace DB
{
namespace JSONBuilder
{
class JSONMap;
class IItem;
using ItemPtr = std::unique_ptr<IItem>;
}
class Block;
struct FillColumnDescription
{
/// All missed values in range [FROM, TO) will be filled
@ -62,16 +71,18 @@ struct SortColumnDescription
{
return fmt::format("{}:{}:dir {}nulls ", column_name, column_number, direction, nulls_direction);
}
void explain(JSONBuilder::JSONMap & map, const Block & header) const;
};
/// Description of the sorting rule for several columns.
using SortDescription = std::vector<SortColumnDescription>;
class Block;
/// Outputs user-readable description into `out`.
void dumpSortDescription(const SortDescription & description, const Block & header, WriteBuffer & out);
std::string dumpSortDescription(const SortDescription & description);
JSONBuilder::ItemPtr explainSortDescription(const SortDescription & description, const Block & header);
}

View File

@ -228,6 +228,7 @@ BlockInputStreamPtr InterpreterExplainQuery::executeImpl()
MutableColumns res_columns = sample_block.cloneEmptyColumns();
WriteBufferFromOwnString buf;
bool single_line = false;
if (ast.getKind() == ASTExplainQuery::ParsedAST)
{
@ -275,6 +276,8 @@ BlockInputStreamPtr InterpreterExplainQuery::executeImpl()
JSONBuilder::FormatContext format_context{.out = buf};
plan_array->format(json_format_settings, format_context);
single_line = true;
}
else
plan.explainPlan(buf, settings.query_plan_options);
@ -310,7 +313,10 @@ BlockInputStreamPtr InterpreterExplainQuery::executeImpl()
}
}
fillColumn(*res_columns[0], buf.str());
if (single_line)
res_columns[0]->insertData(buf.str().data(), buf.str().size());
else
fillColumn(*res_columns[0], buf.str());
return std::make_shared<OneBlockInputStream>(sample_block.cloneWithColumns(std::move(res_columns)));
}

View File

@ -21,6 +21,9 @@ ActionsDAGPtr addMissingDefaults(
const ColumnsDescription & columns,
const Context & context)
{
std::cerr << "====== addMissingDefaults " << header.dumpStructure() << std::endl;
auto actions = std::make_shared<ActionsDAG>(header.getColumnsWithTypeAndName());
auto & index = actions->getIndex();

View File

@ -3,6 +3,7 @@
#include <Processors/Transforms/CreatingSetsTransform.h>
#include <IO/Operators.h>
#include <Interpreters/ExpressionActions.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -60,6 +61,15 @@ void CreatingSetStep::describeActions(FormatSettings & settings) const
settings.out << description << '\n';
}
void CreatingSetStep::describeActions(JSONBuilder::JSONMap & map) const
{
if (subquery_for_set.set)
map.add("Set", description);
else if (subquery_for_set.join)
map.add("Join", description);
}
CreatingSetsStep::CreatingSetsStep(DataStreams input_streams_)
{
if (input_streams_.empty())

View File

@ -21,6 +21,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
private:

View File

@ -2,6 +2,7 @@
#include <Processors/Transforms/DistinctTransform.h>
#include <Processors/QueryPipeline.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -102,4 +103,13 @@ void DistinctStep::describeActions(FormatSettings & settings) const
settings.out << '\n';
}
void DistinctStep::describeActions(JSONBuilder::JSONMap & map) const
{
auto columns_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & column : columns)
columns_array->add(column);
map.add("Columns", std::move(columns_array));
}
}

View File

@ -20,6 +20,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
private:

View File

@ -2,6 +2,7 @@
#include <Processors/Transforms/FillingTransform.h>
#include <Processors/QueryPipeline.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -50,4 +51,9 @@ void FillingStep::describeActions(FormatSettings & settings) const
settings.out << '\n';
}
void FillingStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Sort Description", explainSortDescription(sort_description, input_streams.front().header));
}
}

View File

@ -15,6 +15,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
const SortDescription & getSortDescription() const { return sort_description; }

View File

@ -4,6 +4,7 @@
#include <Processors/Transforms/ExpressionTransform.h>
#include <Interpreters/ExpressionActions.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -113,4 +114,13 @@ void FilterStep::describeActions(FormatSettings & settings) const
settings.out << '\n';
}
void FilterStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Filter Column", filter_column_name);
map.add("Removes Filter", remove_filter_column);
auto expression = std::make_shared<ExpressionActions>(actions_dag, ExpressionActionsSettings{});
map.add("Expression", expression->toTree());
}
}

View File

@ -22,6 +22,7 @@ public:
void updateInputStream(DataStream input_stream, bool keep_header);
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
const ActionsDAGPtr & getExpression() const { return actions_dag; }

View File

@ -5,6 +5,7 @@
#include <Processors/Transforms/PartialSortingTransform.h>
#include <Processors/Transforms/FinishSortingTransform.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -101,4 +102,13 @@ void FinishSortingStep::describeActions(FormatSettings & settings) const
settings.out << prefix << "Limit " << limit << '\n';
}
void FinishSortingStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Prefix Sort Description", explainSortDescription(prefix_description, input_streams.front().header));
map.add("Result Sort Description", explainSortDescription(result_description, input_streams.front().header));
if (limit)
map.add("Limit", limit);
}
}

View File

@ -20,6 +20,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
/// Add limit or change it to lower value.

View File

@ -2,6 +2,7 @@
#include <Processors/Transforms/LimitByTransform.h>
#include <Processors/QueryPipeline.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -72,4 +73,15 @@ void LimitByStep::describeActions(FormatSettings & settings) const
settings.out << prefix << "Offset " << group_offset << '\n';
}
void LimitByStep::describeActions(JSONBuilder::JSONMap & map) const
{
auto columns_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & column : columns)
columns_array->add(column);
map.add("Columns", std::move(columns_array));
map.add("Length", group_length);
map.add("Offset", group_offset);
}
}

View File

@ -16,6 +16,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
private:

View File

@ -2,6 +2,7 @@
#include <Processors/QueryPipeline.h>
#include <Processors/LimitTransform.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -76,4 +77,12 @@ void LimitStep::describeActions(FormatSettings & settings) const
}
}
void LimitStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Limit", limit);
map.add("Offset", offset);
map.add("With Ties", with_ties);
map.add("Reads All Data", always_read_till_end);
}
}

View File

@ -20,6 +20,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
size_t getLimitForSorting() const

View File

@ -2,6 +2,7 @@
#include <Processors/QueryPipeline.h>
#include <Processors/Transforms/MergeSortingTransform.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -84,4 +85,12 @@ void MergeSortingStep::describeActions(FormatSettings & settings) const
settings.out << prefix << "Limit " << limit << '\n';
}
void MergeSortingStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Sort Description", explainSortDescription(description, input_streams.front().header));
if (limit)
map.add("Limit", limit);
}
}

View File

@ -26,6 +26,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
/// Add limit or change it to lower value.

View File

@ -68,4 +68,9 @@ void MergingAggregatedStep::describeActions(FormatSettings & settings) const
return params->params.explain(settings.out, settings.offset);
}
void MergingAggregatedStep::describeActions(JSONBuilder::JSONMap & map) const
{
params->params.explain(map);
}
}

View File

@ -23,6 +23,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
private:

View File

@ -9,6 +9,7 @@
#include <Processors/Transforms/AddingSelectorTransform.h>
#include <Processors/Transforms/CopyTransform.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -161,4 +162,9 @@ void MergingFinal::describeActions(FormatSettings & settings) const
settings.out << '\n';
}
void MergingFinal::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Sort Description", explainSortDescription(sort_description, input_streams.front().header));
}
}

View File

@ -22,6 +22,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
private:

View File

@ -2,6 +2,7 @@
#include <Processors/QueryPipeline.h>
#include <Processors/Merges/MergingSortedTransform.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -73,4 +74,12 @@ void MergingSortedStep::describeActions(FormatSettings & settings) const
settings.out << prefix << "Limit " << limit << '\n';
}
void MergingSortedStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Sort Description", explainSortDescription(sort_description, input_streams.front().header));
if (limit)
map.add("Limit", limit);
}
}

View File

@ -21,6 +21,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
/// Add limit or change it to lower value.

View File

@ -2,6 +2,7 @@
#include <Processors/OffsetTransform.h>
#include <Processors/QueryPipeline.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -41,4 +42,9 @@ void OffsetStep::describeActions(FormatSettings & settings) const
settings.out << String(settings.offset, ' ') << "Offset " << offset << '\n';
}
void OffsetStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Offset", offset);
}
}

View File

@ -15,6 +15,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
private:

View File

@ -3,6 +3,7 @@
#include <Processors/Transforms/PartialSortingTransform.h>
#include <Processors/Transforms/LimitsCheckingTransform.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -81,4 +82,12 @@ void PartialSortingStep::describeActions(FormatSettings & settings) const
settings.out << prefix << "Limit " << limit << '\n';
}
void PartialSortingStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Sort Description", explainSortDescription(sort_description, input_streams.front().header));
if (limit)
map.add("Limit", limit);
}
}

View File

@ -20,6 +20,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
/// Add limit or change it to lower value.

View File

@ -4,6 +4,7 @@
#include <Processors/Transforms/TotalsHavingTransform.h>
#include <Interpreters/ExpressionActions.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -95,4 +96,15 @@ void TotalsHavingStep::describeActions(FormatSettings & settings) const
}
}
void TotalsHavingStep::describeActions(JSONBuilder::JSONMap & map) const
{
map.add("Mode", totalsModeToString(totals_mode, auto_include_threshold));
if (actions_dag)
{
map.add("Filter column", filter_column_name);
auto expression = std::make_shared<ExpressionActions>(actions_dag, ExpressionActionsSettings{});
map.add("Expression", expression->toTree());
}
}
}

View File

@ -26,6 +26,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings & settings) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
const ActionsDAGPtr & getActions() const { return actions_dag; }

View File

@ -5,6 +5,7 @@
#include <Processors/QueryPipeline.h>
#include <Interpreters/ExpressionActions.h>
#include <IO/Operators.h>
#include <Common/JSONBuilder.h>
namespace DB
{
@ -116,4 +117,25 @@ void WindowStep::describeActions(FormatSettings & settings) const
}
}
void WindowStep::describeActions(JSONBuilder::JSONMap & map) const
{
if (!window_description.partition_by.empty())
{
auto partion_columns_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & descr : window_description.partition_by)
partion_columns_array->add(descr.column_name);
map.add("Partition By", std::move(partion_columns_array));
}
if (!window_description.order_by.empty())
map.add("Sort Description", explainSortDescription(window_description.order_by, {}));
auto functions_array = std::make_unique<JSONBuilder::JSONArray>();
for (const auto & func : window_functions)
functions_array->add(func.column_name);
map.add("Functions", std::move(functions_array));
}
}

View File

@ -22,6 +22,7 @@ public:
void transformPipeline(QueryPipeline & pipeline, const BuildQueryPipelineSettings &) override;
void describeActions(JSONBuilder::JSONMap & map) const override;
void describeActions(FormatSettings & settings) const override;
private: