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

Method getCreateTableQueryImpl

src/Databases/DatabaseDictionary.cpp:111–142  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 7

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

Tested by

no test coverage detected