plugin.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. TString MRJobBinary = "./mrjob";
  18. TString UdfDirectory;
  19. //! Mapping cluster name -> proxy address.
  20. THashMap<TString, TString> Clusters;
  21. std::optional<TString> DefaultCluster;
  22. TYsonString OperationAttributes;
  23. int MaxFilesSizeMb;
  24. int MaxFileCount;
  25. int DownloadFileRetryCount;
  26. TString YTTokenPath;
  27. THolder<TLogBackend> LogBackend;
  28. std::optional<TString> YqlPluginSharedLibrary;
  29. };
  30. struct TQueryResult
  31. {
  32. std::optional<TString> YsonResult;
  33. std::optional<TString> Plan;
  34. std::optional<TString> Statistics;
  35. std::optional<TString> Progress;
  36. std::optional<TString> TaskInfo;
  37. //! YSON representation of a YT error.
  38. std::optional<TString> YsonError;
  39. };
  40. struct TQueryFile
  41. {
  42. TStringBuf Name;
  43. TStringBuf Content;
  44. EQueryFileContentType Type;
  45. };
  46. //! This interface encapsulates YT <-> YQL integration.
  47. //! There are two major implementation: one of them is based
  48. //! on YQL code and another wraps the pure C bridge interface, which
  49. //! is implemented by a dynamic library.
  50. /*!
  51. * \note Thread affinity: any
  52. */
  53. struct IYqlPlugin
  54. {
  55. virtual TQueryResult Run(TQueryId queryId, TString impersonationUser, TString queryText, TYsonString settings, std::vector<TQueryFile> files) noexcept = 0;
  56. virtual TQueryResult GetProgress(TQueryId queryId) noexcept = 0;
  57. virtual ~IYqlPlugin() = default;
  58. };
  59. ////////////////////////////////////////////////////////////////////////////////
  60. Y_WEAK std::unique_ptr<IYqlPlugin> CreateYqlPlugin(TYqlPluginOptions& options) noexcept;
  61. ////////////////////////////////////////////////////////////////////////////////
  62. } // namespace NYT::NYqlPlugin