object_processing.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "object_processing.h"
  2. #include <yql/essentials/core/sql_types/yql_callable_names.h>
  3. namespace NSQLTranslationV1 {
  4. using namespace NYql;
  5. INode::TPtr TObjectProcessorImpl::BuildKeys() const {
  6. auto keys = Y("Key");
  7. keys = L(keys, Q(Y(Q("objectId"), Y("String", BuildQuotedAtom(Pos, ObjectId)))));
  8. keys = L(keys, Q(Y(Q("typeId"), Y("String", BuildQuotedAtom(Pos, TypeId)))));
  9. return keys;
  10. }
  11. TObjectProcessorImpl::TObjectProcessorImpl(TPosition pos, const TString& objectId, const TString& typeId, const TObjectOperatorContext& context)
  12. : TBase(pos)
  13. , TObjectOperatorContext(context)
  14. , ObjectId(objectId)
  15. , TypeId(typeId)
  16. {
  17. }
  18. bool TObjectProcessorImpl::DoInit(TContext& ctx, ISource* src) {
  19. Y_UNUSED(src);
  20. Scoped->UseCluster(ServiceId, Cluster);
  21. auto options = FillFeatures(BuildOptions());
  22. auto keys = BuildKeys();
  23. Add("block", Q(Y(
  24. Y("let", "sink", Y("DataSink", BuildQuotedAtom(Pos, ServiceId), Scoped->WrapCluster(Cluster, ctx))),
  25. Y("let", "world", Y(TString(WriteName), "world", "sink", keys, Y("Void"), Q(options))),
  26. Y("return", ctx.PragmaAutoCommit ? Y(TString(CommitName), "world", "sink") : AstNode("world"))
  27. )));
  28. return TAstListNode::DoInit(ctx, src);
  29. }
  30. INode::TPtr TCreateObject::FillFeatures(INode::TPtr options) const {
  31. if (!Features.empty()) {
  32. auto features = Y();
  33. for (auto&& i : Features) {
  34. if (i.second.HasNode()) {
  35. features->Add(Q(Y(BuildQuotedAtom(Pos, i.first), i.second.Build())));
  36. } else {
  37. features->Add(Q(Y(BuildQuotedAtom(Pos, i.first))));
  38. }
  39. }
  40. options->Add(Q(Y(Q("features"), Q(features))));
  41. }
  42. if (!FeaturesToReset.empty()) {
  43. auto reset = Y();
  44. for (const auto& featureName : FeaturesToReset) {
  45. reset->Add(BuildQuotedAtom(Pos, featureName));
  46. }
  47. options->Add(Q(Y(Q("resetFeatures"), Q(reset))));
  48. }
  49. return options;
  50. }
  51. TObjectOperatorContext::TObjectOperatorContext(TScopedStatePtr scoped)
  52. : Scoped(scoped)
  53. , ServiceId(Scoped->CurrService)
  54. , Cluster(Scoped->CurrCluster)
  55. {
  56. }
  57. }