ClickHouse/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp

67 lines
1.8 KiB
C++
Raw Normal View History

#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>
#include <Interpreters/InterpreterShowCreateQuery.h>
2016-12-12 07:24:56 +00:00
namespace DB
{
namespace ErrorCodes
{
2018-03-07 19:52:22 +00:00
extern const int SYNTAX_ERROR;
extern const int THERE_IS_NO_QUERY;
}
2016-12-12 07:24:56 +00:00
BlockIO InterpreterShowCreateQuery::execute()
{
BlockIO res;
res.in = executeImpl();
return res;
2016-12-12 07:24:56 +00:00
}
Block InterpreterShowCreateQuery::getSampleBlock()
{
return Block{{
ColumnString::create(),
std::make_shared<DataTypeString>(),
"statement"}};
2016-12-12 07:24:56 +00:00
}
BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl()
{
const ASTShowCreateQuery & ast = typeid_cast<const ASTShowCreateQuery &>(*query_ptr);
2016-12-12 07:24:56 +00:00
if (ast.temporary && !ast.database.empty())
2018-03-07 19:39:05 +00:00
throw Exception("Temporary databases are not possible.", ErrorCodes::SYNTAX_ERROR);
2018-03-07 19:39:05 +00:00
ASTPtr create_query = (ast.temporary ? context.getCreateExternalQuery(ast.table) :
context.getCreateQuery(ast.database, ast.table));
2018-03-07 19:39:05 +00:00
if (!create_query && ast.temporary)
2018-03-07 19:52:22 +00:00
throw Exception("Unable to show the create query of " + ast.table + ". Maybe it was created by the system.", ErrorCodes::THERE_IS_NO_QUERY);
std::stringstream stream;
2018-03-07 19:39:05 +00:00
formatAST(*create_query, stream, false, true);
String res = stream.str();
2016-12-12 07:24:56 +00:00
MutableColumnPtr column = ColumnString::create();
ColumnConst unification (#1011) * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * Fixed error in ColumnArray::replicateGeneric [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150]. * ColumnConst: unification (incomplete) [#CLICKHOUSE-3150].
2017-07-21 06:35:58 +00:00
column->insert(res);
return std::make_shared<OneBlockInputStream>(Block{{
std::move(column),
std::make_shared<DataTypeString>(),
"statement"}});
2016-12-12 07:24:56 +00:00
}
}