ClickHouse/src/Processors/QueryPlan/IQueryPlanStep.cpp

114 lines
2.9 KiB
C++
Raw Normal View History

2020-06-05 15:38:03 +00:00
#include <Processors/QueryPlan/IQueryPlanStep.h>
2020-06-25 09:39:17 +00:00
#include <Processors/IProcessor.h>
#include <IO/Operators.h>
2020-06-05 15:38:03 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
const DataStream & IQueryPlanStep::getOutputStream() const
{
if (!hasOutputStream())
throw Exception("QueryPlanStep " + getName() + " does not have output stream.", ErrorCodes::LOGICAL_ERROR);
return *output_stream;
}
2020-12-24 09:09:35 +00:00
static void doDescribeHeader(const Block & header, size_t count, IQueryPlanStep::FormatSettings & settings)
2020-06-26 13:58:28 +00:00
{
2020-07-07 19:51:32 +00:00
String prefix(settings.offset, settings.indent_char);
2020-06-26 13:58:28 +00:00
prefix += "Header";
if (count > 1)
2020-06-29 20:23:34 +00:00
prefix += " × " + std::to_string(count) + " ";
2020-06-26 13:58:28 +00:00
prefix += ": ";
settings.out << prefix;
if (!header)
{
settings.out << " empty\n";
return;
}
2020-07-07 19:51:32 +00:00
prefix.assign(prefix.size(), settings.indent_char);
2020-06-26 13:58:28 +00:00
bool first = true;
for (const auto & elem : header)
{
if (!first)
settings.out << prefix;
first = false;
elem.dumpNameAndType(settings.out);
2020-12-24 04:03:33 +00:00
settings.out << ": ";
elem.dumpStructure(settings.out);
2020-06-26 13:58:28 +00:00
settings.out << '\n';
}
}
2020-12-24 09:09:35 +00:00
static void doDescribeProcessor(const IProcessor & processor, size_t count, IQueryPlanStep::FormatSettings & settings)
2020-06-25 09:39:17 +00:00
{
2020-07-07 19:51:32 +00:00
settings.out << String(settings.offset, settings.indent_char) << processor.getName();
2020-06-25 09:39:17 +00:00
if (count > 1)
2020-06-29 20:23:34 +00:00
settings.out << " × " << std::to_string(count);
2020-06-25 09:39:17 +00:00
size_t num_inputs = processor.getInputs().size();
size_t num_outputs = processor.getOutputs().size();
if (num_inputs != 1 || num_outputs != 1)
2020-06-29 20:23:34 +00:00
settings.out << " " << std::to_string(num_inputs) << "" << std::to_string(num_outputs);
2020-06-25 09:39:17 +00:00
settings.out << '\n';
2020-06-26 13:58:28 +00:00
if (settings.write_header)
{
const Block * last_header = nullptr;
size_t num_equal_headers = 0;
for (const auto & port : processor.getOutputs())
{
if (last_header && !blocksHaveEqualStructure(*last_header, port.getHeader()))
{
doDescribeHeader(*last_header, num_equal_headers, settings);
num_equal_headers = 0;
}
++num_equal_headers;
last_header = &port.getHeader();
}
if (last_header)
doDescribeHeader(*last_header, num_equal_headers, settings);
}
2020-07-07 19:51:32 +00:00
settings.offset += settings.indent;
2020-06-25 09:39:17 +00:00
}
2020-12-24 09:09:35 +00:00
void IQueryPlanStep::describePipeline(const Processors & processors, FormatSettings & settings)
2020-06-25 09:39:17 +00:00
{
const IProcessor * prev = nullptr;
size_t count = 0;
for (auto it = processors.rbegin(); it != processors.rend(); ++it)
{
if (prev && prev->getName() != (*it)->getName())
{
doDescribeProcessor(*prev, count, settings);
count = 0;
}
++count;
prev = it->get();
}
if (prev)
doDescribeProcessor(*prev, count, settings);
}
2020-06-05 15:38:03 +00:00
}