mkql_lookup.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "mkql_lookup.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 TLookupWrapper : public TMutableCodegeneratorPtrNode<TLookupWrapper> {
  8. typedef TMutableCodegeneratorPtrNode<TLookupWrapper> TBaseComputation;
  9. public:
  10. TLookupWrapper(TComputationMutables& mutables, EValueRepresentation kind, IComputationNode* dict, IComputationNode* key)
  11. : TBaseComputation(mutables, kind)
  12. , Dict(dict)
  13. , Key(key)
  14. {
  15. }
  16. NUdf::TUnboxedValue DoCalculate(TComputationContext& ctx) const {
  17. return Dict->GetValue(ctx).Lookup(Key->GetValue(ctx));
  18. }
  19. #ifndef MKQL_DISABLE_CODEGEN
  20. void DoGenerateGetValue(const TCodegenContext& ctx, Value* pointer, BasicBlock*& block) const {
  21. const auto dict = GetNodeValue(Dict, ctx, block);
  22. GetNodeValue(pointer, Key, ctx, block);
  23. const auto keyp = new LoadInst(Type::getInt128Ty(ctx.Codegen.GetContext()), pointer, "key", block);
  24. CallBoxedValueVirtualMethod<NUdf::TBoxedValueAccessor::EMethod::Lookup>(pointer, dict, ctx.Codegen, block, pointer);
  25. ValueUnRef(Key->GetRepresentation(), keyp, ctx, block);
  26. if (Dict->IsTemporaryValue())
  27. CleanupBoxed(dict, ctx, block);
  28. }
  29. #endif
  30. private:
  31. void RegisterDependencies() const final {
  32. DependsOn(Dict);
  33. DependsOn(Key);
  34. }
  35. IComputationNode* const Dict;
  36. IComputationNode* const Key;
  37. };
  38. }
  39. IComputationNode* WrapLookup(TCallable& callable, const TComputationNodeFactoryContext& ctx) {
  40. MKQL_ENSURE(callable.GetInputsCount() == 2, "Expected 2 args");
  41. const auto dict = LocateNode(ctx.NodeLocator, callable, 0);
  42. const auto key = LocateNode(ctx.NodeLocator, callable, 1);
  43. return new TLookupWrapper(ctx.Mutables, GetValueRepresentation(callable.GetType()->GetReturnType()), dict, key);
  44. }
  45. }
  46. }