| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <unordered_map> |
| 4 | |
| 5 | #include <Parsers/ASTAsterisk.h> |
| 6 | #include <Parsers/ASTQualifiedAsterisk.h> |
| 7 | #include <Parsers/ASTColumnsMatcher.h> |
| 8 | |
| 9 | namespace DB |
| 10 | { |
| 11 | |
| 12 | struct AsteriskSemanticImpl |
| 13 | { |
| 14 | using RevertedAliases = std::unordered_map<String, std::vector<String>>; |
| 15 | using RevertedAliasesPtr = std::shared_ptr<RevertedAliases>; |
| 16 | |
| 17 | RevertedAliasesPtr aliases; /// map of aliases that should be set in phase of * expanding. |
| 18 | }; |
| 19 | |
| 20 | |
| 21 | struct AsteriskSemantic |
| 22 | { |
| 23 | using RevertedAliases = AsteriskSemanticImpl::RevertedAliases; |
| 24 | using RevertedAliasesPtr = AsteriskSemanticImpl::RevertedAliasesPtr; |
| 25 | |
| 26 | static void setAliases(ASTAsterisk & node, const RevertedAliasesPtr & aliases) { node.semantic = makeSemantic(aliases); } |
| 27 | static void setAliases(ASTQualifiedAsterisk & node, const RevertedAliasesPtr & aliases) { node.semantic = makeSemantic(aliases); } |
| 28 | static void setAliases(ASTColumnsMatcher & node, const RevertedAliasesPtr & aliases) { node.semantic = makeSemantic(aliases); } |
| 29 | |
| 30 | static RevertedAliasesPtr getAliases(const ASTAsterisk & node) { return node.semantic ? node.semantic->aliases : nullptr; } |
| 31 | static RevertedAliasesPtr getAliases(const ASTQualifiedAsterisk & node) { return node.semantic ? node.semantic->aliases : nullptr; } |
| 32 | static RevertedAliasesPtr getAliases(const ASTColumnsMatcher & node) { return node.semantic ? node.semantic->aliases : nullptr; } |
| 33 | |
| 34 | private: |
| 35 | static std::shared_ptr<AsteriskSemanticImpl> makeSemantic(const RevertedAliasesPtr & aliases) |
| 36 | { |
| 37 | return std::make_shared<AsteriskSemanticImpl>(AsteriskSemanticImpl{aliases}); |
| 38 | } |
| 39 | }; |
| 40 | |
| 41 | } |
| 42 |