aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Parsers/Kusto/ParserKQLTable.cpp
blob: 6356ad688b67973d45ac2c9338f56d0fa781517c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <Parsers/ASTLiteral.h>
#include <Parsers/IParserBase.h>
#include <Parsers/ParserTablesInSelectQuery.h>
#include <Parsers/Kusto/ParserKQLQuery.h>
#include <Parsers/Kusto/ParserKQLTable.h>
#include <unordered_set>
namespace DB
{

bool ParserKQLTable :: parseImpl(Pos & pos, ASTPtr & node, Expected & expected)
{
    std::unordered_set<String> sql_keywords
    ({
        "SELECT",
        "INSERT",
        "CREATE",
        "ALTER",
        "SYSTEM",
        "SHOW",
        "GRANT",
        "REVOKE",
        "ATTACH",
        "CHECK",
        "DESCRIBE",
        "DESC",
        "DETACH",
        "DROP",
        "EXISTS",
        "KILL",
        "OPTIMIZE",
        "RENAME",
        "SET",
        "TRUNCATE",
        "USE",
        "EXPLAIN"
    });

    ASTPtr tables;
    String table_name(pos->begin,pos->end);
    String table_name_upcase(table_name);

    std::transform(table_name_upcase.begin(), table_name_upcase.end(),table_name_upcase.begin(), toupper);

    if (sql_keywords.find(table_name_upcase) != sql_keywords.end())
        return false;

    if (!ParserTablesInSelectQuery().parse(pos, tables, expected))
        return false;

    node->as<ASTSelectQuery>()->setExpression(ASTSelectQuery::Expression::TABLES, std::move(tables));

    return true;
}

}