summaryrefslogtreecommitdiffstats
path: root/yql/essentials/minikql/comp_nodes/mkql_exists.cpp
blob: 82fd70f790c329b72b8692119e8560d184242623 (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
#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 {
        auto& context = ctx.Codegen.GetContext();
        const auto check = IsExists(value, block, context);
        if (Node_->IsTemporaryValue()) {
            ValueCleanup(Node_->GetRepresentation(), value, ctx, block);
        }
        return MakeBoolean(check, context, block);
    }
#endif
};

} // namespace

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

} // namespace NMiniKQL
} // namespace NKikimr