2017-04-25 09:10:27 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-04-24 11:02:25 +00:00
|
|
|
#include <atomic>
|
2017-04-25 09:10:27 +00:00
|
|
|
|
2021-04-24 11:02:25 +00:00
|
|
|
#include <Storages/IStorage.h>
|
2021-04-21 13:45:13 +00:00
|
|
|
#include <Interpreters/IExternalLoaderConfigRepository.h>
|
2023-04-06 17:00:51 +00:00
|
|
|
#include <base/scope_guard.h>
|
2017-04-25 09:10:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2022-09-28 11:20:24 +00:00
|
|
|
|
2017-06-26 08:54:58 +00:00
|
|
|
struct DictionaryStructure;
|
2021-03-19 12:47:27 +00:00
|
|
|
class TableFunctionDictionary;
|
2022-09-28 11:20:24 +00:00
|
|
|
class IDictionary;
|
2017-04-25 09:10:27 +00:00
|
|
|
|
2022-05-03 06:43:28 +00:00
|
|
|
class StorageDictionary final : public IStorage, public WithContext
|
2017-04-25 09:10:27 +00:00
|
|
|
{
|
2022-04-19 20:47:29 +00:00
|
|
|
friend class TableFunctionDictionary;
|
|
|
|
|
2017-04-25 09:10:27 +00:00
|
|
|
public:
|
2022-04-19 20:47:29 +00:00
|
|
|
/// Specifies where the table is located relative to the dictionary.
|
|
|
|
enum class Location
|
|
|
|
{
|
|
|
|
/// Table was created automatically as an element of a database with the Dictionary engine.
|
|
|
|
DictionaryDatabase,
|
|
|
|
|
|
|
|
/// Table was created automatically along with a dictionary
|
|
|
|
/// and has the same database and name as the dictionary.
|
|
|
|
/// It provides table-like access to the dictionary.
|
|
|
|
/// User cannot drop that table.
|
|
|
|
SameDatabaseAndNameAsDictionary,
|
|
|
|
|
|
|
|
/// Table was created explicitly by a statement like
|
|
|
|
/// CREATE TABLE ... ENGINE=Dictionary
|
|
|
|
/// User chose the table's database and name and can drop that table.
|
|
|
|
Custom,
|
|
|
|
};
|
|
|
|
|
|
|
|
StorageDictionary(
|
|
|
|
const StorageID & table_id_,
|
|
|
|
const String & dictionary_name_,
|
|
|
|
const ColumnsDescription & columns_,
|
|
|
|
const String & comment,
|
|
|
|
Location location_,
|
|
|
|
ContextPtr context_);
|
|
|
|
|
|
|
|
StorageDictionary(
|
|
|
|
const StorageID & table_id_,
|
|
|
|
const String & dictionary_name_,
|
|
|
|
const DictionaryStructure & dictionary_structure,
|
|
|
|
const String & comment,
|
|
|
|
Location location_,
|
|
|
|
ContextPtr context_);
|
|
|
|
|
|
|
|
StorageDictionary(
|
|
|
|
const StorageID & table_id_,
|
|
|
|
LoadablesConfigurationPtr dictionary_configuration_,
|
|
|
|
ContextPtr context_);
|
|
|
|
|
2017-04-25 09:10:27 +00:00
|
|
|
std::string getName() const override { return "Dictionary"; }
|
2019-07-09 15:40:21 +00:00
|
|
|
|
2021-04-22 07:53:44 +00:00
|
|
|
~StorageDictionary() override;
|
|
|
|
|
2020-04-09 23:25:52 +00:00
|
|
|
void checkTableCanBeDropped() const override;
|
2020-11-11 14:34:58 +00:00
|
|
|
void checkTableCanBeDetached() const override;
|
2020-04-09 23:25:52 +00:00
|
|
|
|
2020-08-03 13:54:14 +00:00
|
|
|
Pipe read(
|
2020-06-15 19:08:58 +00:00
|
|
|
const Names & column_names,
|
2021-07-09 03:15:41 +00:00
|
|
|
const StorageSnapshotPtr & storage_snapshot,
|
2020-09-20 17:52:17 +00:00
|
|
|
SelectQueryInfo & query_info,
|
2021-04-10 23:33:54 +00:00
|
|
|
ContextPtr context,
|
2018-04-19 14:47:09 +00:00
|
|
|
QueryProcessingStage::Enum processed_stage,
|
2020-02-20 14:40:58 +00:00
|
|
|
size_t max_block_size,
|
2022-10-07 10:46:45 +00:00
|
|
|
size_t threads) override;
|
2020-01-31 08:14:20 +00:00
|
|
|
|
2023-04-14 12:00:02 +00:00
|
|
|
/// FIXME: processing after reading from dictionaries are not parallelized due to some bug:
|
|
|
|
/// count() can return wrong result, see test_dictionaries_redis/test_long.py::test_redis_dict_long
|
|
|
|
bool parallelizeOutputAfterReading() const override { return false; }
|
|
|
|
|
2022-09-28 11:20:24 +00:00
|
|
|
std::shared_ptr<const IDictionary> getDictionary() const;
|
|
|
|
|
2017-12-25 21:57:29 +00:00
|
|
|
static NamesAndTypesList getNamesAndTypes(const DictionaryStructure & dictionary_structure);
|
2020-04-12 20:50:32 +00:00
|
|
|
static String generateNamesAndTypesDescription(const NamesAndTypesList & list);
|
2018-03-13 13:28:32 +00:00
|
|
|
|
2021-04-21 13:45:13 +00:00
|
|
|
bool isDictionary() const override { return true; }
|
2021-04-26 20:35:56 +00:00
|
|
|
void shutdown() override;
|
|
|
|
void startup() override;
|
2021-04-21 13:45:13 +00:00
|
|
|
|
|
|
|
void renameInMemory(const StorageID & new_table_id) override;
|
|
|
|
|
2021-12-28 16:41:57 +00:00
|
|
|
void checkAlterIsPossible(const AlterCommands & commands, ContextPtr /* context */) const override;
|
|
|
|
|
|
|
|
void alter(const AlterCommands & params, ContextPtr alter_context, AlterLockHolder &) override;
|
|
|
|
|
2021-04-22 07:53:44 +00:00
|
|
|
Poco::Timestamp getUpdateTime() const;
|
|
|
|
LoadablesConfigurationPtr getConfiguration() const;
|
2021-04-21 13:45:13 +00:00
|
|
|
|
2021-06-17 22:29:41 +00:00
|
|
|
String getDictionaryName() const { return dictionary_name; }
|
2020-04-08 18:59:52 +00:00
|
|
|
|
2017-04-25 09:10:27 +00:00
|
|
|
private:
|
2021-06-17 22:29:41 +00:00
|
|
|
String dictionary_name;
|
2020-07-05 14:14:20 +00:00
|
|
|
const Location location;
|
2017-04-28 18:33:31 +00:00
|
|
|
|
2021-04-22 07:53:44 +00:00
|
|
|
mutable std::mutex dictionary_config_mutex;
|
2021-04-21 13:45:13 +00:00
|
|
|
Poco::Timestamp update_time;
|
|
|
|
LoadablesConfigurationPtr configuration;
|
2021-04-24 11:02:25 +00:00
|
|
|
|
2021-06-15 19:55:21 +00:00
|
|
|
scope_guard remove_repository_callback;
|
2021-04-21 13:45:13 +00:00
|
|
|
|
2021-04-24 11:02:25 +00:00
|
|
|
void removeDictionaryConfigurationFromRepository();
|
2017-04-25 09:10:27 +00:00
|
|
|
};
|
2017-11-03 21:50:22 +00:00
|
|
|
|
2017-05-15 13:58:40 +00:00
|
|
|
}
|