#include #include #include #include #include #include #include #include #include #include #include #include #include namespace DB { namespace ErrorCodes { extern const int SYNTAX_ERROR; extern const int THERE_IS_NO_QUERY; } BlockIO InterpreterShowCreateQuery::execute() { BlockIO res; res.in = executeImpl(); return res; } Block InterpreterShowCreateQuery::getSampleBlock() { return Block{{ ColumnString::create(), std::make_shared(), "statement"}}; } BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() { ASTPtr create_query; ASTQueryWithTableAndOutput * show_query; if ((show_query = query_ptr->as())) { if (show_query->temporary) create_query = context.getCreateExternalTableQuery(show_query->table); else create_query = context.getDatabase(show_query->database)->getCreateTableQuery(context, show_query->table); } else if ((show_query = query_ptr->as())) { if (show_query->temporary) throw Exception("Temporary databases are not possible.", ErrorCodes::SYNTAX_ERROR); create_query = context.getDatabase(show_query->database)->getCreateDatabaseQuery(context); } else if ((show_query = query_ptr->as())) { if (show_query->temporary) throw Exception("Temporary dictionaries are not possible.", ErrorCodes::SYNTAX_ERROR); create_query = context.getDatabase(show_query->database)->getCreateDictionaryQuery(context, show_query->table); } if (!create_query && show_query && show_query->temporary) throw Exception("Unable to show the create query of " + show_query->table + ". Maybe it was created by the system.", ErrorCodes::THERE_IS_NO_QUERY); std::stringstream stream; formatAST(*create_query, 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"}}); } }