2017-04-01 09:19:00 +00:00
|
|
|
#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>
|
2017-07-13 20:58:19 +00:00
|
|
|
#include <Common/typeid_cast.h>
|
2017-05-23 18:24:43 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/InterpreterShowCreateQuery.h>
|
2016-12-12 07:24:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
BlockIO InterpreterShowCreateQuery::execute()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockIO res;
|
|
|
|
res.in = executeImpl();
|
|
|
|
res.in_sample = getSampleBlock();
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Block InterpreterShowCreateQuery::getSampleBlock()
|
|
|
|
{
|
2017-07-21 06:35:58 +00:00
|
|
|
return {{ nullptr, std::make_shared<DataTypeString>(), "statement" }};
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
const ASTShowCreateQuery & ast = typeid_cast<const ASTShowCreateQuery &>(*query_ptr);
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
std::stringstream stream;
|
|
|
|
formatAST(*context.getCreateQuery(ast.database, ast.table), stream, 0, false, true);
|
|
|
|
String res = stream.str();
|
2016-12-12 07:24:56 +00:00
|
|
|
|
2017-07-21 06:35:58 +00:00
|
|
|
ColumnPtr column = std::make_shared<ColumnString>();
|
|
|
|
column->insert(res);
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return std::make_shared<OneBlockInputStream>(Block{{
|
2017-07-21 06:35:58 +00:00
|
|
|
column,
|
2017-04-01 07:20:54 +00:00
|
|
|
std::make_shared<DataTypeString>(),
|
|
|
|
"statement"}});
|
2016-12-12 07:24:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|