From 29a993a66f8b04d90ce8e5a427fb3aa5c5a71ee0 Mon Sep 17 00:00:00 2001 From: Alexander Tokmakov Date: Fri, 21 Feb 2020 18:22:28 +0300 Subject: [PATCH] remove another method from Context --- dbms/src/Interpreters/Context.cpp | 13 ------------- dbms/src/Interpreters/Context.h | 8 +++----- .../Interpreters/InterpreterShowCreateQuery.cpp | 16 ++++++++-------- dbms/src/Storages/StorageMerge.cpp | 4 ++-- 4 files changed, 13 insertions(+), 28 deletions(-) diff --git a/dbms/src/Interpreters/Context.cpp b/dbms/src/Interpreters/Context.cpp index 8b06eed08f0..9343e41e490 100644 --- a/dbms/src/Interpreters/Context.cpp +++ b/dbms/src/Interpreters/Context.cpp @@ -844,19 +844,6 @@ StoragePtr Context::getViewSource() return view_source; } -ASTPtr Context::getCreateExternalTableQuery(const String & table_name) const -{ - StorageID external_id = StorageID::createEmpty(); - { - auto lock = getLock(); - auto it = external_tables_mapping.find(table_name); - if (external_tables_mapping.end() == it) - throw Exception("Temporary table " + backQuoteIfNeed(table_name) + " doesn't exist", ErrorCodes::UNKNOWN_TABLE); - external_id = it->second->getGlobalTableID(); - } - return DatabaseCatalog::instance().getDatabaseForTemporaryTables()->getCreateTableQuery(*this, external_id.table_name); -} - Settings Context::getSettings() const { return settings; diff --git a/dbms/src/Interpreters/Context.h b/dbms/src/Interpreters/Context.h index d643dee9e2c..abc0f97ad50 100644 --- a/dbms/src/Interpreters/Context.h +++ b/dbms/src/Interpreters/Context.h @@ -175,8 +175,11 @@ private: using TemporaryTablesMapping = std::map>; TemporaryTablesMapping external_tables_mapping; Scalars scalars; + + //TODO maybe replace with temporary tables? StoragePtr view_source; /// Temporary StorageValues used to generate alias columns for materialized views Tables table_function_results; /// Temporary tables obtained by execution of table functions. Keyed by AST tree id. + Context * query_context = nullptr; Context * session_context = nullptr; /// Session context or nullptr. Could be equal to this. Context * global_context = nullptr; /// Global context. Could be equal to this. @@ -385,9 +388,6 @@ public: std::optional getTCPPortSecure() const; - /// Get query for the CREATE table. - ASTPtr getCreateExternalTableQuery(const String & table_name) const; - std::shared_ptr acquireSession(const String & session_id, std::chrono::steady_clock::duration timeout, bool session_check) const; void releaseSession(const String & session_id, std::chrono::steady_clock::duration timeout); @@ -595,8 +595,6 @@ private: EmbeddedDictionaries & getEmbeddedDictionariesImpl(bool throw_on_error) const; - StoragePtr getTableImpl(const StorageID & table_id, std::optional * exception) const; - SessionKey getSessionKey(const String & session_id) const; /// Session will be closed after specified timeout. diff --git a/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp b/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp index 4f59b6665d5..758fef1dba5 100644 --- a/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp +++ b/dbms/src/Interpreters/InterpreterShowCreateQuery.cpp @@ -47,18 +47,17 @@ BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() ASTQueryWithTableAndOutput * show_query; if ((show_query = query_ptr->as())) { - if (show_query->temporary) - create_query = context.getCreateExternalTableQuery(show_query->table); - else - { - context.checkAccess(AccessType::SHOW, show_query->database, show_query->table); - create_query = DatabaseCatalog::instance().getDatabase(show_query->database, context)->getCreateTableQuery(context, show_query->table); - } + StorageID table_id{show_query->database, show_query->table}; + auto resolve_table_type = show_query->temporary ? Context::ResolveExternal : Context::ResolveOrdinary; + table_id = context.resolveStorageID(table_id, resolve_table_type); + context.checkAccess(AccessType::SHOW, table_id.database_name, table_id.table_name); + create_query = DatabaseCatalog::instance().getDatabase(table_id.database_name)->getCreateTableQuery(context, table_id.table_name); } else if ((show_query = query_ptr->as())) { if (show_query->temporary) throw Exception("Temporary databases are not possible.", ErrorCodes::SYNTAX_ERROR); + show_query->database = context.resolveDatabase(show_query->database); context.checkAccess(AccessType::SHOW, show_query->database); create_query = DatabaseCatalog::instance().getDatabase(show_query->database)->getCreateDatabaseQuery(context); } @@ -66,8 +65,9 @@ BlockInputStreamPtr InterpreterShowCreateQuery::executeImpl() { if (show_query->temporary) throw Exception("Temporary dictionaries are not possible.", ErrorCodes::SYNTAX_ERROR); + show_query->database = context.resolveDatabase(show_query->database); context.checkAccess(AccessType::SHOW, show_query->database, show_query->table); - create_query = DatabaseCatalog::instance().getDatabase(show_query->database, context)->getCreateDictionaryQuery(context, show_query->table); + create_query = DatabaseCatalog::instance().getDatabase(show_query->database)->getCreateDictionaryQuery(context, show_query->table); } if (!create_query && show_query && show_query->temporary) diff --git a/dbms/src/Storages/StorageMerge.cpp b/dbms/src/Storages/StorageMerge.cpp index 15c90106824..dd2c06c6b8f 100644 --- a/dbms/src/Storages/StorageMerge.cpp +++ b/dbms/src/Storages/StorageMerge.cpp @@ -396,10 +396,10 @@ StorageMerge::StorageListWithLocks StorageMerge::getSelectedTables(const ASTPtr } -DatabaseTablesIteratorPtr StorageMerge::getDatabaseIterator(const Context & context) const +DatabaseTablesIteratorPtr StorageMerge::getDatabaseIterator() const { checkStackSize(); - auto database = DatabaseCatalog::instance().getDatabase(source_database, context); + auto database = DatabaseCatalog::instance().getDatabase(source_database); auto table_name_match = [this](const String & table_name_) { return table_name_regexp.match(table_name_); }; return database->getTablesIterator(global_context, table_name_match); }