aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/yql_udf_resolver.h
blob: 915a7a40407fccd20a73a3b2c9e1651fe4d29cb2 (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
#pragma once

#include "yql_user_data.h"
#include <yql/essentials/providers/common/proto/udf_resolver.pb.h>

#include <yql/essentials/core/yql_holding_file_storage.h>
#include <yql/essentials/public/langver/yql_langver.h>
#include <yql/essentials/public/issue/yql_issue.h>
#include <yql/essentials/public/udf/udf_log.h>

#include <util/generic/maybe.h>
#include <util/generic/vector.h>

namespace NYql {

class TTypeAnnotationNode;
struct TUserDataBlock;
struct TExprContext;

struct TFilePathWithMd5 {
    TString Path;
    TString Md5;

    explicit TFilePathWithMd5(const TString& path = "", const TString& md5 = "")
        : Path(path)
        , Md5(md5)
    {
    }

    TFilePathWithMd5& operator=(const TFilePathWithMd5& other) = default;
};

class IUdfResolver : public TThrRefBase {
public:
    using TPtr = TIntrusiveConstPtr<IUdfResolver>;

    virtual ~IUdfResolver() = default;

    struct TFunction {
        // input
        TPosition Pos;
        TString Name;
        TString TypeConfig;
        const TTypeAnnotationNode* UserType = nullptr;
        THashMap<TString, TString> SecureParams;
        NYql::TLangVersion LangVer = NYql::UnknownLangVersion;

        // output
        TString NormalizedName;
        const TTypeAnnotationNode* NormalizedUserType = nullptr;
        const TTypeAnnotationNode* RunConfigType = nullptr;
        const TTypeAnnotationNode* CallableType = nullptr;
        bool SupportsBlocks = false;
        bool IsStrict = false;
        NYql::TLangVersion MinLangVer = NYql::UnknownLangVersion;
        NYql::TLangVersion MaxLangVer = NYql::UnknownLangVersion;
        TVector<TString> Messages;
    };

    struct TImport {
        // input
        TPosition Pos;
        TString FileAlias;
        const TUserDataBlock* Block = nullptr;

        // output
        TMaybe<TVector<TString>> Modules;
    };

    /*
    Returns nothing if module is not a system one
    Always returns frozen path
    */
    virtual TMaybe<TFilePathWithMd5> GetSystemModulePath(const TStringBuf& moduleName) const = 0;
    virtual bool LoadMetadata(const TVector<TImport*>& imports,
        const TVector<TFunction*>& functions, TExprContext& ctx, NUdf::ELogLevel logLevel, THoldingFileStorage& storage) const = 0;

    virtual TResolveResult LoadRichMetadata(const TVector<TImport>& imports, NUdf::ELogLevel logLevel, THoldingFileStorage& storage) const = 0;
    virtual bool ContainsModule(const TStringBuf& moduleName) const = 0;
};

TResolveResult LoadRichMetadata(const IUdfResolver& resolver, const TVector<TUserDataBlock>& blocks, THoldingFileStorage& storage, NUdf::ELogLevel logLevel = NUdf::ELogLevel::Info);
TResolveResult LoadRichMetadata(const IUdfResolver& resolver, const TVector<TString>& paths, THoldingFileStorage& storage, NUdf::ELogLevel logLevel = NUdf::ELogLevel::Info);

}