aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/configuration.cpp
blob: 9dbba885b2cba3b88853c6ca871a16d949eda054 (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
56
57
58
59
60
61
62
#include "configuration.h"

#include <yql/essentials/sql/v1/complete/syntax/grammar.h>

namespace NSQLComplete {

    TConfiguration MakeConfiguration(THashSet<TString> allowedStmts) {
        allowedStmts.emplace("sql_stmt");

        TConfiguration config;
        for (const std::string& name : GetSqlGrammar().GetAllRules()) {
            if (name.ends_with("_stmt") && !allowedStmts.contains(name)) {
                config.IgnoredRules_.emplace(name);
            }
        }
        return config;
    }

    TConfiguration MakeYDBConfiguration() {
        TConfiguration config;
        config.IgnoredRules_ = {
            "use_stmt",
            "import_stmt",
            "export_stmt",
        };
        return config;
    }

    TConfiguration MakeYQLConfiguration() {
        auto config = MakeConfiguration(/* allowedStmts = */ {
            "lambda_stmt",
            "pragma_stmt",
            "select_stmt",
            "named_nodes_stmt",
            "drop_table_stmt",
            "use_stmt",
            "into_table_stmt",
            "commit_stmt",
            "declare_stmt",
            "import_stmt",
            "export_stmt",
            "do_stmt",
            "define_action_or_subquery_stmt",
            "if_stmt",
            "for_stmt",
            "values_stmt",
        });

        config.DisabledPreviousByToken_ = {};

        config.ForcedPreviousByToken_ = {
            {"PARALLEL", {}},
            {"TABLESTORE", {}},
            {"FOR", {"EVALUATE"}},
            {"IF", {"EVALUATE"}},
            {"EXTERNAL", {"USING"}},
        };

        return config;
    }

} // namespace NSQLComplete