mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 07:01:59 +00:00
dbms: filtered tables in 'show tables from' query [#METR-13667]
This commit is contained in:
parent
ed6b36d33f
commit
14c231c055
@ -38,6 +38,8 @@ private:
|
||||
NamesAndTypesList columns;
|
||||
|
||||
StorageSystemTables(const std::string & name_, const Context & context_);
|
||||
|
||||
ColumnWithNameAndType getFilteredDatabases(ASTPtr query);
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -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 filtered_databases_column;
|
||||
filtered_databases_column.name = "database";
|
||||
filtered_databases_column.type = new DataTypeString;
|
||||
filtered_databases_column.column = new ColumnString;
|
||||
|
||||
Block filtered_databases_block;
|
||||
filtered_databases_block.insert(filtered_databases_column);
|
||||
for (auto database_it = context.getDatabases().begin(); database_it != context.getDatabases().end(); ++database_it)
|
||||
{
|
||||
filtered_databases_column.column->insert(database_it->first);
|
||||
}
|
||||
VirtualColumnUtils::filterBlockWithQuery(query, filtered_databases_block, context);
|
||||
|
||||
return filtered_databases_column;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,2 @@
|
||||
A
|
||||
B
|
9
dbms/tests/queries/0_stateless/00080_show_tables.sql
Normal file
9
dbms/tests/queries/0_stateless/00080_show_tables.sql
Normal 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;
|
||||
|
Loading…
Reference in New Issue
Block a user