plugin.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. #include <yt/yql/plugin/bridge/interface.h>
  3. #include <util/generic/hash.h>
  4. #include <util/generic/string.h>
  5. #include <library/cpp/logger/log.h>
  6. #include <library/cpp/yt/string/guid.h>
  7. #include <library/cpp/yt/yson_string/string.h>
  8. #include <optional>
  9. namespace NYT::NYqlPlugin {
  10. using namespace NYson;
  11. ////////////////////////////////////////////////////////////////////////////////
  12. using TQueryId = TGuid;
  13. ////////////////////////////////////////////////////////////////////////////////
  14. class TYqlPluginOptions
  15. {
  16. public:
  17. TYsonString SingletonsConfig;
  18. TYsonString GatewayConfig;
  19. TYsonString FileStorageConfig;
  20. TYsonString OperationAttributes;
  21. TString YTTokenPath;
  22. THolder<TLogBackend> LogBackend;
  23. std::optional<TString> YqlPluginSharedLibrary;
  24. };
  25. struct TQueryResult
  26. {
  27. std::optional<TString> YsonResult;
  28. std::optional<TString> Plan;
  29. std::optional<TString> Statistics;
  30. std::optional<TString> Progress;
  31. std::optional<TString> TaskInfo;
  32. //! YSON representation of a YT error.
  33. std::optional<TString> YsonError;
  34. };
  35. struct TQueryFile
  36. {
  37. TStringBuf Name;
  38. TStringBuf Content;
  39. EQueryFileContentType Type;
  40. };
  41. //! This interface encapsulates YT <-> YQL integration.
  42. //! There are two major implementation: one of them is based
  43. //! on YQL code and another wraps the pure C bridge interface, which
  44. //! is implemented by a dynamic library.
  45. /*!
  46. * \note Thread affinity: any
  47. */
  48. struct IYqlPlugin
  49. {
  50. virtual TQueryResult Run(TQueryId queryId, TString impersonationUser, TString queryText, TYsonString settings, std::vector<TQueryFile> files) noexcept = 0;
  51. virtual TQueryResult GetProgress(TQueryId queryId) noexcept = 0;
  52. virtual ~IYqlPlugin() = default;
  53. };
  54. ////////////////////////////////////////////////////////////////////////////////
  55. Y_WEAK std::unique_ptr<IYqlPlugin> CreateYqlPlugin(TYqlPluginOptions& options) noexcept;
  56. ////////////////////////////////////////////////////////////////////////////////
  57. } // namespace NYT::NYqlPlugin