aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/sql_call_expr.h
blob: 9b9d39b81a84bea1b4708077c12b941723c0cabd (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
#pragma once

#include "sql_translation.h"

namespace NSQLTranslationV1 {

TNodePtr BuildSqlCall(TContext& ctx, TPosition pos, const TString& module, const TString& name, const TVector<TNodePtr>& args,
    TNodePtr positionalArgs, TNodePtr namedArgs, TNodePtr customUserType, const TDeferredAtom& typeConfig, TNodePtr runConfig);

using namespace NSQLv1Generated;

class TSqlCallExpr: public TSqlTranslation {
public:
    TSqlCallExpr(TContext& ctx, NSQLTranslation::ESqlMode mode)
        : TSqlTranslation(ctx, mode)
    {
    }

    TSqlCallExpr(const TSqlCallExpr& call, const TVector<TNodePtr>& args)
        : TSqlTranslation(call.Ctx, call.Mode)
        , Pos(call.Pos)
        , Func(call.Func)
        , Module(call.Module)
        , Node(call.Node)
        , Args(args)
        , AggMode(call.AggMode)
        , DistinctAllowed(call.DistinctAllowed)
        , UsingCallExpr(call.UsingCallExpr)
        , IsExternalCall(call.IsExternalCall)
        , CallConfig(call.CallConfig)
    {
    }

    void AllowDistinct() {
        DistinctAllowed = true;
    }

    void InitName(const TString& name);
    void InitExpr(const TNodePtr& expr);

    bool Init(const TRule_using_call_expr& node);
    bool Init(const TRule_value_constructor& node);
    bool Init(const TRule_invoke_expr& node);
    bool ConfigureExternalCall(const TRule_external_call_settings& node);
    void IncCounters();

    TNodePtr BuildUdf(bool forReduce);

    TNodePtr BuildCall();

    TPosition GetPos() const {
        return Pos;
    }

    const TVector<TNodePtr>& GetArgs() const {
        return Args;
    }

    void SetOverWindow() {
        YQL_ENSURE(AggMode == EAggregateMode::Normal);
        AggMode = EAggregateMode::OverWindow;
    }

    void SetOverWindowDistinct() {
        YQL_ENSURE(AggMode == EAggregateMode::Distinct);
        AggMode = EAggregateMode::OverWindowDistinct;
    }

    void SetIgnoreNulls() {
        Func += "_IgnoreNulls";
    }

    bool IsExternal() {
        return IsExternalCall;
    }

private:
    bool ExtractCallParam(const TRule_external_call_param& node);
    bool FillArg(const TString& module, const TString& func, size_t& idx, const TRule_named_expr& node);
    bool FillArgs(const TRule_named_expr_list& node);

private:
    TPosition Pos;
    TString Func;
    TString Module;
    TNodePtr Node;
    TVector<TNodePtr> Args;
    TVector<TNodePtr> PositionalArgs;
    TVector<TNodePtr> NamedArgs;
    EAggregateMode AggMode = EAggregateMode::Normal;
    TString WindowName;
    bool DistinctAllowed = false;
    bool UsingCallExpr = false;
    bool IsExternalCall = false;
    TFunctionConfig CallConfig;
};

} // namespace NSQLTranslationV1