mkql_seq.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "mkql_seq.h"
  2. #include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>
  3. namespace NKikimr {
  4. namespace NMiniKQL {
  5. namespace {
  6. class TSeqWrapper : public TMutableComputationNode<TSeqWrapper> {
  7. typedef TMutableComputationNode<TSeqWrapper> TBaseComputation;
  8. public:
  9. TSeqWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& args)
  10. : TBaseComputation(mutables)
  11. , Args(std::move(args))
  12. {}
  13. NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
  14. for (size_t i = 0; i + 1 < Args.size(); ++i) {
  15. Args[i]->GetValue(ctx);
  16. }
  17. auto value = Args.back()->GetValue(ctx);
  18. return value.Release();
  19. }
  20. private:
  21. void RegisterDependencies() const final {
  22. std::for_each(Args.cbegin(), Args.cend(), std::bind(&TSeqWrapper::DependsOn, this, std::placeholders::_1));
  23. }
  24. const TComputationNodePtrVector Args;
  25. };
  26. }
  27. IComputationNode* WrapSeq(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
  28. MKQL_ENSURE(callable.GetInputsCount() >= 1, "Seq: Expected at least one argument");
  29. TComputationNodePtrVector args;
  30. args.reserve(callable.GetInputsCount());
  31. for (ui32 i = 0; i < callable.GetInputsCount(); ++i) {
  32. args.push_back(LocateNode(ctx.NodeLocator, callable, i));
  33. }
  34. return new TSeqWrapper(ctx.Mutables, std::move(args));
  35. }
  36. }
  37. }