| 1 | #include <Storages/IndicesDescription.h> |
|---|---|
| 2 | |
| 3 | #include <Parsers/ASTIndexDeclaration.h> |
| 4 | #include <Parsers/formatAST.h> |
| 5 | #include <Parsers/ParserCreateQuery.h> |
| 6 | #include <Parsers/parseQuery.h> |
| 7 | |
| 8 | namespace DB |
| 9 | { |
| 10 | |
| 11 | bool IndicesDescription::empty() const |
| 12 | { |
| 13 | return indices.empty(); |
| 14 | } |
| 15 | |
| 16 | bool IndicesDescription::has(const String & name) const |
| 17 | { |
| 18 | return std::cend(indices) != std::find_if( |
| 19 | std::cbegin(indices), std::cend(indices), |
| 20 | [&name](const auto & index) |
| 21 | { |
| 22 | return index->name == name; |
| 23 | }); |
| 24 | } |
| 25 | |
| 26 | String IndicesDescription::toString() const |
| 27 | { |
| 28 | if (indices.empty()) |
| 29 | return {}; |
| 30 | |
| 31 | ASTExpressionList list; |
| 32 | for (const auto & index : indices) |
| 33 | list.children.push_back(index); |
| 34 | |
| 35 | return serializeAST(list, true); |
| 36 | } |
| 37 | |
| 38 | IndicesDescription IndicesDescription::parse(const String & str) |
| 39 | { |
| 40 | if (str.empty()) |
| 41 | return {}; |
| 42 | |
| 43 | IndicesDescription res; |
| 44 | ParserIndexDeclarationList parser; |
| 45 | ASTPtr list = parseQuery(parser, str, 0); |
| 46 | |
| 47 | for (const auto & index : list->children) |
| 48 | res.indices.push_back(std::dynamic_pointer_cast<ASTIndexDeclaration>(index)); |
| 49 | |
| 50 | return res; |
| 51 | } |
| 52 | |
| 53 | } |
| 54 |