aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/comp_nodes/mkql_exists.cpp
blob: 9a90aa9546f1b728bbd3417a8d84f29197a778b5 (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
#include "mkql_exists.h"
#include <yql/essentials/minikql/computation/mkql_computation_node_codegen.h>  // Y_IGNORE
#include <yql/essentials/minikql/mkql_node_cast.h>

namespace NKikimr {
namespace NMiniKQL {

namespace {

class TExistsWrapper : public TDecoratorCodegeneratorNode<TExistsWrapper> {
    typedef TDecoratorCodegeneratorNode<TExistsWrapper> TBaseComputation;
public:
    TExistsWrapper(IComputationNode* optional)
        : TBaseComputation(optional)
    {}

    NUdf::TUnboxedValuePod DoCalculate(TComputationContext&, const NUdf::TUnboxedValuePod& value) const {
        return NUdf::TUnboxedValuePod(bool(value));
    }

#ifndef MKQL_DISABLE_CODEGEN
    Value* DoGenerateGetValue(const TCodegenContext& ctx, Value* value, BasicBlock*& block) const {
        const auto check = IsExists(value, block);
        if (Node->IsTemporaryValue())
            ValueCleanup(Node->GetRepresentation(), value, ctx, block);
        return MakeBoolean(check, ctx.Codegen.GetContext(), block);
    }
#endif
};

}

IComputationNode* WrapExists(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
    MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 arg");
    return new TExistsWrapper(LocateNode(ctx.NodeLocator, callable, 0));
}

}
}