forked from ClickHouse/ClickHouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add system table system.user_directories
- Loading branch information
Vitaly Baranov
committed
Aug 16, 2020
1 parent
0759dff
commit 29a6558
Showing
8 changed files
with
96 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters