diff options
author | robot-piglet <robot-piglet@yandex-team.com> | 2023-11-25 09:58:34 +0300 |
---|---|---|
committer | robot-piglet <robot-piglet@yandex-team.com> | 2023-11-25 10:21:16 +0300 |
commit | 87b47db8278b512a71c50ed56d2ed8ee68ac7e4d (patch) | |
tree | 7bd7c6e592dd051becd4e873d49e08300fd09fe8 /contrib/clickhouse/src/Interpreters | |
parent | 6b2a05ea439e6a1248e679d60d44519c21f11396 (diff) | |
download | ydb-87b47db8278b512a71c50ed56d2ed8ee68ac7e4d.tar.gz |
Intermediate changes
Diffstat (limited to 'contrib/clickhouse/src/Interpreters')
-rw-r--r-- | contrib/clickhouse/src/Interpreters/InterpreterAlterQuery.cpp | 15 | ||||
-rw-r--r-- | contrib/clickhouse/src/Interpreters/InterpreterCreateQuery.cpp | 7 |
2 files changed, 17 insertions, 5 deletions
diff --git a/contrib/clickhouse/src/Interpreters/InterpreterAlterQuery.cpp b/contrib/clickhouse/src/Interpreters/InterpreterAlterQuery.cpp index 7d1f994823..669ad4e985 100644 --- a/contrib/clickhouse/src/Interpreters/InterpreterAlterQuery.cpp +++ b/contrib/clickhouse/src/Interpreters/InterpreterAlterQuery.cpp @@ -42,6 +42,7 @@ namespace ErrorCodes extern const int TABLE_IS_READ_ONLY; extern const int BAD_ARGUMENTS; extern const int UNKNOWN_TABLE; + extern const int UNKNOWN_DATABASE; } @@ -74,9 +75,14 @@ BlockIO InterpreterAlterQuery::executeToTable(const ASTAlterQuery & alter) if (!UserDefinedSQLFunctionFactory::instance().empty()) UserDefinedSQLFunctionVisitor::visit(query_ptr); - auto table_id = getContext()->resolveStorageID(alter, Context::ResolveOrdinary); - query_ptr->as<ASTAlterQuery &>().setDatabase(table_id.database_name); - StoragePtr table = DatabaseCatalog::instance().tryGetTable(table_id, getContext()); + auto table_id = getContext()->tryResolveStorageID(alter, Context::ResolveOrdinary); + StoragePtr table; + + if (table_id) + { + query_ptr->as<ASTAlterQuery &>().setDatabase(table_id.database_name); + table = DatabaseCatalog::instance().tryGetTable(table_id, getContext()); + } if (!alter.cluster.empty() && !maybeRemoveOnCluster(query_ptr, getContext())) { @@ -90,6 +96,9 @@ BlockIO InterpreterAlterQuery::executeToTable(const ASTAlterQuery & alter) getContext()->checkAccess(getRequiredAccess()); + if (!table_id) + throw Exception(ErrorCodes::UNKNOWN_DATABASE, "Database {} does not exist", backQuoteIfNeed(alter.getDatabase())); + DatabasePtr database = DatabaseCatalog::instance().getDatabase(table_id.database_name); if (database->shouldReplicateQuery(getContext(), query_ptr)) { diff --git a/contrib/clickhouse/src/Interpreters/InterpreterCreateQuery.cpp b/contrib/clickhouse/src/Interpreters/InterpreterCreateQuery.cpp index 92d74f4f18..06cee002ba 100644 --- a/contrib/clickhouse/src/Interpreters/InterpreterCreateQuery.cpp +++ b/contrib/clickhouse/src/Interpreters/InterpreterCreateQuery.cpp @@ -1215,9 +1215,9 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) DatabasePtr database; bool need_add_to_database = !create.temporary; if (need_add_to_database) - database = DatabaseCatalog::instance().getDatabase(database_name); + database = DatabaseCatalog::instance().tryGetDatabase(database_name); - if (need_add_to_database && database->shouldReplicateQuery(getContext(), query_ptr)) + if (need_add_to_database && database && database->shouldReplicateQuery(getContext(), query_ptr)) { chassert(!ddl_guard); auto guard = DatabaseCatalog::instance().getDDLGuard(create.getDatabase(), create.getTable()); @@ -1232,6 +1232,9 @@ BlockIO InterpreterCreateQuery::createTable(ASTCreateQuery & create) return executeQueryOnCluster(create); } + if (need_add_to_database && !database) + throw Exception(ErrorCodes::UNKNOWN_DATABASE, "Database {} does not exist", backQuoteIfNeed(database_name)); + if (create.replace_table) { chassert(!ddl_guard); |