topfreq_udf_ut.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. #include <util/random/shuffle.h>
  2. #include <library/cpp/testing/unittest/registar.h>
  3. #include <yql/essentials/minikql/mkql_function_registry.h>
  4. #include <yql/essentials/minikql/mkql_program_builder.h>
  5. #include <yql/essentials/minikql/invoke_builtins/mkql_builtins.h>
  6. #include <yql/essentials/minikql/computation/mkql_computation_node.h>
  7. #include <yql/essentials/minikql/comp_nodes/mkql_factories.h>
  8. #include <util/random/random.h>
  9. #include <array>
  10. #include <yql/essentials/udfs/common/topfreq/static/topfreq_udf.h>
  11. namespace NYql {
  12. using namespace NKikimr::NMiniKQL;
  13. namespace NUdf {
  14. extern NUdf::TUniquePtr<NUdf::IUdfModule> CreateTopFreqModule();
  15. }
  16. class TSetup {
  17. public:
  18. TSetup()
  19. : MutableFunctionRegistry_(CreateFunctionRegistry(CreateBuiltinRegistry())->Clone())
  20. , RandomProvider_(CreateDeterministicRandomProvider(1))
  21. , TimeProvider_(CreateDeterministicTimeProvider(10000000))
  22. , Alloc_(__LOCATION__)
  23. , Env_(Alloc_)
  24. {
  25. MutableFunctionRegistry_->AddModule("", "TopFreq", NUdf::CreateTopFreqModule());
  26. PgmBuidler_.Reset(new TProgramBuilder(Env_, *MutableFunctionRegistry_));
  27. }
  28. TProgramBuilder& GetProgramBuilder() {
  29. return *PgmBuidler_.Get();
  30. }
  31. NUdf::TUnboxedValue GetValue(TRuntimeNode& node) {
  32. Explorer_.Walk(node.GetNode(), Env_);
  33. TComputationPatternOpts opts(Alloc_.Ref(), Env_, GetBuiltinFactory(),
  34. MutableFunctionRegistry_.Get(),
  35. NUdf::EValidateMode::None, NUdf::EValidatePolicy::Fail, "", EGraphPerProcess::Multi);
  36. Pattern_ = MakeComputationPattern(Explorer_, node, {}, opts);
  37. Graph_ = Pattern_->Clone(opts.ToComputationOptions(*RandomProvider_, *TimeProvider_));
  38. return Graph_->GetValue();
  39. }
  40. private:
  41. using IMutableFunctionRegistryPtr = TIntrusivePtr<IMutableFunctionRegistry>;
  42. using IRandomProviderPtr = TIntrusivePtr<IRandomProvider>;
  43. using ITimeProviderPtr = TIntrusivePtr<ITimeProvider>;
  44. IMutableFunctionRegistryPtr MutableFunctionRegistry_;
  45. IRandomProviderPtr RandomProvider_;
  46. ITimeProviderPtr TimeProvider_;
  47. TScopedAlloc Alloc_;
  48. TTypeEnvironment Env_;
  49. THolder<TProgramBuilder> PgmBuidler_;
  50. IComputationPattern::TPtr Pattern_;
  51. THolder<IComputationGraph> Graph_;
  52. TExploringNodeVisitor Explorer_;
  53. };
  54. Y_UNIT_TEST_SUITE(TUDFTopFreqTest) {
  55. Y_UNIT_TEST(SimpleTopFreq) {
  56. TSetup setup;
  57. TProgramBuilder& pgmBuilder = setup.GetProgramBuilder();
  58. const auto valueType = pgmBuilder.NewDataType(NUdf::TDataType<i32>::Id);
  59. const auto emptyStructType = pgmBuilder.NewEmptyStructType();
  60. const auto resourceType = pgmBuilder.NewResourceType("TopFreq.TopFreqResource.Int32");
  61. const auto ui32Type = pgmBuilder.NewDataType(NUdf::TDataType<ui32>::Id);
  62. const auto createArgsType = pgmBuilder.NewTupleType({valueType, ui32Type});
  63. const auto createUserType = pgmBuilder.NewTupleType({createArgsType, emptyStructType, valueType});
  64. auto udfTopFreq_Create = pgmBuilder.Udf("TopFreq.TopFreq_Create", TRuntimeNode(), createUserType);
  65. auto addValueArgsType = pgmBuilder.NewTupleType({resourceType, valueType});
  66. auto addValueUserType = pgmBuilder.NewTupleType({addValueArgsType, emptyStructType, valueType});
  67. auto udfTopFreq_AddValue = pgmBuilder.Udf("TopFreq.TopFreq_AddValue", TRuntimeNode(), addValueUserType);
  68. auto getArgsType = pgmBuilder.NewTupleType({resourceType, ui32Type});
  69. auto getUserType = pgmBuilder.NewTupleType({getArgsType, emptyStructType, valueType});
  70. auto udfTopFreq_Get = pgmBuilder.Udf("TopFreq.TopFreq_Get", TRuntimeNode(), getUserType);
  71. TRuntimeNode pgmTopFreq;
  72. {
  73. auto val = pgmBuilder.NewDataLiteral<i32>(3);
  74. auto param = pgmBuilder.NewDataLiteral<ui32>(10);
  75. TVector<TRuntimeNode> params = {val, param};
  76. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_Create, params);
  77. }
  78. for (int n = 0; n < 9; n++) {
  79. auto value = pgmBuilder.NewDataLiteral<i32>(1);
  80. TVector<TRuntimeNode> params = {pgmTopFreq, value};
  81. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  82. }
  83. for (int n = 0; n < 7; n++) {
  84. auto value = pgmBuilder.NewDataLiteral<i32>(4);
  85. TVector<TRuntimeNode> params = {pgmTopFreq, value};
  86. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  87. }
  88. TRuntimeNode pgmReturn;
  89. {
  90. auto param = pgmBuilder.NewDataLiteral<ui32>(4);
  91. TVector<TRuntimeNode> params = {pgmTopFreq, param};
  92. pgmReturn = pgmBuilder.Apply(udfTopFreq_Get, params);
  93. }
  94. auto value = setup.GetValue(pgmReturn);
  95. auto listIterator = value.GetListIterator();
  96. TUnboxedValue item;
  97. UNIT_ASSERT(listIterator.Next(item));
  98. UNIT_ASSERT_EQUAL(item.GetElement(1).Get<i32>(), 1);
  99. UNIT_ASSERT_EQUAL(item.GetElement(0).Get<ui64>(), 9);
  100. UNIT_ASSERT(listIterator.Next(item));
  101. UNIT_ASSERT_EQUAL(item.GetElement(1).Get<i32>(), 4);
  102. UNIT_ASSERT_EQUAL(item.GetElement(0).Get<ui64>(), 7);
  103. UNIT_ASSERT(listIterator.Next(item));
  104. UNIT_ASSERT_EQUAL(item.GetElement(1).Get<i32>(), 3);
  105. UNIT_ASSERT_EQUAL(item.GetElement(0).Get<ui64>(), 1);
  106. UNIT_ASSERT(!listIterator.Next(item));
  107. }
  108. Y_UNIT_TEST(MergingTopFreq) {
  109. TSetup setup;
  110. TProgramBuilder& pgmBuilder = setup.GetProgramBuilder();
  111. const auto valueType = pgmBuilder.NewDataType(NUdf::TDataType<ui64>::Id);
  112. const auto emptyStructType = pgmBuilder.NewEmptyStructType();
  113. const auto resourceType = pgmBuilder.NewResourceType("TopFreq.TopFreqResource.Uint64");
  114. const auto ui32Type = pgmBuilder.NewDataType(NUdf::TDataType<ui32>::Id);
  115. const auto createArgsType = pgmBuilder.NewTupleType({valueType, ui32Type});
  116. const auto createUserType = pgmBuilder.NewTupleType({createArgsType, emptyStructType, valueType});
  117. auto udfTopFreq_Create = pgmBuilder.Udf("TopFreq.TopFreq_Create", TRuntimeNode(), createUserType);
  118. auto addValueArgsType = pgmBuilder.NewTupleType({resourceType, valueType});
  119. auto addValueUserType = pgmBuilder.NewTupleType({addValueArgsType, emptyStructType, valueType});
  120. auto udfTopFreq_AddValue = pgmBuilder.Udf("TopFreq.TopFreq_AddValue", TRuntimeNode(), addValueUserType);
  121. auto mergeArgsType = pgmBuilder.NewTupleType({resourceType, resourceType});
  122. auto mergeUserType = pgmBuilder.NewTupleType({mergeArgsType, emptyStructType, valueType});
  123. auto udfTopFreq_Merge = pgmBuilder.Udf("TopFreq.TopFreq_Merge", TRuntimeNode(), mergeUserType);
  124. auto getArgsType = pgmBuilder.NewTupleType({resourceType, ui32Type});
  125. auto getUserType = pgmBuilder.NewTupleType({getArgsType, emptyStructType, valueType});
  126. auto udfTopFreq_Get = pgmBuilder.Udf("TopFreq.TopFreq_Get", TRuntimeNode(), getUserType);
  127. TRuntimeNode pgmTopFreq;
  128. {
  129. auto value = pgmBuilder.NewDataLiteral<ui64>(1);
  130. auto param = pgmBuilder.NewDataLiteral<ui32>(1);
  131. TVector<TRuntimeNode> params = {value, param};
  132. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_Create, params);
  133. }
  134. for (int n = 0; n < 1; n++) {
  135. auto value = pgmBuilder.NewDataLiteral<ui64>(1);
  136. TVector<TRuntimeNode> params = {pgmTopFreq, value};
  137. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  138. }
  139. for (int n = 0; n < 4; n++) {
  140. auto value = pgmBuilder.NewDataLiteral<ui64>(5);
  141. TVector<TRuntimeNode> params = {pgmTopFreq, value};
  142. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  143. }
  144. for (int n = 0; n < 1; n++) {
  145. auto value = pgmBuilder.NewDataLiteral<ui64>(3);
  146. TVector<TRuntimeNode> params = {pgmTopFreq, value};
  147. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  148. }
  149. TRuntimeNode pgmTopFreq2;
  150. {
  151. auto value = pgmBuilder.NewDataLiteral<ui64>(1);
  152. auto param = pgmBuilder.NewDataLiteral<ui32>(1);
  153. TVector<TRuntimeNode> params = {value, param};
  154. pgmTopFreq2 = pgmBuilder.Apply(udfTopFreq_Create, params);
  155. }
  156. for (int n = 0; n < 5; n++) {
  157. auto value = pgmBuilder.NewDataLiteral<ui64>(1);
  158. TVector<TRuntimeNode> params = {pgmTopFreq2, value};
  159. pgmTopFreq2 = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  160. }
  161. for (int n = 0; n < 5; n++) {
  162. auto value = pgmBuilder.NewDataLiteral<ui64>(5);
  163. TVector<TRuntimeNode> params = {pgmTopFreq2, value};
  164. pgmTopFreq2 = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  165. }
  166. TRuntimeNode pgmTopFreq3;
  167. {
  168. TVector<TRuntimeNode> params = {pgmTopFreq, pgmTopFreq2};
  169. pgmTopFreq3 = pgmBuilder.Apply(udfTopFreq_Merge, params);
  170. }
  171. TRuntimeNode pgmReturn;
  172. {
  173. auto param = pgmBuilder.NewDataLiteral<ui32>(1);
  174. TVector<TRuntimeNode> params = {pgmTopFreq3, param};
  175. pgmReturn = pgmBuilder.Apply(udfTopFreq_Get, params);
  176. }
  177. auto value = setup.GetValue(pgmReturn);
  178. auto listIterator = value.GetListIterator();
  179. TUnboxedValue item;
  180. UNIT_ASSERT(listIterator.Next(item));
  181. UNIT_ASSERT_EQUAL(item.GetElement(1).Get<ui64>(), 5);
  182. UNIT_ASSERT_EQUAL(item.GetElement(0).Get<ui64>(), 9);
  183. UNIT_ASSERT(!listIterator.Next(item));
  184. }
  185. Y_UNIT_TEST(SerializedTopFreq) {
  186. TSetup setup;
  187. TProgramBuilder& pgmBuilder = setup.GetProgramBuilder();
  188. const auto valueType = pgmBuilder.NewDataType(NUdf::TDataType<bool>::Id);
  189. const auto emptyStructType = pgmBuilder.NewEmptyStructType();
  190. const auto resourceType = pgmBuilder.NewResourceType("TopFreq.TopFreqResource.Bool");
  191. const auto ui32Type = pgmBuilder.NewDataType(NUdf::TDataType<ui32>::Id);
  192. const auto ui64Type = pgmBuilder.NewDataType(NUdf::TDataType<ui64>::Id);
  193. const auto createArgsType = pgmBuilder.NewTupleType({valueType, ui32Type});
  194. const auto createUserType = pgmBuilder.NewTupleType({createArgsType, emptyStructType, valueType});
  195. auto udfTopFreq_Create = pgmBuilder.Udf("TopFreq.TopFreq_Create", TRuntimeNode(), createUserType);
  196. auto addValueArgsType = pgmBuilder.NewTupleType({resourceType, valueType});
  197. auto addValueUserType = pgmBuilder.NewTupleType({addValueArgsType, emptyStructType, valueType});
  198. auto udfTopFreq_AddValue = pgmBuilder.Udf("TopFreq.TopFreq_AddValue", TRuntimeNode(), addValueUserType);
  199. auto getArgsType = pgmBuilder.NewTupleType({resourceType, ui32Type});
  200. auto getUserType = pgmBuilder.NewTupleType({getArgsType, emptyStructType, valueType});
  201. auto udfTopFreq_Get = pgmBuilder.Udf("TopFreq.TopFreq_Get", TRuntimeNode(), getUserType);
  202. auto serializeArgsType = pgmBuilder.NewTupleType({resourceType});
  203. auto serializeUserType = pgmBuilder.NewTupleType({serializeArgsType, emptyStructType, valueType});
  204. auto udfTopFreq_Serialize = pgmBuilder.Udf("TopFreq.TopFreq_Serialize", TRuntimeNode(), serializeUserType);
  205. auto serializedType = pgmBuilder.NewTupleType({ui32Type, ui32Type,
  206. pgmBuilder.NewListType(pgmBuilder.NewTupleType({ui64Type, valueType}))});
  207. auto deserializeArgsType = pgmBuilder.NewTupleType({serializedType});
  208. auto deserializeUserType = pgmBuilder.NewTupleType({deserializeArgsType, emptyStructType, valueType});
  209. auto udfTopFreq_Deserialize = pgmBuilder.Udf("TopFreq.TopFreq_Deserialize", TRuntimeNode(), deserializeUserType);
  210. TRuntimeNode pgmTopFreq;
  211. {
  212. auto value = pgmBuilder.NewDataLiteral<bool>(true);
  213. auto param = pgmBuilder.NewDataLiteral<ui32>(10);
  214. TVector<TRuntimeNode> params = {value, param};
  215. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_Create, params);
  216. }
  217. for (int n = 0; n < 7; n++) {
  218. auto value = pgmBuilder.NewDataLiteral<bool>(true);
  219. TVector<TRuntimeNode> params = {pgmTopFreq, value};
  220. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  221. }
  222. for (int n = 0; n < 10; n++) {
  223. auto value = pgmBuilder.NewDataLiteral<bool>(false);
  224. TVector<TRuntimeNode> params = {pgmTopFreq, value};
  225. pgmTopFreq = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  226. }
  227. TRuntimeNode pgmSerializedTopFreq;
  228. {
  229. TVector<TRuntimeNode> params = {pgmTopFreq};
  230. pgmSerializedTopFreq = pgmBuilder.Apply(udfTopFreq_Serialize, params);
  231. }
  232. TRuntimeNode pgmDeserializedTopFreq;
  233. {
  234. TVector<TRuntimeNode> params = {pgmSerializedTopFreq};
  235. pgmDeserializedTopFreq = pgmBuilder.Apply(udfTopFreq_Deserialize, params);
  236. }
  237. TRuntimeNode pgmReturn;
  238. {
  239. auto param = pgmBuilder.NewDataLiteral<ui32>(3);
  240. TVector<TRuntimeNode> params = {pgmDeserializedTopFreq, param};
  241. pgmReturn = pgmBuilder.Apply(udfTopFreq_Get, params);
  242. }
  243. auto value = setup.GetValue(pgmReturn);
  244. auto listIterator = value.GetListIterator();
  245. TUnboxedValue item;
  246. UNIT_ASSERT(listIterator.Next(item));
  247. UNIT_ASSERT_EQUAL(item.GetElement(1).Get<bool>(), false);
  248. UNIT_ASSERT_EQUAL(item.GetElement(0).Get<ui64>(), 10);
  249. UNIT_ASSERT(listIterator.Next(item));
  250. UNIT_ASSERT_EQUAL(item.GetElement(1).Get<bool>(), true);
  251. UNIT_ASSERT_EQUAL(item.GetElement(0).Get<ui64>(), 8);
  252. UNIT_ASSERT(!listIterator.Next(item));
  253. }
  254. Y_UNIT_TEST(ApproxTopFreq) {
  255. TSetup setup;
  256. TProgramBuilder& pgmBuilder = setup.GetProgramBuilder();
  257. const auto valueType = pgmBuilder.NewDataType(NUdf::TDataType<ui64>::Id);
  258. const auto emptyStructType = pgmBuilder.NewEmptyStructType();
  259. const auto resourceType = pgmBuilder.NewResourceType("TopFreq.TopFreqResource.Uint64");
  260. const auto ui32Type = pgmBuilder.NewDataType(NUdf::TDataType<ui32>::Id);
  261. const auto ui64Type = pgmBuilder.NewDataType(NUdf::TDataType<ui64>::Id);
  262. const auto createArgsType = pgmBuilder.NewTupleType({valueType, ui32Type});
  263. const auto createUserType = pgmBuilder.NewTupleType({createArgsType, emptyStructType, valueType});
  264. auto udfTopFreq_Create = pgmBuilder.Udf("TopFreq.TopFreq_Create", TRuntimeNode(), createUserType);
  265. auto addValueArgsType = pgmBuilder.NewTupleType({resourceType, valueType});
  266. auto addValueUserType = pgmBuilder.NewTupleType({addValueArgsType, emptyStructType, valueType});
  267. auto udfTopFreq_AddValue = pgmBuilder.Udf("TopFreq.TopFreq_AddValue", TRuntimeNode(), addValueUserType);
  268. auto mergeArgsType = pgmBuilder.NewTupleType({resourceType, resourceType});
  269. auto mergeUserType = pgmBuilder.NewTupleType({mergeArgsType, emptyStructType, valueType});
  270. auto udfTopFreq_Merge = pgmBuilder.Udf("TopFreq.TopFreq_Merge", TRuntimeNode(), mergeUserType);
  271. auto getArgsType = pgmBuilder.NewTupleType({resourceType, ui32Type});
  272. auto getUserType = pgmBuilder.NewTupleType({getArgsType, emptyStructType, valueType});
  273. auto udfTopFreq_Get = pgmBuilder.Udf("TopFreq.TopFreq_Get", TRuntimeNode(), getUserType);
  274. auto serializeArgsType = pgmBuilder.NewTupleType({resourceType});
  275. auto serializeUserType = pgmBuilder.NewTupleType({serializeArgsType, emptyStructType, valueType});
  276. auto udfTopFreq_Serialize = pgmBuilder.Udf("TopFreq.TopFreq_Serialize", TRuntimeNode(), serializeUserType);
  277. auto serializedType = pgmBuilder.NewTupleType({ui32Type, ui32Type,
  278. pgmBuilder.NewListType(pgmBuilder.NewTupleType({ui64Type, valueType}))});
  279. auto deserializeArgsType = pgmBuilder.NewTupleType({serializedType});
  280. auto deserializeUserType = pgmBuilder.NewTupleType({deserializeArgsType, emptyStructType, valueType});
  281. auto udfTopFreq_Deserialize = pgmBuilder.Udf("TopFreq.TopFreq_Deserialize", TRuntimeNode(), deserializeUserType);
  282. static const ui64 BigNum = 20;
  283. static const ui64 BigEach = 5000;
  284. static const ui64 SmallNum = 500;
  285. static const ui64 SmallEach = 20;
  286. static const ui64 Total = BigNum * BigEach + SmallNum * SmallEach;
  287. static const i32 AskFor = 25;
  288. static const ui64 BlockSize = 200;
  289. static const ui64 BlockCount = 10;
  290. static const i32 WorksIfAtLeast = 15;
  291. std::array<ui64, Total> values;
  292. std::array<TRuntimeNode, BlockCount> pgmTopFreqs;
  293. i32 curIndex = 0;
  294. for (ui64 i = 1; i <= BigNum; i++) {
  295. for (ui64 j = 0; j < BigEach; j++) {
  296. values[curIndex++] = i;
  297. }
  298. }
  299. for (ui64 i = BigNum + 1; i <= BigNum + SmallNum; i++) {
  300. for (ui64 j = 0; j < SmallEach; j++) {
  301. values[curIndex++] = i;
  302. }
  303. }
  304. Shuffle(values.begin(), values.end());
  305. TVector<TRuntimeNode> params;
  306. TRuntimeNode param;
  307. TRuntimeNode pgmvalue;
  308. for (ui64 i = 0; i < BlockCount; i++) {
  309. {
  310. pgmvalue = pgmBuilder.NewDataLiteral<ui64>(values[i * BlockSize]);
  311. param = pgmBuilder.NewDataLiteral<ui32>(AskFor);
  312. params = {pgmvalue, param};
  313. pgmTopFreqs[i] = pgmBuilder.Apply(udfTopFreq_Create, params);
  314. }
  315. for (ui64 j = i * BlockSize + 1; j < (i + 1) * BlockSize; j++) {
  316. pgmvalue = pgmBuilder.NewDataLiteral<ui64>(values[j]);
  317. params = {pgmTopFreqs[i], pgmvalue};
  318. pgmTopFreqs[i] = pgmBuilder.Apply(udfTopFreq_AddValue, params);
  319. }
  320. {
  321. params = {pgmTopFreqs[i]};
  322. pgmTopFreqs[i] = pgmBuilder.Apply(udfTopFreq_Serialize, params);
  323. }
  324. }
  325. TRuntimeNode pgmMainTopFreq;
  326. {
  327. pgmvalue = pgmBuilder.NewDataLiteral<ui64>(Total + 2);
  328. param = pgmBuilder.NewDataLiteral<ui32>(AskFor);
  329. params = {pgmvalue, param};
  330. pgmMainTopFreq = pgmBuilder.Apply(udfTopFreq_Create, params);
  331. }
  332. for (ui64 i = 0; i < BlockCount; i++) {
  333. params = {pgmTopFreqs[i]};
  334. pgmTopFreqs[i] = pgmBuilder.Apply(udfTopFreq_Deserialize, params);
  335. params = {pgmMainTopFreq, pgmTopFreqs[i]};
  336. pgmMainTopFreq = pgmBuilder.Apply(udfTopFreq_Merge, params);
  337. }
  338. TRuntimeNode pgmReturn;
  339. {
  340. param = pgmBuilder.NewDataLiteral<ui32>(AskFor);
  341. params = {pgmMainTopFreq, param};
  342. pgmReturn = pgmBuilder.Apply(udfTopFreq_Get, params);
  343. }
  344. auto value = setup.GetValue(pgmReturn);
  345. auto listIterator = value.GetListIterator();
  346. ui32 found = 0;
  347. for (ui64 i = 0; i < AskFor; i++) {
  348. TUnboxedValue item;
  349. UNIT_ASSERT(listIterator.Next(item));
  350. ui64 current = item.GetElement(1).Get<ui64>();
  351. if (current <= BigNum)
  352. found++;
  353. }
  354. UNIT_ASSERT(!listIterator.Skip());
  355. UNIT_ASSERT(found >= WorksIfAtLeast);
  356. }
  357. }
  358. }