aboutsummaryrefslogblamecommitdiffstats
path: root/yt/yql/plugin/plugin.h
blob: 3fcc8e3e16487e027eb0beea405eeb0372bc72d2 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
            
                                           
                                   
                                       
                                              

                                


                           
                                                                                


                                                                                

                       


                                           











                                                  
                                    




                                          





                               




                                          


                                                                    

                             
                 




                                                    
                                                                    
 
                                                              








                                                                                        
#pragma once

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

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

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

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

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

#include <optional>

namespace NYT::NYqlPlugin {

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

using TQueryId = TGuid;

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

class TYqlPluginOptions
{
public:
    NYson::TYsonString SingletonsConfig;
    NYson::TYsonString GatewayConfig;
    NYson::TYsonString FileStorageConfig;
    NYson::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;
};

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

//! 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,
        NYson::TYsonString settings,
        std::vector<TQueryFile> files) noexcept = 0;
    virtual TQueryResult GetProgress(TQueryId queryId) noexcept = 0;

    virtual TAbortResult Abort(TQueryId queryId) noexcept = 0;

    virtual ~IYqlPlugin() = default;
};

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

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

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

} // namespace NYT::NYqlPlugin