This commit is contained in:
Evgeniy Gatov 2014-11-13 19:49:37 +03:00
commit 4e7946f2ef
4 changed files with 42 additions and 3 deletions

View File

@ -38,6 +38,8 @@ private:
NamesAndTypesList columns;
StorageSystemTables(const std::string & name_, const Context & context_);
ColumnWithNameAndType getFilteredDatabases(ASTPtr query);
};
}

View File

@ -2,6 +2,7 @@
#include <DB/DataTypes/DataTypeString.h>
#include <DB/DataStreams/OneBlockInputStream.h>
#include <DB/Storages/StorageSystemTables.h>
#include <DB/Common/VirtualColumnUtils.h>
namespace DB
@ -51,11 +52,19 @@ BlockInputStreams StorageSystemTables::read(
Poco::ScopedLock<Poco::Mutex> lock(context.getMutex());
for (Databases::const_iterator it = context.getDatabases().begin(); it != context.getDatabases().end(); ++it)
ColumnWithNameAndType filtered_databases_column = getFilteredDatabases(query);
for (size_t row_number = 0; row_number < filtered_databases_column.column->size(); ++row_number)
{
for (Tables::const_iterator jt = it->second.begin(); jt != it->second.end(); ++jt)
std::string database_name = filtered_databases_column.column->getDataAt(row_number).toString();
auto database_it = context.getDatabases().find(database_name);
if (database_it == context.getDatabases().end())
throw DB::Exception(std::string("Fail to find database " + database_name), DB::ErrorCodes::LOGICAL_ERROR);
for (Tables::const_iterator jt = database_it->second.begin(); jt != database_it->second.end(); ++jt)
{
col_db.column->insert(it->first);
col_db.column->insert(database_name);
col_name.column->insert(jt->first);
col_engine.column->insert(jt->second->getName());
}
@ -64,5 +73,22 @@ BlockInputStreams StorageSystemTables::read(
return BlockInputStreams(1, new OneBlockInputStream(block));
}
ColumnWithNameAndType StorageSystemTables::getFilteredDatabases(ASTPtr query)
{
ColumnWithNameAndType column;
column.name = "database";
column.type = new DataTypeString;
column.column = new ColumnString;
Block block;
block.insert(column);
for (auto database_it = context.getDatabases().begin(); database_it != context.getDatabases().end(); ++database_it)
{
column.column->insert(database_it->first);
}
VirtualColumnUtils::filterBlockWithQuery(query, block, context);
return block.getByPosition(0);
}
}

View File

@ -0,0 +1,2 @@
A
B

View File

@ -0,0 +1,9 @@
DROP DATABASE IF EXISTS test_show_tables;
CREATE DATABASE test_show_tables;
CREATE TABLE test_show_tables.A (A UInt8) ENGINE = TinyLog;
CREATE TABLE test_show_tables.B (A UInt8) ENGINE = TinyLog;
SHOW TABLES from test_show_tables;