dbms: fixed error with views [#METR-14449].

This commit is contained in:
Alexey Milovidov 2014-12-23 23:32:00 +03:00
parent 9d87dbc703
commit 10553e7840
4 changed files with 15 additions and 15 deletions

View File

@ -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<BlockOutputStreamPtr> children;

View File

@ -48,8 +48,8 @@ typedef std::map<String, Tables> Databases;
/// (имя базы данных, имя таблицы)
typedef std::pair<String, String> DatabaseAndTableName;
/// таблица -> множество таблиц-вьюшек, которые селектят из нее
typedef std::map<DatabaseAndTableName, std::set<DatabaseAndTableName> > ViewDependencies;
/// Таблица -> множество таблиц-представлений, которые деляют SELECT из неё.
typedef std::map<DatabaseAndTableName, std::set<DatabaseAndTableName>> ViewDependencies;
typedef std::vector<DatabaseAndTableName> 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;

View File

@ -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<Poco::Mutex> 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<DatabaseAndTableName> &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

View File

@ -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"