| 1 | #include <Poco/String.h> | 
|---|
| 2 | #include <Interpreters/misc.h> | 
|---|
| 3 | #include <Interpreters/MarkTableIdentifiersVisitor.h> | 
|---|
| 4 | #include <Interpreters/IdentifierSemantic.h> | 
|---|
| 5 | #include <Parsers/ASTFunction.h> | 
|---|
| 6 | #include <Parsers/ASTSelectQuery.h> | 
|---|
| 7 | #include <Parsers/ASTTablesInSelectQuery.h> | 
|---|
| 8 |  | 
|---|
| 9 | namespace DB | 
|---|
| 10 | { | 
|---|
| 11 |  | 
|---|
| 12 | bool MarkTableIdentifiersMatcher::needChildVisit(ASTPtr & node, const ASTPtr & child) | 
|---|
| 13 | { | 
|---|
| 14 | if (child->as<ASTSelectQuery>()) | 
|---|
| 15 | return false; | 
|---|
| 16 | if (node->as<ASTTableExpression>()) | 
|---|
| 17 | return false; | 
|---|
| 18 | return true; | 
|---|
| 19 | } | 
|---|
| 20 |  | 
|---|
| 21 | void MarkTableIdentifiersMatcher::visit(ASTPtr & ast, Data & data) | 
|---|
| 22 | { | 
|---|
| 23 | if (auto * node_func = ast->as<ASTFunction>()) | 
|---|
| 24 | visit(*node_func, ast, data); | 
|---|
| 25 | else if (auto * node_table = ast->as<ASTTableExpression>()) | 
|---|
| 26 | visit(*node_table, ast, data); | 
|---|
| 27 | } | 
|---|
| 28 |  | 
|---|
| 29 | void MarkTableIdentifiersMatcher::visit(ASTTableExpression & table, ASTPtr &, Data &) | 
|---|
| 30 | { | 
|---|
| 31 | if (table.database_and_table_name) | 
|---|
| 32 | setIdentifierSpecial(table.database_and_table_name); | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | void MarkTableIdentifiersMatcher::visit(const ASTFunction & func, ASTPtr &, Data & data) | 
|---|
| 36 | { | 
|---|
| 37 | /// `IN t` can be specified, where t is a table, which is equivalent to `IN (SELECT * FROM t)`. | 
|---|
| 38 | if (functionIsInOrGlobalInOperator(func.name)) | 
|---|
| 39 | { | 
|---|
| 40 | auto & ast = func.arguments->children.at(1); | 
|---|
| 41 | if (auto opt_name = tryGetIdentifierName(ast)) | 
|---|
| 42 | if (!data.aliases.count(*opt_name)) | 
|---|
| 43 | setIdentifierSpecial(ast); | 
|---|
| 44 | } | 
|---|
| 45 |  | 
|---|
| 46 | // first argument of joinGet can be a table identifier | 
|---|
| 47 | if (func.name == "joinGet") | 
|---|
| 48 | { | 
|---|
| 49 | auto & ast = func.arguments->children.at(0); | 
|---|
| 50 | if (auto opt_name = tryGetIdentifierName(ast)) | 
|---|
| 51 | setIdentifierSpecial(ast); | 
|---|
| 52 | } | 
|---|
| 53 | } | 
|---|
| 54 |  | 
|---|
| 55 | } | 
|---|
| 56 |  | 
|---|