mkql_exists.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #include "mkql_exists.h"
  2. #include <yql/essentials/minikql/computation/mkql_computation_node_codegen.h> // Y_IGNORE
  3. #include <yql/essentials/minikql/mkql_node_cast.h>
  4. namespace NKikimr {
  5. namespace NMiniKQL {
  6. namespace {
  7. class TExistsWrapper : public TDecoratorCodegeneratorNode<TExistsWrapper> {
  8. typedef TDecoratorCodegeneratorNode<TExistsWrapper> TBaseComputation;
  9. public:
  10. TExistsWrapper(IComputationNode* optional)
  11. : TBaseComputation(optional)
  12. {}
  13. NUdf::TUnboxedValuePod DoCalculate(TComputationContext&, const NUdf::TUnboxedValuePod& value) const {
  14. return NUdf::TUnboxedValuePod(bool(value));
  15. }
  16. #ifndef MKQL_DISABLE_CODEGEN
  17. Value* DoGenerateGetValue(const TCodegenContext& ctx, Value* value, BasicBlock*& block) const {
  18. auto& context = ctx.Codegen.GetContext();
  19. const auto check = IsExists(value, block, context);
  20. if (Node->IsTemporaryValue())
  21. ValueCleanup(Node->GetRepresentation(), value, ctx, block);
  22. return MakeBoolean(check, context, block);
  23. }
  24. #endif
  25. };
  26. }
  27. IComputationNode* WrapExists(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
  28. MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 arg");
  29. return new TExistsWrapper(LocateNode(ctx.NodeLocator, callable, 0));
  30. }
  31. }
  32. }