#include "mkql_exists.h" #include // Y_IGNORE #include namespace NKikimr { namespace NMiniKQL { namespace { class TExistsWrapper : public TDecoratorCodegeneratorNode { typedef TDecoratorCodegeneratorNode 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 }; } IComputationNode* WrapExists(TCallable& callable, const TComputationNodeFactoryContext& ctx) { MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 arg"); return new TExistsWrapper(LocateNode(ctx.NodeLocator, callable, 0)); } } }