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

Method getCreateTableQueryImpl

src/Databases/DatabaseDictionary.cpp:100–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100ASTPtr DatabaseDictionary::getCreateTableQueryImpl(const String & table_name, ContextPtr, bool throw_on_error) const
101{
102 String query;
103 {
104 WriteBufferFromString buffer(query);
105
106 auto load_result = getContext()->getExternalDictionariesLoader().getLoadResult(table_name);
107 if (!load_result.config)
108 {
109 if (throw_on_error)
110 throw Exception(ErrorCodes::CANNOT_GET_CREATE_DICTIONARY_QUERY, "Dictionary {} doesn't exist", backQuote(table_name));
111 return {};
112 }
113
114 auto names_and_types = StorageDictionary::getNamesAndTypes(ExternalDictionariesLoader::getDictionaryStructure(*load_result.config), false);
115 buffer << "CREATE TABLE " << backQuoteIfNeed(getDatabaseName()) << '.' << backQuoteIfNeed(table_name) << " (";
116 buffer << names_and_types.toNamesAndTypesDescription();
117 buffer << ") Engine = Dictionary(" << backQuoteIfNeed(table_name) << ")";
118 }
119
120 const auto & settings = getContext()->getSettingsRef();
121 ParserCreateQuery parser;
122 const char * pos = query.data();
123 std::string error_message;
124 auto ast = tryParseQuery(
125 parser,
126 pos,
127 pos + query.size(),
128 error_message,
129 /* hilite = */ false,
130 "",
131 /* allow_multi_statements = */ false,
132 0,
133 settings[Setting::max_parser_depth],
134 settings[Setting::max_parser_backtracks],
135 true);
136
137 if (!ast && throw_on_error)
138 throw Exception::createDeprecated(error_message, ErrorCodes::SYNTAX_ERROR);
139
140 return ast;
141}
142
143ASTPtr DatabaseDictionary::getCreateDatabaseQueryImpl() const
144{

Callers

nothing calls this directly

Calls 10

backQuoteFunction · 0.85
getDictionaryStructureFunction · 0.85
backQuoteIfNeedFunction · 0.85
tryParseQueryFunction · 0.85
getContextFunction · 0.50
ExceptionClass · 0.50
getLoadResultMethod · 0.45
dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected