2022-11-10 16:05:04 +00:00
|
|
|
#include "StorageSystemNamedCollections.h"
|
2022-11-10 16:07:17 +00:00
|
|
|
|
|
|
|
#include <Common/FieldVisitorToString.h>
|
2022-11-10 16:05:04 +00:00
|
|
|
#include <DataTypes/DataTypeString.h>
|
2022-11-10 16:07:17 +00:00
|
|
|
#include <DataTypes/DataTypeMap.h>
|
2022-11-10 16:05:04 +00:00
|
|
|
#include <Interpreters/Context.h>
|
2022-11-10 16:07:17 +00:00
|
|
|
#include <Interpreters/ProfileEventsExt.h>
|
2022-11-10 16:05:04 +00:00
|
|
|
#include <Access/Common/AccessType.h>
|
|
|
|
#include <Access/Common/AccessFlags.h>
|
2022-11-10 16:07:17 +00:00
|
|
|
#include <Columns/ColumnMap.h>
|
2022-11-10 16:05:04 +00:00
|
|
|
#include <Storages/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>())},
|
2022-11-10 16:05:04 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
StorageSystemNamedCollections::StorageSystemNamedCollections(const StorageID & table_id_)
|
|
|
|
: IStorageSystemOneBlock(table_id_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void StorageSystemNamedCollections::fillData(MutableColumns & res_columns, ContextPtr context, const SelectQueryInfo &) const
|
|
|
|
{
|
|
|
|
context->checkAccess(AccessType::SHOW_NAMED_COLLECTIONS);
|
|
|
|
|
|
|
|
auto collections = NamedCollectionFactory::instance().getAll();
|
|
|
|
|
|
|
|
for (const auto & [name, collection] : collections)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
for (const auto & [key, value] : collection->dumpStructure())
|
|
|
|
{
|
|
|
|
key_column.insertData(key.data(), key.size());
|
|
|
|
value_column.insert(convertFieldToString(value));
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
|
|
|
|
offsets.push_back(offsets.back() + size);
|
2022-11-10 16:05:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|