raw_requests.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #pragma once
  2. #include "raw_batch_request.h"
  3. #include <yt/cpp/mapreduce/common/fwd.h>
  4. #include <yt/cpp/mapreduce/http/context.h>
  5. #include <yt/cpp/mapreduce/interface/client.h>
  6. #include <yt/cpp/mapreduce/interface/client_method_options.h>
  7. #include <yt/cpp/mapreduce/interface/operation.h>
  8. #include <yt/cpp/mapreduce/interface/raw_client.h>
  9. namespace NYT {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. class IRequestRetryPolicy;
  12. struct TClientContext;
  13. struct TExecuteBatchOptions;
  14. ////////////////////////////////////////////////////////////////////////////////
  15. namespace NDetail::NRawClient {
  16. ////////////////////////////////////////////////////////////////////////////////
  17. TOperationAttributes ParseOperationAttributes(const TNode& node);
  18. TJobAttributes ParseJobAttributes(const TNode& node);
  19. TCheckPermissionResponse ParseCheckPermissionResponse(const TNode& node);
  20. ////////////////////////////////////////////////////////////////////////////////
  21. TRichYPath CanonizeYPath(
  22. const IRawClientPtr& rawClient,
  23. const TRichYPath& path);
  24. TVector<TRichYPath> CanonizeYPaths(
  25. const IRawClientPtr& rawClient,
  26. const TVector<TRichYPath>& paths);
  27. NHttpClient::IHttpResponsePtr SkyShareTable(
  28. const TClientContext& context,
  29. const std::vector<TYPath>& tablePaths,
  30. const TSkyShareTableOptions& options);
  31. void InsertRows(
  32. const TClientContext& context,
  33. const TYPath& path,
  34. const TNode::TListType& rows,
  35. const TInsertRowsOptions& options);
  36. TNode::TListType LookupRows(
  37. const TClientContext& context,
  38. const TYPath& path,
  39. const TNode::TListType& keys,
  40. const TLookupRowsOptions& options);
  41. void DeleteRows(
  42. const TClientContext& context,
  43. const TYPath& path,
  44. const TNode::TListType& keys,
  45. const TDeleteRowsOptions& options);
  46. TAuthorizationInfo WhoAmI(const TClientContext& context);
  47. ////////////////////////////////////////////////////////////////////////////////
  48. template<typename TSrc, typename TBatchAdder>
  49. auto BatchTransform(
  50. const IRawClientPtr& rawClient,
  51. const TSrc& src,
  52. TBatchAdder batchAdder,
  53. const TExecuteBatchOptions& executeBatchOptions = {})
  54. {
  55. auto batch = rawClient->CreateRawBatchRequest();
  56. using TFuture = decltype(batchAdder(batch, *std::begin(src)));
  57. TVector<TFuture> futures;
  58. for (const auto& el : src) {
  59. futures.push_back(batchAdder(batch, el));
  60. }
  61. batch->ExecuteBatch(executeBatchOptions);
  62. using TDst = decltype(futures[0].ExtractValueSync());
  63. TVector<TDst> result;
  64. result.reserve(std::size(src));
  65. for (auto& future : futures) {
  66. result.push_back(future.ExtractValueSync());
  67. }
  68. return result;
  69. }
  70. ////////////////////////////////////////////////////////////////////////////////
  71. } // namespace NDetail::NRawClient
  72. } // namespace NYT