| 98 | } |
| 99 | |
| 100 | ASTPtr 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 | |
| 143 | ASTPtr DatabaseDictionary::getCreateDatabaseQueryImpl() const |
| 144 | { |
nothing calls this directly
no test coverage detected