aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/settings/translation_settings.h
blob: 57f79d74888ddc9204d62b46f7a45dbe83d23653 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#pragma once

#include <yql/essentials/core/pg_settings/guc_settings.h>

#include <util/generic/hash.h>
#include <util/generic/hash_set.h>
#include <util/generic/map.h>
#include <util/generic/maybe.h>
#include <util/generic/vector.h>

namespace google::protobuf {
    class Arena;
}

namespace NYql {
    class TIssues;
    class IAutoParamBuilderFactory;
}

namespace NSQLTranslation {
    constexpr const size_t SQL_MAX_PARSER_ERRORS = 100;

    enum class ESqlMode {
        QUERY = 0,
        LIMITED_VIEW = 1,
        LIBRARY = 2,
        SUBQUERY = 3,
        DISCOVERY = 4,
    };

    enum class EBindingsMode {
        // raise error
        DISABLED,
        // classic support for bindings
        ENABLED,
        // bindings.my_binding -> current_cluster.my_binding + raise warning
        DROP_WITH_WARNING,
        // bindings.my_binding -> current_cluster.my_binding
        DROP
    };

    inline bool IsQueryMode(NSQLTranslation::ESqlMode mode) {
        return mode == NSQLTranslation::ESqlMode::QUERY || mode == NSQLTranslation::ESqlMode::DISCOVERY;
    }

    using TIncrementMonCounterFunction = std::function<void(const TString&, const TString&)>;

    // persisted
    enum class EV0Behavior : ui32 {
        Silent = 0,
        Report,
        Disable
    };

    class ISqlFeaturePolicy : public TThrRefBase {
    public:
        virtual ~ISqlFeaturePolicy() = default;
        virtual bool Allow() const = 0;

        using TPtr = TIntrusivePtr<ISqlFeaturePolicy>;

        static TPtr MakeAlwaysDisallow();

        static TPtr MakeAlwaysAllow();

        static TPtr Make(bool allow);
    };

    struct TTableBindingSettings {
        TString ClusterType;
        THashMap<TString, TString> Settings;
    };

    struct TTranslationSettings
    {
        TTranslationSettings();
        google::protobuf::Arena* Arena = nullptr;

        THashMap<TString, TString> ClusterMapping;
        TString PathPrefix;
        // keys (cluster name) should be normalized
        THashMap<TString, TString> ClusterPathPrefixes;
        THashMap<TString, TString> ModuleMapping;
        THashSet<TString> Libraries;
        THashSet<TString> Flags;

        EBindingsMode BindingsMode;
        THashMap<TString, TTableBindingSettings> Bindings;
        bool SaveWorldDependencies = false;

        // each (name, type) entry in this map is equivalent to
        // DECLARE $name AS type;
        // NOTE: DECLARE statement in SQL text overrides entry in DeclaredNamedExprs
        TMap<TString, TString> DeclaredNamedExprs;

        ESqlMode Mode;
        TString DefaultCluster;
        TIncrementMonCounterFunction IncrementCounter;
        size_t MaxErrors;
        bool EndOfQueryCommit;
        TString File;
        bool EnableGenericUdfs;
        ui16 SyntaxVersion;
        bool AnsiLexer;
        bool Antlr4Parser;
        bool PgParser;
        bool InferSyntaxVersion;
        EV0Behavior V0Behavior;
        bool V0ForceDisable;
        bool PGDisable;
        bool WarnOnV0;
        bool TestAntlr4;
        ISqlFeaturePolicy::TPtr V0WarnAsError;
        ISqlFeaturePolicy::TPtr DqDefaultAuto;
        ISqlFeaturePolicy::TPtr BlockDefaultAuto;
        bool AssumeYdbOnClusterWithSlash;
        TString DynamicClusterProvider;
        TString FileAliasPrefix;

        TVector<ui32> PgParameterTypeOids;
        bool AutoParametrizeEnabled = false;
        bool AutoParametrizeValuesStmt = false;

        TGUCSettings::TPtr GUCSettings = std::make_shared<TGUCSettings>();
        bool UnicodeLiterals = false;

        TMaybe<TString> ApplicationName;
        bool PgSortNulls = false;
        NYql::IAutoParamBuilderFactory* AutoParamBuilderFactory = nullptr;
    };

    bool ParseTranslationSettings(const TString& query, NSQLTranslation::TTranslationSettings& settings, NYql::TIssues& issues);

}  // namespace NSQLTranslation