mkql_exists.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. const auto check = IsExists(value, block);
  19. if (Node->IsTemporaryValue())
  20. ValueCleanup(Node->GetRepresentation(), value, ctx, block);
  21. return MakeBoolean(check, ctx.Codegen.GetContext(), block);
  22. }
  23. #endif
  24. };
  25. }
  26. IComputationNode* WrapExists(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
  27. MKQL_ENSURE(callable.GetInputsCount() == 1, "Expected 1 arg");
  28. return new TExistsWrapper(LocateNode(ctx.NodeLocator, callable, 0));
  29. }
  30. }
  31. }