mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-21 23:21:59 +00:00
review system.views
This commit is contained in:
parent
52570b1c80
commit
64efa917d8
@ -608,11 +608,10 @@ Dependencies DatabaseCatalog::getDependencies(const StorageID & from) const
|
||||
return {};
|
||||
return Dependencies(iter->second.begin(), iter->second.end());
|
||||
}
|
||||
|
||||
void DatabaseCatalog::getViewDependencies(ViewDependencies & view_dependencies_) const
|
||||
|
||||
ViewDependencies DatabaseCatalog::getViewDependencies() const;
|
||||
{
|
||||
std::lock_guard lock{databases_mutex};
|
||||
view_dependencies_ = view_dependencies;
|
||||
return view_dependencies;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -174,7 +174,7 @@ public:
|
||||
void addDependency(const StorageID & from, const StorageID & where);
|
||||
void removeDependency(const StorageID & from, const StorageID & where);
|
||||
Dependencies getDependencies(const StorageID & from) const;
|
||||
void getViewDependencies(ViewDependencies & view_dependencies_) const;
|
||||
ViewDependencies getViewDependencies() const;
|
||||
|
||||
/// For Materialized and Live View
|
||||
void updateDependency(const StorageID & old_from, const StorageID & old_where,const StorageID & new_from, const StorageID & new_where);
|
||||
|
@ -1,47 +0,0 @@
|
||||
#include <Storages/System/StorageSystemTableViews.h>
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
#include <Access/ContextAccess.h>
|
||||
#include <Interpreters/Context.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class Context;
|
||||
|
||||
NamesAndTypesList StorageSystemTableViews::getNamesAndTypes()
|
||||
{
|
||||
return {
|
||||
{"database", std::make_shared<DataTypeString>()},
|
||||
{"table", std::make_shared<DataTypeString>()},
|
||||
{"view_database", std::make_shared<DataTypeString>()},
|
||||
{"view_table", std::make_shared<DataTypeString>()},
|
||||
};
|
||||
}
|
||||
|
||||
void StorageSystemTableViews::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo & ) const
|
||||
{
|
||||
const auto access = context.getAccess();
|
||||
const bool check_access_for_databases = !access->isGranted(AccessType::SHOW_TABLES);
|
||||
|
||||
ViewDependencies view_dependencies;
|
||||
DatabaseCatalog::instance().getViewDependencies(view_dependencies);
|
||||
|
||||
for (const auto & [storage_id, view_ids] : view_dependencies)
|
||||
{
|
||||
const bool check_access_for_tables = check_access_for_databases && !access->isGranted(AccessType::SHOW_TABLES, storage_id.database_name);
|
||||
|
||||
if (check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, storage_id.database_name, storage_id.table_name))
|
||||
continue;
|
||||
|
||||
for (const auto & view_id : view_ids)
|
||||
{
|
||||
size_t col_num = 0;
|
||||
res_columns[col_num++]->insert(storage_id.database_name);
|
||||
res_columns[col_num++]->insert(storage_id.table_name);
|
||||
res_columns[col_num++]->insert(view_id.database_name);
|
||||
res_columns[col_num++]->insert(view_id.table_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
45
src/Storages/System/StorageSystemViews.cpp
Normal file
45
src/Storages/System/StorageSystemViews.cpp
Normal file
@ -0,0 +1,45 @@
|
||||
#include <Storages/System/StorageSystemViews.h>
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
#include <Access/ContextAccess.h>
|
||||
#include <Interpreters/Context.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class Context;
|
||||
|
||||
NamesAndTypesList StorageSystemViews::getNamesAndTypes()
|
||||
{
|
||||
return {
|
||||
{"database", std::make_shared<DataTypeString>()},
|
||||
{"name", std::make_shared<DataTypeString>()},
|
||||
{"table", std::make_shared<DataTypeString>()},
|
||||
{"table_database", std::make_shared<DataTypeString>()},
|
||||
};
|
||||
}
|
||||
|
||||
void StorageSystemViews::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const
|
||||
{
|
||||
const auto access = context.getAccess();
|
||||
const bool check_access_for_databases = !access->isGranted(AccessType::SHOW_TABLES);
|
||||
|
||||
for (const auto & [table_id, view_ids] : DatabaseCatalog::instance().getViewDependencies())
|
||||
{
|
||||
const bool check_access_for_tables = check_access_for_databases && !access->isGranted(AccessType::SHOW_TABLES, table_id.database_name);
|
||||
|
||||
if (check_access_for_tables && !access->isGranted(AccessType::SHOW_TABLES, table_id.database_name, table_id.table_name))
|
||||
continue;
|
||||
|
||||
size_t col_num;
|
||||
for (const auto & view_id : view_ids)
|
||||
{
|
||||
col_num = 0;
|
||||
res_columns[col_num++]->insert(table_id.database_name);
|
||||
res_columns[col_num++]->insert(table_id.table_name);
|
||||
res_columns[col_num++]->insert(view_id.database_name);
|
||||
res_columns[col_num++]->insert(view_id.table_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -6,16 +6,16 @@
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class StorageSystemTableViews final : public ext::shared_ptr_helper<StorageSystemTableViews>, public IStorageSystemOneBlock<StorageSystemTableViews>
|
||||
class StorageSystemViews final : public ext::shared_ptr_helper<StorageSystemViews>, public IStorageSystemOneBlock<StorageSystemViews>
|
||||
{
|
||||
friend struct ext::shared_ptr_helper<StorageSystemTableViews>;
|
||||
friend struct ext::shared_ptr_helper<StorageSystemViews>;
|
||||
protected:
|
||||
using IStorageSystemOneBlock::IStorageSystemOneBlock;
|
||||
|
||||
void fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo & query_info) const override;
|
||||
|
||||
public:
|
||||
std::string getName() const override { return "TableViews"; }
|
||||
std::string getName() const override { return "SystemViews"; }
|
||||
|
||||
static NamesAndTypesList getNamesAndTypes();
|
||||
|
@ -44,7 +44,7 @@
|
||||
#include <Storages/System/StorageSystemTableEngines.h>
|
||||
#include <Storages/System/StorageSystemTableFunctions.h>
|
||||
#include <Storages/System/StorageSystemTables.h>
|
||||
#include <Storages/System/StorageSystemTableViews.h>
|
||||
#include <Storages/System/StorageSystemViews.h>
|
||||
#include <Storages/System/StorageSystemZooKeeper.h>
|
||||
#include <Storages/System/StorageSystemContributors.h>
|
||||
#include <Storages/System/StorageSystemErrors.h>
|
||||
@ -96,7 +96,7 @@ void attachSystemTablesLocal(IDatabase & system_database)
|
||||
attach<StorageSystemZeros>(system_database, "zeros_mt", true);
|
||||
attach<StorageSystemDatabases>(system_database, "databases");
|
||||
attach<StorageSystemTables>(system_database, "tables");
|
||||
attach<StorageSystemTableViews>(system_database, "table_views");
|
||||
attach<StorageSystemViews>(system_database, "views");
|
||||
attach<StorageSystemColumns>(system_database, "columns");
|
||||
attach<StorageSystemFunctions>(system_database, "functions");
|
||||
attach<StorageSystemEvents>(system_database, "events");
|
||||
|
Loading…
Reference in New Issue
Block a user