aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/comp_nodes/mkql_seq.cpp
blob: 1203099d6ff68f666570e7009b9934fc39085f0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include "mkql_seq.h"

#include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>

namespace NKikimr {
namespace NMiniKQL {

namespace {

class TSeqWrapper : public TMutableComputationNode<TSeqWrapper> {
    typedef TMutableComputationNode<TSeqWrapper> TBaseComputation;
public:
    TSeqWrapper(TComputationMutables& mutables, TComputationNodePtrVector&& args)
        : TBaseComputation(mutables)
        , Args(std::move(args))
    {}

    NUdf::TUnboxedValuePod DoCalculate(TComputationContext& ctx) const {
        for (size_t i = 0; i + 1 < Args.size(); ++i) {
            Args[i]->GetValue(ctx);
        }

        auto value = Args.back()->GetValue(ctx);
        return value.Release();
    }

private:
    void RegisterDependencies() const final {
        std::for_each(Args.cbegin(), Args.cend(), std::bind(&TSeqWrapper::DependsOn, this, std::placeholders::_1));
    }

    const TComputationNodePtrVector Args;
};

}

IComputationNode* WrapSeq(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
    MKQL_ENSURE(callable.GetInputsCount() >= 1, "Seq: Expected at least one argument");

    TComputationNodePtrVector args;
    args.reserve(callable.GetInputsCount());
    for (ui32 i = 0; i < callable.GetInputsCount(); ++i) {
        args.push_back(LocateNode(ctx.NodeLocator, callable, i));
    }

    return new TSeqWrapper(ctx.Mutables, std::move(args));
}

}
}