| 109 | } |
| 110 | |
| 111 | ASTPtr 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 | |
| 144 | ASTPtr DatabaseDictionary::getCreateDatabaseQuery() const |
| 145 | { |
nothing calls this directly
no test coverage detected