ClickHouse/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp
2018-02-15 21:54:12 +03:00

53 lines
1.3 KiB
C++

#include <Storages/IStorage.h>
#include <Parsers/TablePropertiesQueriesASTs.h>
#include <Parsers/formatAST.h>
#include <DataStreams/OneBlockInputStream.h>
#include <DataStreams/BlockIO.h>
#include <DataStreams/copyData.h>
#include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeString.h>
#include <Columns/ColumnString.h>
#include <Common/typeid_cast.h>
#include <Interpreters/Context.h>
#include <Interpreters/InterpreterShowCreateQuery.h>
namespace DB
{
BlockIO InterpreterShowCreateQuery::execute()
{
BlockIO res;
res.in = executeImpl();
return res;
}
Block InterpreterShowCreateQuery::getSampleBlock()
{
return Block{{
ColumnString::create(),
std::make_shared<DataTypeString>(),
"statement"}};
}
BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl()
{
const ASTShowCreateQuery & ast = typeid_cast<const ASTShowCreateQuery &>(*query_ptr);
std::stringstream stream;
formatAST(*context.getCreateQuery(ast.database, ast.table), stream, false, true);
String res = stream.str();
MutableColumnPtr column = ColumnString::create();
column->insert(res);
return std::make_shared<OneBlockInputStream>(Block{{
std::move(column),
std::make_shared<DataTypeString>(),
"statement"}});
}
}