Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better exception message for invalid pipeline #9868

Merged
merged 4 commits into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 15 additions & 1 deletion dbms/src/Processors/Executors/PipelineExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,21 @@ PipelineExecutor::PipelineExecutor(Processors & processors_, QueryStatus * elem)
, expand_pipeline_task(nullptr)
, process_list_element(elem)
{
buildGraph();
try
{
buildGraph();
}
catch (Exception & exception)
{
/// If exception was thrown while pipeline initialization, it means that query pipeline was not build correctly.
/// It is logical error, and we need more information about pipeline.
WriteBufferFromOwnString buf;
printPipeline(processors, buf);
buf.finalize();
exception.addMessage("Query pipeline:\n" + buf.str());

throw;
}
}

bool PipelineExecutor::addEdges(UInt64 node)
Expand Down
3 changes: 3 additions & 0 deletions dbms/src/Processors/printPipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ void printPipeline(const Processors & processors, const Statuses & statuses, Wri
{
for (const auto & port : processor->getOutputs())
{
if (!port.isConnected())
continue;

const IProcessor & curr = *processor;
const IProcessor & next = port.getInputPort().getProcessor();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include <gtest/gtest.h>

#include <Processors/Sources/SourceFromSingleChunk.h>
#include <Processors/NullSink.h>
#include <Processors/Executors/PipelineExecutor.h>

#include <Columns/ColumnsNumber.h>
#include <DataTypes/DataTypesNumber.h>

using namespace DB;

TEST(Processors, PortsConnected)
{
auto col = ColumnUInt8::create(1, 1);
Columns columns;
columns.emplace_back(std::move(col));
Chunk chunk(std::move(columns), 1);

Block header = {ColumnWithTypeAndName(ColumnUInt8::create(), std::make_shared<DataTypeUInt8>(), "x")};

auto source = std::make_shared<SourceFromSingleChunk>(std::move(header), std::move(chunk));
auto sink = std::make_shared<NullSink>(source->getPort().getHeader());

connect(source->getPort(), sink->getPort());

Processors processors;
processors.emplace_back(std::move(source));
processors.emplace_back(std::move(sink));

PipelineExecutor executor(processors);
executor.execute(1);
}

TEST(Processors, PortsNotConnected)
{
auto col = ColumnUInt8::create(1, 1);
Columns columns;
columns.emplace_back(std::move(col));
Chunk chunk(std::move(columns), 1);

Block header = {ColumnWithTypeAndName(ColumnUInt8::create(), std::make_shared<DataTypeUInt8>(), "x")};

auto source = std::make_shared<SourceFromSingleChunk>(std::move(header), std::move(chunk));
auto sink = std::make_shared<NullSink>(source->getPort().getHeader());

/// connect(source->getPort(), sink->getPort());

Processors processors;
processors.emplace_back(std::move(source));
processors.emplace_back(std::move(sink));

auto exec = [&]()
{

try
{
PipelineExecutor executor(processors);
executor.execute(1);
}
catch (DB::Exception & e)
{
std::cout << e.displayText() << std::endl;
ASSERT_TRUE(e.displayText().find("pipeline") != std::string::npos);
throw;
}
};

ASSERT_THROW(exec(), DB::Exception);
}