ISSUES-2850 add dependencies for system tables

This commit is contained in:
zhang2014 2018-08-10 18:15:59 +08:00
parent 1e3c637741
commit dd10e85e90
3 changed files with 31 additions and 0 deletions

View File

@ -12,6 +12,7 @@
#include <Common/typeid_cast.h> #include <Common/typeid_cast.h>
#include <Common/StringUtils/StringUtils.h> #include <Common/StringUtils/StringUtils.h>
#include <DataTypes/DataTypesNumber.h> #include <DataTypes/DataTypesNumber.h>
#include <DataTypes/DataTypeArray.h>
namespace DB namespace DB
@ -35,6 +36,7 @@ StorageSystemTables::StorageSystemTables(const std::string & name_)
{"data_path", std::make_shared<DataTypeString>()}, {"data_path", std::make_shared<DataTypeString>()},
{"metadata_path", std::make_shared<DataTypeString>()}, {"metadata_path", std::make_shared<DataTypeString>()},
{"metadata_modification_time", std::make_shared<DataTypeDateTime>()}, {"metadata_modification_time", std::make_shared<DataTypeDateTime>()},
{"dependencies", std::make_shared<DataTypeArray>(std::make_shared<DataTypeString>())},
{"create_table_query", std::make_shared<DataTypeString>()}, {"create_table_query", std::make_shared<DataTypeString>()},
{"engine_full", std::make_shared<DataTypeString>()} {"engine_full", std::make_shared<DataTypeString>()}
})); }));
@ -126,6 +128,18 @@ BlockInputStreams StorageSystemTables::read(
if (columns_mask[src_index++]) if (columns_mask[src_index++])
res_columns[res_index++]->insert(static_cast<UInt64>(database->getTableMetadataModificationTime(context, table_name))); res_columns[res_index++]->insert(static_cast<UInt64>(database->getTableMetadataModificationTime(context, table_name)));
if (columns_mask[src_index++])
{
Array dependencies_name_array;
const auto dependencies = context.getDependencies(database_name, table_name);
dependencies_name_array.reserve(dependencies.size());
for (const auto & dependency : dependencies)
dependencies_name_array.push_back(dependency.first + "." + dependency.second);
res_columns[res_index++]->insert(dependencies_name_array);
}
if (columns_mask[src_index] || columns_mask[src_index + 1]) if (columns_mask[src_index] || columns_mask[src_index + 1])
{ {
ASTPtr ast = database->tryGetCreateTableQuery(context, table_name); ASTPtr ast = database->tryGetCreateTableQuery(context, table_name);
@ -188,6 +202,18 @@ BlockInputStreams StorageSystemTables::read(
if (columns_mask[src_index++]) if (columns_mask[src_index++])
res_columns[res_index++]->insertDefault(); res_columns[res_index++]->insertDefault();
if (columns_mask[src_index++])
{
Array dependencies_name_array;
const auto dependencies = context.getDependencies("", table.first);
dependencies_name_array.reserve(dependencies.size());
for (const auto & dependency : dependencies)
dependencies_name_array.push_back(dependency.second);
res_columns[res_index++]->insert(dependencies_name_array);
}
if (columns_mask[src_index++]) if (columns_mask[src_index++])
res_columns[res_index++]->insertDefault(); res_columns[res_index++]->insertDefault();

View File

@ -3,4 +3,5 @@ B
A 1 TinyLog CREATE TABLE test_show_tables.A ( A UInt8) ENGINE = TinyLog A 1 TinyLog CREATE TABLE test_show_tables.A ( A UInt8) ENGINE = TinyLog
B 1 TinyLog CREATE TABLE test_show_tables.B ( A UInt8) ENGINE = TinyLog B 1 TinyLog CREATE TABLE test_show_tables.B ( A UInt8) ENGINE = TinyLog
test_temporary_table test_temporary_table
['test_show_tables.test_materialized']
0 0

View File

@ -12,6 +12,10 @@ SELECT name, toUInt32(metadata_modification_time) > 0, engine_full, create_table
CREATE TEMPORARY TABLE test_temporary_table (id UInt64); CREATE TEMPORARY TABLE test_temporary_table (id UInt64);
SELECT name FROM system.tables WHERE is_temporary = 1 AND name = 'test_temporary_table'; SELECT name FROM system.tables WHERE is_temporary = 1 AND name = 'test_temporary_table';
CREATE TABLE test_show_tables.test_log(id UInt64)ENGINE = Log;
CREATE MATERIALIZED VIEW test_show_tables.test_materialized ENGINE = Log AS SELECT * FROM test_show_tables.test_log;
SELECT dependencies FROM system.tables WHERE name = 'test_log';
DROP DATABASE test_show_tables; DROP DATABASE test_show_tables;