aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Dictionaries/DictionaryFactory.h
blob: 35097a5ed246f49dc79bf568651fd6d643ec7bd4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma once

#include <Interpreters/Context_fwd.h>
#include "IDictionary.h"
#include "registerDictionaries.h"
#include <Parsers/ASTCreateQuery.h>


namespace Poco
{

namespace Util
{
    class AbstractConfiguration;
}

class Logger;

}


namespace DB
{

/** Create dictionary according to its layout.
  */
class DictionaryFactory : private boost::noncopyable
{
public:

    static DictionaryFactory & instance();

    /// Create dictionary from AbstractConfiguration parsed
    /// from xml-file on filesystem.
    DictionaryPtr create(
        const std::string & name,
        const Poco::Util::AbstractConfiguration & config,
        const std::string & config_prefix,
        ContextPtr global_context,
        bool created_from_ddl) const;

    /// Create dictionary from DDL-query
    DictionaryPtr create(const std::string & name,
        const ASTCreateQuery & ast,
        ContextPtr global_context) const;

    using LayoutCreateFunction = std::function<DictionaryPtr(
        const std::string & name,
        const DictionaryStructure & dict_struct,
        const Poco::Util::AbstractConfiguration & config,
        const std::string & config_prefix,
        DictionarySourcePtr source_ptr,
        ContextPtr global_context,
        bool created_from_ddl)>;

    bool isComplex(const std::string & layout_type) const;

    /// If the argument `layout_type` is not complex layout and has corresponding complex layout,
    /// change `layout_type` to corresponding complex and return true; otherwise do nothing and return false.
    bool convertToComplex(std::string & layout_type) const;

    void registerLayout(const std::string & layout_type, LayoutCreateFunction create_layout, bool is_layout_complex, bool has_layout_complex = true);

private:
    struct RegisteredLayout
    {
        LayoutCreateFunction layout_create_function;
        bool is_layout_complex;
        bool has_layout_complex;
    };

    using LayoutRegistry = std::unordered_map<std::string, RegisteredLayout>;
    LayoutRegistry registered_layouts;

};

}