| 1 | #include <Parsers/ASTDictionary.h> |
| 2 | #include <Poco/String.h> |
| 3 | |
| 4 | namespace DB |
| 5 | { |
| 6 | |
| 7 | ASTPtr ASTDictionaryRange::clone() const |
| 8 | { |
| 9 | auto res = std::make_shared<ASTDictionaryRange>(*this); |
| 10 | res->children.clear(); |
| 11 | res->min_attr_name = min_attr_name; |
| 12 | res->max_attr_name = max_attr_name; |
| 13 | return res; |
| 14 | } |
| 15 | |
| 16 | |
| 17 | void ASTDictionaryRange::formatImpl(const FormatSettings & settings, |
| 18 | FormatState &, |
| 19 | FormatStateStacked) const |
| 20 | { |
| 21 | settings.ostr << (settings.hilite ? hilite_keyword : "" ) |
| 22 | << "RANGE" |
| 23 | << (settings.hilite ? hilite_none : "" ) |
| 24 | << "(" |
| 25 | << (settings.hilite ? hilite_keyword : "" ) |
| 26 | << "MIN " |
| 27 | << min_attr_name << " " |
| 28 | << (settings.hilite ? hilite_keyword : "" ) |
| 29 | << "MAX " |
| 30 | << (settings.hilite ? hilite_none : "" ) |
| 31 | << max_attr_name << ")" ; |
| 32 | } |
| 33 | |
| 34 | |
| 35 | |
| 36 | ASTPtr ASTDictionaryLifetime::clone() const |
| 37 | { |
| 38 | auto res = std::make_shared<ASTDictionaryLifetime>(*this); |
| 39 | res->children.clear(); |
| 40 | res->min_sec = min_sec; |
| 41 | res->max_sec = max_sec; |
| 42 | return res; |
| 43 | } |
| 44 | |
| 45 | |
| 46 | void ASTDictionaryLifetime::formatImpl(const FormatSettings & settings, |
| 47 | FormatState &, |
| 48 | FormatStateStacked) const |
| 49 | { |
| 50 | settings.ostr << (settings.hilite ? hilite_keyword : "" ) |
| 51 | << "LIFETIME" |
| 52 | << (settings.hilite ? hilite_none : "" ) |
| 53 | << "(" |
| 54 | << (settings.hilite ? hilite_keyword : "" ) |
| 55 | << "MIN " |
| 56 | << min_sec << " " |
| 57 | << (settings.hilite ? hilite_keyword : "" ) |
| 58 | << "MAX " |
| 59 | << (settings.hilite ? hilite_none : "" ) |
| 60 | << max_sec << ")" ; |
| 61 | } |
| 62 | |
| 63 | |
| 64 | ASTPtr ASTDictionaryLayout::clone() const |
| 65 | { |
| 66 | auto res = std::make_shared<ASTDictionaryLayout>(*this); |
| 67 | res->children.clear(); |
| 68 | res->layout_type = layout_type; |
| 69 | if (parameter.has_value()) |
| 70 | { |
| 71 | res->parameter.emplace(parameter->first, nullptr); |
| 72 | res->set(res->parameter->second, parameter->second->clone()); |
| 73 | } |
| 74 | return res; |
| 75 | } |
| 76 | |
| 77 | |
| 78 | void ASTDictionaryLayout::formatImpl(const FormatSettings & settings, |
| 79 | FormatState & state, |
| 80 | FormatStateStacked expected) const |
| 81 | { |
| 82 | settings.ostr << (settings.hilite ? hilite_keyword : "" ) |
| 83 | << "LAYOUT" |
| 84 | << (settings.hilite ? hilite_none : "" ) |
| 85 | << "(" |
| 86 | << (settings.hilite ? hilite_keyword : "" ) |
| 87 | << Poco::toUpper(layout_type) |
| 88 | << (settings.hilite ? hilite_none : "" ); |
| 89 | |
| 90 | settings.ostr << "(" ; |
| 91 | if (parameter) |
| 92 | { |
| 93 | settings.ostr << (settings.hilite ? hilite_keyword : "" ) |
| 94 | << Poco::toUpper(parameter->first) |
| 95 | << (settings.hilite ? hilite_none : "" ) |
| 96 | << " " ; |
| 97 | |
| 98 | parameter->second->formatImpl(settings, state, expected); |
| 99 | } |
| 100 | settings.ostr << ")" ; |
| 101 | settings.ostr << ")" ; |
| 102 | } |
| 103 | |
| 104 | |
| 105 | ASTPtr ASTDictionary::clone() const |
| 106 | { |
| 107 | auto res = std::make_shared<ASTDictionary>(*this); |
| 108 | res->children.clear(); |
| 109 | |
| 110 | if (source) |
| 111 | res->set(res->source, source->clone()); |
| 112 | |
| 113 | if (primary_key) |
| 114 | res->set(res->primary_key, primary_key->clone()); |
| 115 | |
| 116 | if (lifetime) |
| 117 | res->set(res->lifetime, lifetime->clone()); |
| 118 | |
| 119 | if (layout) |
| 120 | res->set(res->layout, layout->clone()); |
| 121 | |
| 122 | if (range) |
| 123 | res->set(res->range, range->clone()); |
| 124 | |
| 125 | return res; |
| 126 | } |
| 127 | |
| 128 | |
| 129 | void ASTDictionary::formatImpl(const FormatSettings & settings, FormatState & state, FormatStateStacked frame) const |
| 130 | { |
| 131 | if (primary_key) |
| 132 | { |
| 133 | settings.ostr << (settings.hilite ? hilite_keyword : "" ) << settings.nl_or_ws << "PRIMARY KEY " |
| 134 | << (settings.hilite ? hilite_none : "" ); |
| 135 | primary_key->formatImpl(settings, state, frame); |
| 136 | } |
| 137 | |
| 138 | if (source) |
| 139 | { |
| 140 | settings.ostr << (settings.hilite ? hilite_keyword : "" ) << settings.nl_or_ws << "SOURCE(" |
| 141 | << (settings.hilite ? hilite_none : "" ); |
| 142 | source->formatImpl(settings, state, frame); |
| 143 | settings.ostr << ")" ; |
| 144 | } |
| 145 | |
| 146 | if (lifetime) |
| 147 | { |
| 148 | settings.ostr << settings.nl_or_ws; |
| 149 | lifetime->formatImpl(settings, state, frame); |
| 150 | } |
| 151 | |
| 152 | if (layout) |
| 153 | { |
| 154 | settings.ostr << settings.nl_or_ws; |
| 155 | layout->formatImpl(settings, state, frame); |
| 156 | } |
| 157 | |
| 158 | if (range) |
| 159 | { |
| 160 | settings.ostr << settings.nl_or_ws; |
| 161 | range->formatImpl(settings, state, frame); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | } |
| 166 | |