#include #include #include #include #include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int SYNTAX_ERROR; } BlockIO InterpreterShowCreateQuery::execute() { BlockIO res; res.in = executeImpl(); return res; } Block InterpreterShowCreateQuery::getSampleBlock() { return Block{{ ColumnString::create(), std::make_shared(), "statement"}}; } BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() { const ASTShowCreateQuery & ast = typeid_cast(*query_ptr); if (ast.temporary && !ast.database.empty()) throw Exception("Can't add database When using `TEMPORARY`", ErrorCodes::SYNTAX_ERROR); ASTPtr createQuery = (ast.temporary ? context.getCreateExternalQuery(ast.table) : context.getCreateQuery(ast.database, ast.table)); if (!createQuery && ast.temporary) throw Exception("Unable to show the create query of " + ast.table + ", It maybe created by system."); std::stringstream stream; formatAST(*createQuery, stream, false, true); String res = stream.str(); MutableColumnPtr column = ColumnString::create(); column->insert(res); return std::make_shared(Block{{ std::move(column), std::make_shared(), "statement"}}); } }