aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yql/plugin/plugin.h
blob: 9c9cc5079832af95f36328590524d816b5b9b74d (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
#pragma once

#include <yt/yql/plugin/bridge/interface.h>

#include <util/generic/hash.h>
#include <util/generic/string.h>

#include <library/cpp/logger/log.h>

#include <library/cpp/yt/string/guid.h>

#include <library/cpp/yt/yson_string/string.h>

#include <optional>

namespace NYT::NYqlPlugin {

using namespace NYson;

////////////////////////////////////////////////////////////////////////////////

using TQueryId = TGuid;

////////////////////////////////////////////////////////////////////////////////

class TYqlPluginOptions
{
public:
    TYsonString SingletonsConfig;
    TYsonString GatewayConfig;
    TYsonString FileStorageConfig;
    TYsonString OperationAttributes;

    TString YTTokenPath;

    THolder<TLogBackend> LogBackend;

    std::optional<TString> YqlPluginSharedLibrary;
};

struct TQueryResult
{
    std::optional<TString> YsonResult;
    std::optional<TString> Plan;
    std::optional<TString> Statistics;
    std::optional<TString> Progress;
    std::optional<TString> TaskInfo;

    //! YSON representation of a YT error.
    std::optional<TString> YsonError;
};

struct TQueryFile
{
    TStringBuf Name;
    TStringBuf Content;
    EQueryFileContentType Type;
};

//! This interface encapsulates YT <-> YQL integration.
//! There are two major implementation: one of them is based
//! on YQL code and another wraps the pure C bridge interface, which
//! is implemented by a dynamic library.
/*!
*  \note Thread affinity: any
*/
struct IYqlPlugin
{
    virtual TQueryResult Run(TQueryId queryId, TString impersonationUser, TString queryText, TYsonString settings, std::vector<TQueryFile> files) noexcept = 0;
    virtual TQueryResult GetProgress(TQueryId queryId) noexcept = 0;

    virtual ~IYqlPlugin() = default;
};

////////////////////////////////////////////////////////////////////////////////

Y_WEAK std::unique_ptr<IYqlPlugin> CreateYqlPlugin(TYqlPluginOptions& options) noexcept;

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NYqlPlugin