ClickHouse/src/Storages/System/StorageSystemNamedCollections.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

68 lines
2.1 KiB
C++
Raw Normal View History

#include "StorageSystemNamedCollections.h"
2022-11-10 16:07:17 +00:00
#include <Common/FieldVisitorToString.h>
#include <DataTypes/DataTypeString.h>
2022-11-10 16:07:17 +00:00
#include <DataTypes/DataTypeMap.h>
#include <Interpreters/Context.h>
2022-11-10 16:07:17 +00:00
#include <Interpreters/ProfileEventsExt.h>
#include <Access/Common/AccessType.h>
#include <Access/Common/AccessFlags.h>
#include <Access/ContextAccess.h>
2022-11-10 16:07:17 +00:00
#include <Columns/ColumnMap.h>
#include <Common/NamedCollections/NamedCollections.h>
namespace DB
{
NamesAndTypesList StorageSystemNamedCollections::getNamesAndTypes()
{
return {
{"name", std::make_shared<DataTypeString>()},
2022-11-10 16:07:17 +00:00
{"collection", std::make_shared<DataTypeMap>(std::make_shared<DataTypeString>(), std::make_shared<DataTypeString>())},
};
}
StorageSystemNamedCollections::StorageSystemNamedCollections(const StorageID & table_id_)
: IStorageSystemOneBlock(table_id_)
{
}
void StorageSystemNamedCollections::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
{
const auto & access = context->getAccess();
2023-02-20 14:29:09 +00:00
NamedCollectionUtils::loadIfNot();
auto collections = NamedCollectionFactory::instance().getAll();
for (const auto & [name, collection] : collections)
{
if (!access->isGranted(AccessType::SHOW_NAMED_COLLECTIONS, name))
continue;
res_columns[0]->insert(name);
2022-11-10 16:07:17 +00:00
auto * column_map = typeid_cast<ColumnMap *>(res_columns[1].get());
auto & offsets = column_map->getNestedColumn().getOffsets();
auto & tuple_column = column_map->getNestedData();
auto & key_column = tuple_column.getColumn(0);
auto & value_column = tuple_column.getColumn(1);
size_t size = 0;
2022-11-10 18:58:07 +00:00
for (const auto & key : collection->getKeys())
2022-11-10 16:07:17 +00:00
{
key_column.insertData(key.data(), key.size());
if (access->isGranted(AccessType::SHOW_NAMED_COLLECTIONS_SECRETS))
value_column.insert(collection->get<String>(key));
else
value_column.insert("[HIDDEN]");
2022-11-10 16:07:17 +00:00
size++;
}
offsets.push_back(offsets.back() + size);
}
}
}