MCPcopy Create free account
hub / github.com/ClickHouse/ClickHouse / executeImpl

Method executeImpl

src/Interpreters/InterpreterShowCreateQuery.cpp:49–124  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47
48
49QueryPipeline InterpreterShowCreateQuery::executeImpl()
50{
51 ASTPtr create_query;
52 ASTQueryWithTableAndOutput * show_query = nullptr;
53 if ((show_query = query_ptr->as<ASTShowCreateTableQuery>()) ||
54 (show_query = query_ptr->as<ASTShowCreateViewQuery>()) ||
55 (show_query = query_ptr->as<ASTShowCreateDictionaryQuery>()))
56 {
57 /// Only `SHOW CREATE TABLE` should resolve temporary tables for an unqualified name —
58 /// `VIEW` and `DICTIONARY` cannot refer to a temporary table, so resolving to one would
59 /// shadow a permanent view/dictionary with the same name and fail with `BAD_ARGUMENTS`.
60 Context::StorageNamespace resolve_table_type = Context::ResolveOrdinary;
61 if (show_query->isTemporary())
62 resolve_table_type = Context::ResolveExternal;
63 else if (query_ptr->as<ASTShowCreateTableQuery>())
64 resolve_table_type = Context::ResolveAll;
65 auto table_id = getContext()->resolveStorageID(*show_query, resolve_table_type);
66
67 bool is_dictionary = static_cast<bool>(query_ptr->as<ASTShowCreateDictionaryQuery>());
68
69 if (is_dictionary)
70 getContext()->checkAccess(AccessType::SHOW_DICTIONARIES, table_id);
71 else
72 getContext()->checkAccess(AccessType::SHOW_COLUMNS, table_id);
73
74 create_query = DatabaseCatalog::instance().getDatabase(table_id.database_name)->getCreateTableQuery(table_id.table_name, getContext());
75
76 auto & ast_create_query = create_query->as<ASTCreateQuery &>();
77 if (query_ptr->as<ASTShowCreateViewQuery>())
78 {
79 if (!ast_create_query.isView())
80 throw Exception(ErrorCodes::BAD_ARGUMENTS, "{}.{} is not a VIEW",
81 backQuote(ast_create_query.getDatabase()), backQuote(ast_create_query.getTable()));
82 }
83 else if (is_dictionary)
84 {
85 if (!ast_create_query.is_dictionary)
86 throw Exception(ErrorCodes::BAD_ARGUMENTS, "{}.{} is not a DICTIONARY",
87 backQuote(ast_create_query.getDatabase()), backQuote(ast_create_query.getTable()));
88 }
89 }
90 else if ((show_query = query_ptr->as<ASTShowCreateDatabaseQuery>()))
91 {
92 if (show_query->isTemporary())
93 throw Exception(ErrorCodes::SYNTAX_ERROR, "Temporary databases are not possible.");
94 show_query->setDatabase(getContext()->resolveDatabase(show_query->getDatabase()));
95 getContext()->checkAccess(AccessType::SHOW_DATABASES, show_query->getDatabase());
96 create_query = DatabaseCatalog::instance().getDatabase(show_query->getDatabase())->getCreateDatabaseQuery();
97 }
98
99 if (!create_query)
100 throw Exception(ErrorCodes::THERE_IS_NO_QUERY,
101 "Unable to show the create query of {}. Maybe it was created by the system.",
102 show_query->getTable());
103
104 if (!getContext()->getSettingsRef()[Setting::show_table_uuid_in_table_create_query_if_not_nil])
105 {
106 auto & create = create_query->as<ASTCreateQuery &>();

Callers

nothing calls this directly

Calls 15

backQuoteFunction · 0.85
resolveStorageIDMethod · 0.80
resolveDatabaseMethod · 0.80
resetInnerUUIDsMethod · 0.80
ExceptionClass · 0.70
formatFunction · 0.70
getContextFunction · 0.50
createFunction · 0.50
QueryPipelineClass · 0.50
isTemporaryMethod · 0.45
checkAccessMethod · 0.45

Tested by

no test coverage detected