Use setting for explain json

This commit is contained in:
Nikolai Kochetov 2021-04-13 10:51:55 +03:00
parent 48bcd5b490
commit d1d2b89a51
3 changed files with 30 additions and 9 deletions

View File

@ -262,7 +262,7 @@ BlockInputStreamPtr InterpreterExplainQuery::executeImpl()
if (settings.json)
{
auto tree = plan.explainPlan();
auto tree = plan.explainPlan(settings.query_plan_options);
std::stringstream out;
boost::property_tree::json_parser::write_json(out, tree);
buf.str() = out.str();

View File

@ -201,21 +201,42 @@ void QueryPlan::addInterpreterContext(std::shared_ptr<Context> context)
}
static boost::property_tree::ptree explainStep(const IQueryPlanStep & step)
static boost::property_tree::ptree explainStep(const IQueryPlanStep & step, const QueryPlan::ExplainPlanOptions & options)
{
boost::property_tree::ptree tree;
tree.put("Node Type", step.getName());
const auto & description = step.getStepDescription();
if (!description.empty())
tree.put("Description", description);
if (options.description)
{
const auto & description = step.getStepDescription();
if (!description.empty())
tree.put("Description", description);
}
step.describeActions(tree);
if (options.header && step.hasOutputStream())
{
boost::property_tree::ptree header_tree;
for (const auto & output_column : step.getOutputStream().header)
{
boost::property_tree::ptree column_tree;
column_tree.add("Name", output_column.name);
if (output_column.type)
column_tree.add("Type", output_column.type->getName());
header_tree.add_child("", column_tree);
}
tree.add_child("Header", header_tree);
}
if (options.actions)
step.describeActions(tree);
return tree;
}
boost::property_tree::ptree QueryPlan::explainPlan()
boost::property_tree::ptree QueryPlan::explainPlan(const ExplainPlanOptions & options)
{
checkInitialized();
@ -237,7 +258,7 @@ boost::property_tree::ptree QueryPlan::explainPlan()
auto & frame = stack.top();
if (frame.next_child == 0)
frame.node_tree = explainStep(*frame.node->step);
frame.node_tree = explainStep(*frame.node->step, options);
if (frame.next_child < frame.node->children.size())
{

View File

@ -74,7 +74,7 @@ public:
bool header = false;
};
boost::property_tree::ptree explainPlan();
boost::property_tree::ptree explainPlan(const ExplainPlanOptions & options);
void explainPlan(WriteBuffer & buffer, const ExplainPlanOptions & options);
void explainPipeline(WriteBuffer & buffer, const ExplainPipelineOptions & options);