mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-10 01:25:21 +00:00
Add system table system.user_directories
This commit is contained in:
parent
0759dff12b
commit
29a6558d33
@ -18,6 +18,8 @@ public:
|
||||
~DiskAccessStorage() override;
|
||||
|
||||
const char * getStorageType() const override { return STORAGE_TYPE; }
|
||||
String getStoragePath() const override { return directory_path; }
|
||||
bool isStorageReadOnly() const override { return readonly; }
|
||||
|
||||
private:
|
||||
std::optional<UUID> findImpl(EntityType type, const String & name) const override;
|
||||
|
@ -25,6 +25,8 @@ public:
|
||||
/// Returns the name of this storage.
|
||||
const String & getStorageName() const { return storage_name; }
|
||||
virtual const char * getStorageType() const = 0;
|
||||
virtual String getStoragePath() const { return {}; }
|
||||
virtual bool isStorageReadOnly() const { return false; }
|
||||
|
||||
using EntityType = IAccessEntity::Type;
|
||||
using EntityTypeInfo = IAccessEntity::TypeInfo;
|
||||
|
@ -482,6 +482,13 @@ UsersConfigAccessStorage::UsersConfigAccessStorage(const String & storage_name_,
|
||||
UsersConfigAccessStorage::~UsersConfigAccessStorage() = default;
|
||||
|
||||
|
||||
String UsersConfigAccessStorage::getStoragePath() const
|
||||
{
|
||||
std::lock_guard lock{load_mutex};
|
||||
return path;
|
||||
}
|
||||
|
||||
|
||||
void UsersConfigAccessStorage::setConfig(const Poco::Util::AbstractConfiguration & config)
|
||||
{
|
||||
std::lock_guard lock{load_mutex};
|
||||
|
@ -26,6 +26,8 @@ public:
|
||||
~UsersConfigAccessStorage() override;
|
||||
|
||||
const char * getStorageType() const override { return STORAGE_TYPE; }
|
||||
String getStoragePath() const override;
|
||||
bool isStorageReadOnly() const override { return true; }
|
||||
|
||||
void setConfig(const Poco::Util::AbstractConfiguration & config);
|
||||
|
||||
|
56
src/Storages/System/StorageSystemUserDirectories.cpp
Normal file
56
src/Storages/System/StorageSystemUserDirectories.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
#include <Storages/System/StorageSystemUserDirectories.h>
|
||||
#include <DataTypes/DataTypeString.h>
|
||||
#include <DataTypes/DataTypesNumber.h>
|
||||
#include <Columns/ColumnString.h>
|
||||
#include <Columns/ColumnsNumber.h>
|
||||
#include <Interpreters/Context.h>
|
||||
#include <Access/AccessControlManager.h>
|
||||
#include <ext/enumerate.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
NamesAndTypesList StorageSystemUserDirectories::getNamesAndTypes()
|
||||
{
|
||||
NamesAndTypesList names_and_types{
|
||||
{"name", std::make_shared<DataTypeString>()},
|
||||
{"type", std::make_shared<DataTypeString>()},
|
||||
{"path", std::make_shared<DataTypeString>()},
|
||||
{"readonly", std::make_shared<DataTypeUInt8>()},
|
||||
{"precedence", std::make_shared<DataTypeUInt64>()},
|
||||
};
|
||||
return names_and_types;
|
||||
}
|
||||
|
||||
|
||||
void StorageSystemUserDirectories::fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const
|
||||
{
|
||||
const auto & access_control = context.getAccessControlManager();
|
||||
auto storages = access_control.getStorages();
|
||||
|
||||
size_t column_index = 0;
|
||||
auto & column_name = assert_cast<ColumnString &>(*res_columns[column_index++]);
|
||||
auto & column_type = assert_cast<ColumnString &>(*res_columns[column_index++]);
|
||||
auto & column_path = assert_cast<ColumnString &>(*res_columns[column_index++]);
|
||||
auto & column_readonly = assert_cast<ColumnUInt8 &>(*res_columns[column_index++]);
|
||||
auto & column_precedence = assert_cast<ColumnUInt64 &>(*res_columns[column_index++]);
|
||||
|
||||
auto add_row = [&](const IAccessStorage & storage, size_t precedence)
|
||||
{
|
||||
const String & name = storage.getStorageName();
|
||||
std::string_view type = storage.getStorageType();
|
||||
const String & path = storage.getStoragePath();
|
||||
bool readonly = storage.isStorageReadOnly();
|
||||
|
||||
column_name.insertData(name.data(), name.length());
|
||||
column_type.insertData(type.data(), type.length());
|
||||
column_path.insertData(path.data(), path.length());
|
||||
column_readonly.insert(readonly);
|
||||
column_precedence.insert(precedence);
|
||||
};
|
||||
|
||||
for (auto [i, storage] : ext::enumerate(storages))
|
||||
add_row(*storage, i + 1);
|
||||
}
|
||||
|
||||
}
|
24
src/Storages/System/StorageSystemUserDirectories.h
Normal file
24
src/Storages/System/StorageSystemUserDirectories.h
Normal file
@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <ext/shared_ptr_helper.h>
|
||||
#include <Storages/System/IStorageSystemOneBlock.h>
|
||||
|
||||
|
||||
namespace DB
|
||||
{
|
||||
class Context;
|
||||
|
||||
/// Implements `users_directories` system table, which allows you to get information about user directories.
|
||||
class StorageSystemUserDirectories final : public ext::shared_ptr_helper<StorageSystemUserDirectories>, public IStorageSystemOneBlock<StorageSystemUserDirectories>
|
||||
{
|
||||
public:
|
||||
std::string getName() const override { return "SystemUserDirectories"; }
|
||||
static NamesAndTypesList getNamesAndTypes();
|
||||
|
||||
protected:
|
||||
friend struct ext::shared_ptr_helper<StorageSystemUserDirectories>;
|
||||
using IStorageSystemOneBlock::IStorageSystemOneBlock;
|
||||
void fillData(MutableColumns & res_columns, const Context & context, const SelectQueryInfo &) const override;
|
||||
};
|
||||
|
||||
}
|
@ -57,6 +57,7 @@
|
||||
#include <Storages/System/StorageSystemQuotaLimits.h>
|
||||
#include <Storages/System/StorageSystemQuotaUsage.h>
|
||||
#include <Storages/System/StorageSystemQuotasUsage.h>
|
||||
#include <Storages/System/StorageSystemUserDirectories.h>
|
||||
#include <Storages/System/StorageSystemPrivileges.h>
|
||||
|
||||
#ifdef OS_LINUX
|
||||
@ -102,6 +103,7 @@ void attachSystemTablesLocal(IDatabase & system_database)
|
||||
attach<StorageSystemQuotaLimits>(system_database, "quota_limits");
|
||||
attach<StorageSystemQuotaUsage>(system_database, "quota_usage");
|
||||
attach<StorageSystemQuotasUsage>(system_database, "quotas_usage");
|
||||
attach<StorageSystemUserDirectories>(system_database, "user_directories");
|
||||
attach<StorageSystemPrivileges>(system_database, "privileges");
|
||||
|
||||
#if !defined(ARCADIA_BUILD)
|
||||
|
@ -183,6 +183,7 @@ SRCS(
|
||||
System/StorageSystemTableFunctions.cpp
|
||||
System/StorageSystemTables.cpp
|
||||
System/StorageSystemUsers.cpp
|
||||
System/StorageSystemUserDirectories.cpp
|
||||
System/StorageSystemZeros.cpp
|
||||
System/StorageSystemZooKeeper.cpp
|
||||
transformQueryForExternalDatabase.cpp
|
||||
|
Loading…
Reference in New Issue
Block a user