ClickHouse/src/Storages/StorageDictionary.h

97 lines
3.0 KiB
C++
Raw Normal View History

2017-04-25 09:10:27 +00:00
#pragma once
#include <Storages/IStorage.h>
#include <ext/shared_ptr_helper.h>
2021-04-21 13:45:13 +00:00
#include <Interpreters/IExternalLoaderConfigRepository.h>
2017-04-25 09:10:27 +00:00
namespace DB
{
struct DictionaryStructure;
2021-03-19 12:47:27 +00:00
class TableFunctionDictionary;
2017-04-25 09:10:27 +00:00
2021-04-21 13:45:13 +00:00
class StorageDictionary final : public ext::shared_ptr_helper<StorageDictionary>, public IStorage, public WithContext
2017-04-25 09:10:27 +00:00
{
2019-08-26 19:07:29 +00:00
friend struct ext::shared_ptr_helper<StorageDictionary>;
2021-03-19 12:47:27 +00:00
friend class TableFunctionDictionary;
2017-04-25 09:10:27 +00:00
public:
std::string getName() const override { return "Dictionary"; }
2021-04-22 07:53:44 +00:00
~StorageDictionary() override;
void checkTableCanBeDropped() const override;
void checkTableCanBeDetached() const override;
2020-08-03 13:54:14 +00:00
Pipe read(
const Names & column_names,
const StorageMetadataPtr & /*metadata_snapshot*/,
SelectQueryInfo & query_info,
ContextPtr context,
QueryProcessingStage::Enum processed_stage,
2020-02-20 14:40:58 +00:00
size_t max_block_size,
unsigned threads) override;
static NamesAndTypesList getNamesAndTypes(const DictionaryStructure & dictionary_structure);
static String generateNamesAndTypesDescription(const NamesAndTypesList & list);
2021-04-21 13:45:13 +00:00
bool isDictionary() const override { return true; }
void drop() override;
void shutdown() override;
void renameInMemory(const StorageID & new_table_id) 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-04-22 09:19:59 +00:00
const String & getDictionaryName() const { return dictionary_name; }
/// Specifies where the table is located relative to the dictionary.
enum class Location
{
2020-07-05 15:44:28 +00:00
/// 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
2020-07-05 15:45:05 +00:00
/// User chose the table's database and name and can drop that table.
Custom,
};
2017-04-25 09:10:27 +00:00
private:
const String dictionary_name;
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;
ext::scope_guard remove_repository_callback;
protected:
StorageDictionary(
2019-12-04 16:06:55 +00:00
const StorageID & table_id_,
const String & dictionary_name_,
const ColumnsDescription & columns_,
2021-04-21 13:45:13 +00:00
Location location_,
ContextPtr context_);
StorageDictionary(
const StorageID & table_id_,
const String & dictionary_name_,
const DictionaryStructure & dictionary_structure,
2021-04-21 13:45:13 +00:00
Location location_,
ContextPtr context_);
StorageDictionary(
const StorageID & table_id_,
LoadablesConfigurationPtr dictionary_configuration_,
ContextPtr context_);
2017-04-25 09:10:27 +00:00
};
}