mkql_wide_stream_ut.cpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "mkql_computation_node_ut.h"
  2. #include <yql/essentials/minikql/computation/mkql_computation_node_holders.h>
  3. namespace NKikimr {
  4. namespace NMiniKQL {
  5. #if !defined(MKQL_RUNTIME_VERSION) || MKQL_RUNTIME_VERSION >= 36u
  6. Y_UNIT_TEST_SUITE(TMiniKQLWideStreamTest) {
  7. Y_UNIT_TEST_LLVM(TestSimple) {
  8. TSetup<LLVM> setup;
  9. TProgramBuilder& pb = *setup.PgmBuilder;
  10. const auto ui64Type = pb.NewDataType(NUdf::TDataType<ui64>::Id);
  11. const auto tupleType = pb.NewTupleType({ui64Type, ui64Type});
  12. const auto data1 = pb.NewTuple(tupleType, {pb.NewDataLiteral<ui64>(1), pb.NewDataLiteral<ui64>(10)});
  13. const auto data2 = pb.NewTuple(tupleType, {pb.NewDataLiteral<ui64>(2), pb.NewDataLiteral<ui64>(20)});
  14. const auto data3 = pb.NewTuple(tupleType, {pb.NewDataLiteral<ui64>(3), pb.NewDataLiteral<ui64>(30)});
  15. const auto list = pb.NewList(tupleType, {data1, data2, data3});
  16. const auto flow = pb.ToFlow(list);
  17. const auto wideFlow = pb.ExpandMap(flow, [&](TRuntimeNode item) -> TRuntimeNode::TList {
  18. return {pb.Nth(item, 0U), pb.Nth(item, 1U)};
  19. });
  20. const auto wideStream = pb.FromFlow(wideFlow);
  21. const auto newWideFlow = pb.ToFlow(wideStream);
  22. const auto narrowFlow = pb.NarrowMap(newWideFlow, [&](TRuntimeNode::TList items) -> TRuntimeNode {
  23. return pb.Sub(items[1], items[0]);
  24. });
  25. const auto pgmReturn = pb.Collect(narrowFlow);
  26. const auto graph = setup.BuildGraph(pgmReturn);
  27. const auto iterator = graph->GetValue().GetListIterator();
  28. NUdf::TUnboxedValue item;
  29. UNIT_ASSERT(iterator.Next(item));
  30. UNIT_ASSERT_VALUES_EQUAL(item.Get<ui64>(), 9);
  31. UNIT_ASSERT(iterator.Next(item));
  32. UNIT_ASSERT_VALUES_EQUAL(item.Get<ui64>(), 18);
  33. UNIT_ASSERT(iterator.Next(item));
  34. UNIT_ASSERT_VALUES_EQUAL(item.Get<ui64>(), 27);
  35. UNIT_ASSERT(!iterator.Next(item));
  36. UNIT_ASSERT(!iterator.Next(item));
  37. }
  38. }
  39. #endif
  40. }
  41. }