1#pragma once
2
3#include <Parsers/IAST.h>
4#include <Parsers/ASTFunctionWithKeyValueArguments.h>
5#include <Parsers/ASTLiteral.h>
6#include <Parsers/ASTExpressionList.h>
7
8namespace DB
9{
10
11/// AST for external dictionary lifetime:
12/// lifetime(min 10 max 100)
13class ASTDictionaryLifetime : public IAST
14{
15public:
16 UInt64 min_sec = 0;
17 UInt64 max_sec = 0;
18
19 String getID(char) const override { return "Dictionary lifetime"; }
20
21 ASTPtr clone() const override;
22
23 void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
24};
25
26/// AST for external dictionary layout. Has name and contain single parameter
27/// layout(type()) or layout(type(param value))
28class ASTDictionaryLayout : public IAST
29{
30 using KeyValue = std::pair<std::string, ASTLiteral *>;
31public:
32 /// flat, cache, hashed, etc.
33 String layout_type;
34 /// optional parameter (size_in_cells)
35 std::optional<KeyValue> parameter;
36
37 String getID(char) const override { return "Dictionary layout"; }
38
39 ASTPtr clone() const override;
40
41 void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
42};
43
44
45/// AST for external range-hashed dictionary
46/// Range bounded with two attributes from minimum to maximum
47/// RANGE(min attr1 max attr2)
48class ASTDictionaryRange : public IAST
49{
50public:
51 String min_attr_name;
52 String max_attr_name;
53
54 String getID(char) const override { return "Dictionary range"; }
55
56 ASTPtr clone() const override;
57
58 void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
59};
60
61
62/// AST contains all parts of external dictionary definition except attributes
63class ASTDictionary : public IAST
64{
65public:
66 /// Dictionary keys -- one or more
67 ASTExpressionList * primary_key;
68 /// Dictionary external source, doesn't have own AST, because
69 /// source parameters absolutely different for different sources
70 ASTFunctionWithKeyValueArguments * source;
71
72 /// Lifetime of dictionary (required part)
73 ASTDictionaryLifetime * lifetime;
74 /// Layout of dictionary (required part)
75 ASTDictionaryLayout * layout;
76 /// Range for dictionary (only for range-hashed dictionaries)
77 ASTDictionaryRange * range;
78
79 String getID(char) const override { return "Dictionary definition"; }
80
81 ASTPtr clone() const override;
82
83 void formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const override;
84};
85
86}
87