From 10553e78402fc43b56921ad33b76a87b73ac0815 Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Tue, 23 Dec 2014 23:32:00 +0300 Subject: [PATCH] dbms: fixed error with views [#METR-14449]. --- .../DataStreams/PushingToViewsBlockOutputStream.h | 8 +++----- dbms/include/DB/Interpreters/Context.h | 6 +++--- dbms/src/Interpreters/Context.cpp | 14 ++++++++------ dbms/tests/clickhouse-test | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dbms/include/DB/DataStreams/PushingToViewsBlockOutputStream.h b/dbms/include/DB/DataStreams/PushingToViewsBlockOutputStream.h index 071aa0bd77a..a442f477aa2 100644 --- a/dbms/include/DB/DataStreams/PushingToViewsBlockOutputStream.h +++ b/dbms/include/DB/DataStreams/PushingToViewsBlockOutputStream.h @@ -18,13 +18,13 @@ namespace DB class PushingToViewsBlockOutputStream : public IBlockOutputStream { public: - PushingToViewsBlockOutputStream(String database_, String table_, const Context & context_, ASTPtr query_ptr_) - : database(database_), table(table_), context(context_), query_ptr(query_ptr_) + PushingToViewsBlockOutputStream(String database, String table, const Context & context_, ASTPtr query_ptr_) + : context(context_), query_ptr(query_ptr_) { storage = context.getTable(database, table); addTableLock(storage->lockStructure(true)); - Dependencies dependencies = context.getDependencies(DatabaseAndTableName(database, table)); + Dependencies dependencies = context.getDependencies(database, table); for (size_t i = 0; i < dependencies.size(); ++i) { children.push_back(new PushingToViewsBlockOutputStream(dependencies[i].first, dependencies[i].second, context, ASTPtr())); @@ -64,8 +64,6 @@ public: private: StoragePtr storage; BlockOutputStreamPtr output; - String database; - String table; Context context; ASTPtr query_ptr; std::vector children; diff --git a/dbms/include/DB/Interpreters/Context.h b/dbms/include/DB/Interpreters/Context.h index 9cd96ae0526..28816603d0d 100644 --- a/dbms/include/DB/Interpreters/Context.h +++ b/dbms/include/DB/Interpreters/Context.h @@ -48,8 +48,8 @@ typedef std::map Databases; /// (имя базы данных, имя таблицы) typedef std::pair DatabaseAndTableName; -/// таблица -> множество таблиц-вьюшек, которые селектят из нее -typedef std::map > ViewDependencies; +/// Таблица -> множество таблиц-представлений, которые деляют SELECT из неё. +typedef std::map> ViewDependencies; typedef std::vector Dependencies; /** Набор известных объектов, которые могут быть использованы в запросе. @@ -206,7 +206,7 @@ public: void addDependency(const DatabaseAndTableName & from, const DatabaseAndTableName & where); void removeDependency(const DatabaseAndTableName & from, const DatabaseAndTableName & where); - Dependencies getDependencies(const DatabaseAndTableName & from) const; + Dependencies getDependencies(const String & database_name, const String & table_name) const; /// Проверка существования таблицы/БД. database может быть пустой - в этом случае используется текущая БД. bool isTableExist(const String & database_name, const String & table_name) const; diff --git a/dbms/src/Interpreters/Context.cpp b/dbms/src/Interpreters/Context.cpp index a18906ca356..c258049028d 100644 --- a/dbms/src/Interpreters/Context.cpp +++ b/dbms/src/Interpreters/Context.cpp @@ -81,15 +81,17 @@ void Context::removeDependency(const DatabaseAndTableName & from, const Database shared->view_dependencies[from].erase(where); } -Dependencies Context::getDependencies(const DatabaseAndTableName & from) const +Dependencies Context::getDependencies(const String & database_name, const String & table_name) const { Poco::ScopedLock lock(shared->mutex); - ViewDependencies::const_iterator iter = shared->view_dependencies.find(from); + + String db = database_name.empty() ? current_database : database_name; + + ViewDependencies::const_iterator iter = shared->view_dependencies.find(DatabaseAndTableName(db, table_name)); if (iter == shared->view_dependencies.end()) - return Dependencies(); - const std::set &buf = iter->second; - Dependencies res(buf.begin(), buf.end()); - return res; + return {}; + + return Dependencies(iter->second.begin(), iter->second.end()); } bool Context::isTableExist(const String & database_name, const String & table_name) const diff --git a/dbms/tests/clickhouse-test b/dbms/tests/clickhouse-test index 92375f645c4..e583a16c3e0 100755 --- a/dbms/tests/clickhouse-test +++ b/dbms/tests/clickhouse-test @@ -76,7 +76,7 @@ do continue fi - printf "%-60s" "$test_name: " + printf "%-64s" "$test_name: " if [ $ZOOKEEPER -eq 0 ] && (echo "$test_name" | grep -q 'zookeeper'); then echo -e "$MSG_SKIPPED - no zookeeper"