mkql_decimal_ut.cpp 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321
  1. #include "mkql_computation_node_ut.h"
  2. #include <yql/essentials/minikql/mkql_node_cast.h>
  3. #include <yql/essentials/minikql/mkql_string_util.h>
  4. namespace NKikimr {
  5. namespace NMiniKQL {
  6. Y_UNIT_TEST_SUITE(TMiniKQLDecimalTest) {
  7. Y_UNIT_TEST_LLVM(TestNanvl) {
  8. TSetup<LLVM> setup;
  9. TProgramBuilder& pb = *setup.PgmBuilder;
  10. const auto type = pb.NewOptionalType(pb.NewDecimalType(13, 5));
  11. const auto data0 = pb.NewOptional(pb.NewDecimalLiteral(0, 13, 5));
  12. const auto data1 = pb.NewOptional(pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 13, 5));
  13. const auto data2 = pb.NewOptional(pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 13, 5));
  14. const auto data3 = pb.NewOptional(pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 13, 5));
  15. const auto data4 = pb.NewEmptyOptional(type);
  16. const auto data = pb.NewDecimalLiteral(314159, 13, 5);
  17. const auto list = pb.NewList(type, {data0, data1, data2, data3, data4});
  18. const auto pgmReturn = pb.Map(list,
  19. [&](TRuntimeNode item) {
  20. return pb.Nanvl(item, data);
  21. });
  22. const auto graph = setup.BuildGraph(pgmReturn);
  23. const auto iterator = graph->GetValue().GetListIterator();
  24. NUdf::TUnboxedValue item;
  25. UNIT_ASSERT(iterator.Next(item));
  26. UNIT_ASSERT(item.GetInt128() == 0);
  27. UNIT_ASSERT(iterator.Next(item));
  28. UNIT_ASSERT(item.GetInt128() == 314159);
  29. UNIT_ASSERT(iterator.Next(item));
  30. UNIT_ASSERT(item.GetInt128() == +NYql::NDecimal::Inf());
  31. UNIT_ASSERT(iterator.Next(item));
  32. UNIT_ASSERT(item.GetInt128() == -NYql::NDecimal::Inf());
  33. UNIT_ASSERT(iterator.Next(item));
  34. UNIT_ASSERT(!item);
  35. UNIT_ASSERT(!iterator.Next(item));
  36. UNIT_ASSERT(!iterator.Next(item));
  37. }
  38. Y_UNIT_TEST_LLVM(TestToIntegral) {
  39. TSetup<LLVM> setup;
  40. TProgramBuilder& pb = *setup.PgmBuilder;
  41. const auto type = pb.NewDecimalType(13, 1);
  42. const auto data0 = pb.NewDecimalLiteral(0, 13, 1);
  43. const auto data1 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 13, 1);
  44. const auto data2 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 13, 1);
  45. const auto data3 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 13, 1);
  46. const auto data4 = pb.NewDecimalLiteral(1270, 13, 1);
  47. const auto data5 = pb.NewDecimalLiteral(-1280, 13, 1);
  48. const auto data6 = pb.NewDecimalLiteral(2550, 13, 1);
  49. const auto data7 = pb.NewDecimalLiteral(-2560, 13, 1);
  50. const auto data8 = pb.NewDecimalLiteral(2560, 13, 1);
  51. const auto data9 = pb.NewDecimalLiteral(-2570, 13, 1);
  52. const auto dataA = pb.NewDecimalLiteral(327670, 13, 1);
  53. const auto dataB = pb.NewDecimalLiteral(-327680, 13, 1);
  54. const auto dataC = pb.NewDecimalLiteral(655350, 13, 1);
  55. const auto dataD = pb.NewDecimalLiteral(-655360, 13, 1);
  56. const auto dataE = pb.NewDecimalLiteral(21474836470, 13, 1);
  57. const auto dataF = pb.NewDecimalLiteral(-21474836480, 13, 1);
  58. const auto dataG = pb.NewDecimalLiteral(21474836480, 13, 1);
  59. const auto dataH = pb.NewDecimalLiteral(-21474836490, 13, 1);
  60. const auto list = pb.NewList(type, {data0, data1, data2, data3, data4, data5, data6, data7, data8, data9, dataA, dataB, dataC, dataD, dataE, dataF, dataG, dataH});
  61. const auto pgmReturn = pb.Map(list,
  62. [&](TRuntimeNode item) {
  63. return pb.NewTuple({
  64. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<i8>::Id, true)),
  65. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<ui8>::Id, true)),
  66. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<i16>::Id, true)),
  67. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<ui16>::Id, true)),
  68. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<i32>::Id, true)),
  69. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<ui32>::Id, true)),
  70. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<i64>::Id, true)),
  71. pb.ToIntegral(item, pb.NewDataType(NUdf::TDataType<ui64>::Id, true))
  72. });
  73. });
  74. const auto graph = setup.BuildGraph(pgmReturn);
  75. const auto iterator = graph->GetValue().GetListIterator();
  76. NUdf::TUnboxedValue item;
  77. UNIT_ASSERT(iterator.Next(item));
  78. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[0].Get<i8>(), 0);
  79. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[1].Get<ui8>(), 0);
  80. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), 0);
  81. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[3].Get<ui16>(), 0);
  82. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), 0);
  83. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 0);
  84. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 0);
  85. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 0);
  86. UNIT_ASSERT(iterator.Next(item));
  87. UNIT_ASSERT(!item.GetElements()[0]);
  88. UNIT_ASSERT(!item.GetElements()[1]);
  89. UNIT_ASSERT(!item.GetElements()[2]);
  90. UNIT_ASSERT(!item.GetElements()[3]);
  91. UNIT_ASSERT(!item.GetElements()[4]);
  92. UNIT_ASSERT(!item.GetElements()[5]);
  93. UNIT_ASSERT(!item.GetElements()[6]);
  94. UNIT_ASSERT(!item.GetElements()[7]);
  95. UNIT_ASSERT(iterator.Next(item));
  96. UNIT_ASSERT(!item.GetElements()[0]);
  97. UNIT_ASSERT(!item.GetElements()[1]);
  98. UNIT_ASSERT(!item.GetElements()[2]);
  99. UNIT_ASSERT(!item.GetElements()[3]);
  100. UNIT_ASSERT(!item.GetElements()[4]);
  101. UNIT_ASSERT(!item.GetElements()[5]);
  102. UNIT_ASSERT(!item.GetElements()[6]);
  103. UNIT_ASSERT(!item.GetElements()[7]);
  104. UNIT_ASSERT(iterator.Next(item));
  105. UNIT_ASSERT(!item.GetElements()[0]);
  106. UNIT_ASSERT(!item.GetElements()[1]);
  107. UNIT_ASSERT(!item.GetElements()[2]);
  108. UNIT_ASSERT(!item.GetElements()[3]);
  109. UNIT_ASSERT(!item.GetElements()[4]);
  110. UNIT_ASSERT(!item.GetElements()[5]);
  111. UNIT_ASSERT(!item.GetElements()[6]);
  112. UNIT_ASSERT(!item.GetElements()[7]);
  113. UNIT_ASSERT(iterator.Next(item));
  114. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[0].Get<i8>(), 127);
  115. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[1].Get<ui8>(), 127);
  116. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), 127);
  117. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[3].Get<ui16>(), 127);
  118. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), 127);
  119. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 127);
  120. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 127);
  121. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 127);
  122. UNIT_ASSERT(iterator.Next(item));
  123. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[0].Get<i8>(), -128);
  124. UNIT_ASSERT(!item.GetElements()[1]);
  125. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), -128);
  126. UNIT_ASSERT(!item.GetElements()[3]);
  127. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), -128);
  128. UNIT_ASSERT(!item.GetElements()[5]);
  129. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), -128);
  130. UNIT_ASSERT(!item.GetElements()[7]);
  131. UNIT_ASSERT(iterator.Next(item));
  132. UNIT_ASSERT(!item.GetElements()[0]);
  133. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[1].Get<ui8>(), 255);
  134. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), 255);
  135. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[3].Get<ui16>(), 255);
  136. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), 255);
  137. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 255);
  138. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 255);
  139. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 255);
  140. UNIT_ASSERT(iterator.Next(item));
  141. UNIT_ASSERT(!item.GetElements()[0]);
  142. UNIT_ASSERT(!item.GetElements()[1]);
  143. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), -256);
  144. UNIT_ASSERT(!item.GetElements()[3]);
  145. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), -256);
  146. UNIT_ASSERT(!item.GetElements()[5]);
  147. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), -256);
  148. UNIT_ASSERT(!item.GetElements()[7]);
  149. UNIT_ASSERT(iterator.Next(item));
  150. UNIT_ASSERT(!item.GetElements()[0]);
  151. UNIT_ASSERT(!item.GetElements()[1]);
  152. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), 256);
  153. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[3].Get<ui16>(), 256);
  154. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), 256);
  155. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 256);
  156. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 256);
  157. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 256);
  158. UNIT_ASSERT(iterator.Next(item));
  159. UNIT_ASSERT(!item.GetElements()[0]);
  160. UNIT_ASSERT(!item.GetElements()[1]);
  161. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), -257);
  162. UNIT_ASSERT(!item.GetElements()[3]);
  163. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), -257);
  164. UNIT_ASSERT(!item.GetElements()[5]);
  165. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), -257);
  166. UNIT_ASSERT(!item.GetElements()[7]);
  167. UNIT_ASSERT(iterator.Next(item));
  168. UNIT_ASSERT(!item.GetElements()[0]);
  169. UNIT_ASSERT(!item.GetElements()[1]);
  170. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), 32767);
  171. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[3].Get<ui16>(), 32767);
  172. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), 32767);
  173. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 32767);
  174. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 32767);
  175. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 32767);
  176. UNIT_ASSERT(iterator.Next(item));
  177. UNIT_ASSERT(!item.GetElements()[0]);
  178. UNIT_ASSERT(!item.GetElements()[1]);
  179. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[2].Get<i16>(), -32768);
  180. UNIT_ASSERT(!item.GetElements()[3]);
  181. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), -32768);
  182. UNIT_ASSERT(!item.GetElements()[5]);
  183. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), -32768);
  184. UNIT_ASSERT(!item.GetElements()[7]);
  185. UNIT_ASSERT(iterator.Next(item));
  186. UNIT_ASSERT(!item.GetElements()[0]);
  187. UNIT_ASSERT(!item.GetElements()[1]);
  188. UNIT_ASSERT(!item.GetElements()[2]);
  189. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[3].Get<ui16>(), 65535);
  190. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), 65535);
  191. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 65535);
  192. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 65535);
  193. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 65535);
  194. UNIT_ASSERT(iterator.Next(item));
  195. UNIT_ASSERT(!item.GetElements()[0]);
  196. UNIT_ASSERT(!item.GetElements()[1]);
  197. UNIT_ASSERT(!item.GetElements()[2]);
  198. UNIT_ASSERT(!item.GetElements()[3]);
  199. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), -65536);
  200. UNIT_ASSERT(!item.GetElements()[5]);
  201. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), -65536);
  202. UNIT_ASSERT(!item.GetElements()[7]);
  203. UNIT_ASSERT(iterator.Next(item));
  204. UNIT_ASSERT(!item.GetElements()[0]);
  205. UNIT_ASSERT(!item.GetElements()[1]);
  206. UNIT_ASSERT(!item.GetElements()[2]);
  207. UNIT_ASSERT(!item.GetElements()[3]);
  208. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), 2147483647LL);
  209. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 2147483647LL);
  210. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 2147483647LL);
  211. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 2147483647LL);
  212. UNIT_ASSERT(iterator.Next(item));
  213. UNIT_ASSERT(!item.GetElements()[0]);
  214. UNIT_ASSERT(!item.GetElements()[1]);
  215. UNIT_ASSERT(!item.GetElements()[2]);
  216. UNIT_ASSERT(!item.GetElements()[3]);
  217. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[4].Get<i32>(), -2147483648LL);
  218. UNIT_ASSERT(!item.GetElements()[5]);
  219. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), -2147483648LL);
  220. UNIT_ASSERT(!item.GetElements()[7]);
  221. UNIT_ASSERT(iterator.Next(item));
  222. UNIT_ASSERT(!item.GetElements()[0]);
  223. UNIT_ASSERT(!item.GetElements()[1]);
  224. UNIT_ASSERT(!item.GetElements()[2]);
  225. UNIT_ASSERT(!item.GetElements()[3]);
  226. UNIT_ASSERT(!item.GetElements()[4]);
  227. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[5].Get<ui32>(), 2147483648LL);
  228. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), 2147483648LL);
  229. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[7].Get<ui64>(), 2147483648LL);
  230. UNIT_ASSERT(iterator.Next(item));
  231. UNIT_ASSERT(!item.GetElements()[0]);
  232. UNIT_ASSERT(!item.GetElements()[1]);
  233. UNIT_ASSERT(!item.GetElements()[2]);
  234. UNIT_ASSERT(!item.GetElements()[3]);
  235. UNIT_ASSERT(!item.GetElements()[4]);
  236. UNIT_ASSERT(!item.GetElements()[5]);
  237. UNIT_ASSERT_VALUES_EQUAL(item.GetElements()[6].Get<i64>(), -2147483649LL);
  238. UNIT_ASSERT(!item.GetElements()[7]);
  239. UNIT_ASSERT(!iterator.Next(item));
  240. UNIT_ASSERT(!iterator.Next(item));
  241. }
  242. Y_UNIT_TEST_LLVM(TestToFloat) {
  243. TSetup<LLVM> setup;
  244. TProgramBuilder& pb = *setup.PgmBuilder;
  245. const auto dataType = pb.NewDecimalType(10, 3);
  246. const auto data0 = pb.NewDecimalLiteral(2123, 10, 3);
  247. const auto data1 = pb.NewDecimalLiteral(233, 10, 3);
  248. const auto data2 = pb.NewDecimalLiteral(0, 10, 3);
  249. const auto data3 = pb.NewDecimalLiteral(-3277823, 10, 3);
  250. const auto data4 = pb.NewDecimalLiteral(-1, 10, 3);
  251. const auto data5 = pb.NewDecimalLiteral(7128, 10, 3);
  252. const auto data6 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 10, 3);
  253. const auto data7 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 10, 3);
  254. const auto data8 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 10, 3);
  255. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8});
  256. const auto pgmReturn = pb.Map(list,
  257. [&](TRuntimeNode item) {
  258. return pb.Convert(item, pb.NewDataType(NUdf::TDataType<float>::Id));
  259. });
  260. const auto graph = setup.BuildGraph(pgmReturn);
  261. const auto iterator = graph->GetValue().GetListIterator();
  262. NUdf::TUnboxedValue item;
  263. UNIT_ASSERT(iterator.Next(item));
  264. UNIT_ASSERT_VALUES_EQUAL(item.template Get<float>(), 2.123f);
  265. UNIT_ASSERT(iterator.Next(item));
  266. UNIT_ASSERT_VALUES_EQUAL(item.template Get<float>(), 0.233f);
  267. UNIT_ASSERT(iterator.Next(item));
  268. UNIT_ASSERT_VALUES_EQUAL(item.template Get<float>(), 0.0f);
  269. UNIT_ASSERT(iterator.Next(item));
  270. UNIT_ASSERT_VALUES_EQUAL(item.template Get<float>(), -3277.823f);
  271. UNIT_ASSERT(iterator.Next(item));
  272. UNIT_ASSERT_VALUES_EQUAL(item.template Get<float>(), -0.001f);
  273. UNIT_ASSERT(iterator.Next(item));
  274. UNIT_ASSERT_VALUES_EQUAL(item.template Get<float>(), 7.128f);
  275. UNIT_ASSERT(iterator.Next(item));
  276. UNIT_ASSERT(std::isnan(item.template Get<float>()));
  277. UNIT_ASSERT(iterator.Next(item));
  278. UNIT_ASSERT(std::isinf(item.template Get<float>()) && item.template Get<float>() > 0.0f);
  279. UNIT_ASSERT(iterator.Next(item));
  280. UNIT_ASSERT(std::isinf(item.template Get<float>()) && item.template Get<float>() < 0.0f);
  281. UNIT_ASSERT(!iterator.Next(item));
  282. UNIT_ASSERT(!iterator.Next(item));
  283. }
  284. Y_UNIT_TEST_LLVM(TestToDouble) {
  285. TSetup<LLVM> setup;
  286. TProgramBuilder& pb = *setup.PgmBuilder;
  287. const auto dataType = pb.NewDecimalType(10, 5);
  288. const auto data0 = pb.NewDecimalLiteral(2123, 10, 5);
  289. const auto data1 = pb.NewDecimalLiteral(233, 10, 5);
  290. const auto data2 = pb.NewDecimalLiteral(0, 10, 5);
  291. const auto data3 = pb.NewDecimalLiteral(-3277823, 10, 5);
  292. const auto data4 = pb.NewDecimalLiteral(-1, 10, 5);
  293. const auto data5 = pb.NewDecimalLiteral(7128, 10, 5);
  294. const auto data6 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 10, 5);
  295. const auto data7 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 10, 5);
  296. const auto data8 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 10, 5);
  297. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8});
  298. const auto pgmReturn = pb.Map(list,
  299. [&](TRuntimeNode item) {
  300. return pb.Convert(item, pb.NewDataType(NUdf::TDataType<double>::Id));
  301. });
  302. const auto graph = setup.BuildGraph(pgmReturn);
  303. const auto iterator = graph->GetValue().GetListIterator();
  304. NUdf::TUnboxedValue item;
  305. UNIT_ASSERT(iterator.Next(item));
  306. UNIT_ASSERT_VALUES_EQUAL(item.template Get<double>(), 0.02123);
  307. UNIT_ASSERT(iterator.Next(item));
  308. UNIT_ASSERT_VALUES_EQUAL(item.template Get<double>(), 0.00233);
  309. UNIT_ASSERT(iterator.Next(item));
  310. UNIT_ASSERT_VALUES_EQUAL(item.template Get<double>(), 0.0);
  311. UNIT_ASSERT(iterator.Next(item));
  312. UNIT_ASSERT_VALUES_EQUAL(item.template Get<double>(), -32.77823);
  313. UNIT_ASSERT(iterator.Next(item));
  314. UNIT_ASSERT_VALUES_EQUAL(item.template Get<double>(), -0.00001);
  315. UNIT_ASSERT(iterator.Next(item));
  316. UNIT_ASSERT_VALUES_EQUAL(item.template Get<double>(), 0.07128);
  317. UNIT_ASSERT(iterator.Next(item));
  318. UNIT_ASSERT(std::isnan(item.template Get<double>()));
  319. UNIT_ASSERT(iterator.Next(item));
  320. UNIT_ASSERT(std::isinf(item.template Get<double>()) && item.template Get<double>() > 0.0);
  321. UNIT_ASSERT(iterator.Next(item));
  322. UNIT_ASSERT(std::isinf(item.template Get<double>()) && item.template Get<double>() < 0.0);
  323. UNIT_ASSERT(!iterator.Next(item));
  324. UNIT_ASSERT(!iterator.Next(item));
  325. }
  326. Y_UNIT_TEST_LLVM(TestDiv) {
  327. TSetup<LLVM> setup;
  328. TProgramBuilder& pb = *setup.PgmBuilder;
  329. const auto dataType = pb.NewDecimalType(10, 0);
  330. const auto data0 = pb.NewDecimalLiteral(2, 10, 0);
  331. const auto data1 = pb.NewDecimalLiteral(23, 10, 0);
  332. const auto data2 = pb.NewDecimalLiteral(-23, 10, 0);
  333. const auto data3 = pb.NewDecimalLiteral(25, 10, 0);
  334. const auto data4 = pb.NewDecimalLiteral(-25, 10, 0);
  335. const auto data5 = pb.NewDecimalLiteral(1, 10, 0);
  336. const auto data6 = pb.NewDecimalLiteral(-1, 10, 0);
  337. const auto data7 = pb.NewDecimalLiteral(3, 10, 0);
  338. const auto data8 = pb.NewDecimalLiteral(-3, 10, 0);
  339. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8});
  340. const auto pgmReturn = pb.Map(list,
  341. [&](TRuntimeNode item) {
  342. return pb.DecimalDiv(item, data0);
  343. });
  344. const auto graph = setup.BuildGraph(pgmReturn);
  345. const auto iterator = graph->GetValue().GetListIterator();
  346. NUdf::TUnboxedValue item;
  347. UNIT_ASSERT(iterator.Next(item));
  348. UNIT_ASSERT(item.GetInt128() == 1);
  349. UNIT_ASSERT(iterator.Next(item));
  350. UNIT_ASSERT(item.GetInt128() == 12);
  351. UNIT_ASSERT(iterator.Next(item));
  352. UNIT_ASSERT(item.GetInt128() == -12);
  353. UNIT_ASSERT(iterator.Next(item));
  354. UNIT_ASSERT(item.GetInt128() == 12);
  355. UNIT_ASSERT(iterator.Next(item));
  356. UNIT_ASSERT(item.GetInt128() == -12);
  357. UNIT_ASSERT(iterator.Next(item));
  358. UNIT_ASSERT(item.GetInt128() == 0);
  359. UNIT_ASSERT(iterator.Next(item));
  360. UNIT_ASSERT(item.GetInt128() == 0);
  361. UNIT_ASSERT(iterator.Next(item));
  362. UNIT_ASSERT(item.GetInt128() == 2);
  363. UNIT_ASSERT(iterator.Next(item));
  364. UNIT_ASSERT(item.GetInt128() == -2);
  365. UNIT_ASSERT(!iterator.Next(item));
  366. UNIT_ASSERT(!iterator.Next(item));
  367. }
  368. Y_UNIT_TEST_LLVM(TestDivInt) {
  369. TSetup<LLVM> setup;
  370. TProgramBuilder& pb = *setup.PgmBuilder;
  371. const auto dataType = pb.NewDataType(NUdf::TDataType<i8>::Id);
  372. const auto data0 = pb.NewDecimalLiteral(-238973, 9, 3);
  373. const auto data1 = pb.NewDataLiteral<i8>(0);
  374. const auto data2 = pb.NewDataLiteral<i8>(-1);
  375. const auto data3 = pb.NewDataLiteral<i8>(-128);
  376. const auto data4 = pb.NewDataLiteral<i8>(3);
  377. const auto data5 = pb.NewDataLiteral<i8>(5);
  378. const auto data6 = pb.NewDataLiteral<i8>(-7);
  379. const auto data7 = pb.NewDataLiteral<i8>(13);
  380. const auto data8 = pb.NewDataLiteral<i8>(-19);
  381. const auto data9 = pb.NewDataLiteral<i8>(42);
  382. const auto list = pb.NewList(dataType, {data1, data2, data3, data4, data5, data6, data7, data8, data9});
  383. const auto pgmReturn = pb.Map(list,
  384. [&](TRuntimeNode item) {
  385. return pb.DecimalDiv(data0, item);
  386. });
  387. const auto graph = setup.BuildGraph(pgmReturn);
  388. const auto iterator = graph->GetValue().GetListIterator();
  389. NUdf::TUnboxedValue item;
  390. UNIT_ASSERT(iterator.Next(item));
  391. UNIT_ASSERT(item.GetInt128() == -NYql::NDecimal::Inf());
  392. UNIT_ASSERT(iterator.Next(item));
  393. UNIT_ASSERT(item.GetInt128() == 238973);
  394. UNIT_ASSERT(iterator.Next(item));
  395. UNIT_ASSERT(item.GetInt128() == 1866);
  396. UNIT_ASSERT(iterator.Next(item));
  397. UNIT_ASSERT(item.GetInt128() == -79658);
  398. UNIT_ASSERT(iterator.Next(item));
  399. UNIT_ASSERT(item.GetInt128() == -47795);
  400. UNIT_ASSERT(iterator.Next(item));
  401. UNIT_ASSERT(item.GetInt128() == 34139);
  402. UNIT_ASSERT(iterator.Next(item));
  403. UNIT_ASSERT(item.GetInt128() == -18383);
  404. UNIT_ASSERT(iterator.Next(item));
  405. UNIT_ASSERT(item.GetInt128() == 12577);
  406. UNIT_ASSERT(iterator.Next(item));
  407. UNIT_ASSERT(item.GetInt128() == -5690);
  408. UNIT_ASSERT(!iterator.Next(item));
  409. UNIT_ASSERT(!iterator.Next(item));
  410. }
  411. Y_UNIT_TEST_LLVM(TestMod) {
  412. TSetup<LLVM> setup;
  413. TProgramBuilder& pb = *setup.PgmBuilder;
  414. const auto dataType = pb.NewDecimalType(5, 2);
  415. const auto data0 = pb.NewDecimalLiteral(-12323, 5, 2);
  416. const auto data1 = pb.NewDecimalLiteral(0, 5, 2);
  417. const auto data2 = pb.NewDecimalLiteral(NYql::NDecimal::Inf(), 5, 2);
  418. const auto data3 = pb.NewDecimalLiteral(-1, 5, 2);
  419. const auto data4 = pb.NewDecimalLiteral(2, 5, 2);
  420. const auto data5 = pb.NewDecimalLiteral(-3, 5, 2);
  421. const auto data6 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 5, 2);
  422. const auto data7 = pb.NewDecimalLiteral(7, 5, 2);
  423. const auto data8 = pb.NewDecimalLiteral(-10000, 5, 2);
  424. const auto data9 = pb.NewDecimalLiteral(12329, 5, 2);
  425. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8, data9});
  426. const auto pgmReturn = pb.Map(list,
  427. [&](TRuntimeNode item) {
  428. return pb.DecimalMod(data0, item);
  429. });
  430. const auto graph = setup.BuildGraph(pgmReturn);
  431. const auto iterator = graph->GetValue().GetListIterator();
  432. NUdf::TUnboxedValue item;
  433. UNIT_ASSERT(iterator.Next(item));
  434. UNIT_ASSERT(item.GetInt128() == 0);
  435. UNIT_ASSERT(iterator.Next(item));
  436. UNIT_ASSERT(item.GetInt128() == NYql::NDecimal::Nan());
  437. UNIT_ASSERT(iterator.Next(item));
  438. UNIT_ASSERT(item.GetInt128() == NYql::NDecimal::Nan());
  439. UNIT_ASSERT(iterator.Next(item));
  440. UNIT_ASSERT(item.GetInt128() == 0);
  441. UNIT_ASSERT(iterator.Next(item));
  442. UNIT_ASSERT(item.GetInt128() == -1);
  443. UNIT_ASSERT(iterator.Next(item));
  444. UNIT_ASSERT(item.GetInt128() == -2);
  445. UNIT_ASSERT(iterator.Next(item));
  446. UNIT_ASSERT(item.GetInt128() == NYql::NDecimal::Nan());
  447. UNIT_ASSERT(iterator.Next(item));
  448. UNIT_ASSERT(item.GetInt128() == -3);
  449. UNIT_ASSERT(iterator.Next(item));
  450. UNIT_ASSERT(item.GetInt128() == -2323);
  451. UNIT_ASSERT(iterator.Next(item));
  452. UNIT_ASSERT(item.GetInt128() == -12323);
  453. UNIT_ASSERT(!iterator.Next(item));
  454. UNIT_ASSERT(!iterator.Next(item));
  455. }
  456. Y_UNIT_TEST_LLVM(TestModInt) {
  457. TSetup<LLVM> setup;
  458. TProgramBuilder& pb = *setup.PgmBuilder;
  459. const auto dataType = pb.NewDataType(NUdf::TDataType<i16>::Id);
  460. const auto data0 = pb.NewDecimalLiteral(-743, 3, 2);
  461. const auto data1 = pb.NewDataLiteral<i16>(0);
  462. const auto data2 = pb.NewDataLiteral<i16>(1);
  463. const auto data3 = pb.NewDataLiteral<i16>(-2);
  464. const auto data4 = pb.NewDataLiteral<i16>(3);
  465. const auto data5 = pb.NewDataLiteral<i16>(4);
  466. const auto data6 = pb.NewDataLiteral<i16>(-5);
  467. const auto data7 = pb.NewDataLiteral<i16>(8);
  468. const auto data8 = pb.NewDataLiteral<i16>(10);
  469. const auto data9 = pb.NewDataLiteral<i16>(-10);
  470. const auto list = pb.NewList(dataType, {data1, data2, data3, data4, data5, data6, data7, data8, data9});
  471. const auto pgmReturn = pb.Map(list,
  472. [&](TRuntimeNode item) {
  473. return pb.DecimalMod(data0, item);
  474. });
  475. const auto graph = setup.BuildGraph(pgmReturn);
  476. const auto iterator = graph->GetValue().GetListIterator();
  477. NUdf::TUnboxedValue item;
  478. UNIT_ASSERT(iterator.Next(item));
  479. UNIT_ASSERT(item.GetInt128() == NYql::NDecimal::Nan());
  480. UNIT_ASSERT(iterator.Next(item));
  481. UNIT_ASSERT(item.GetInt128() == -43);
  482. UNIT_ASSERT(iterator.Next(item));
  483. UNIT_ASSERT(item.GetInt128() == -143);
  484. UNIT_ASSERT(iterator.Next(item));
  485. UNIT_ASSERT(item.GetInt128() == -143);
  486. UNIT_ASSERT(iterator.Next(item));
  487. UNIT_ASSERT(item.GetInt128() == -343);
  488. UNIT_ASSERT(iterator.Next(item));
  489. UNIT_ASSERT(item.GetInt128() == -243);
  490. UNIT_ASSERT(iterator.Next(item));
  491. UNIT_ASSERT(item.GetInt128() == -743);
  492. UNIT_ASSERT(iterator.Next(item));
  493. UNIT_ASSERT(item.GetInt128() == -743);
  494. UNIT_ASSERT(iterator.Next(item));
  495. UNIT_ASSERT(item.GetInt128() == -743);
  496. UNIT_ASSERT(!iterator.Next(item));
  497. UNIT_ASSERT(!iterator.Next(item));
  498. }
  499. Y_UNIT_TEST_LLVM(TestMul) {
  500. TSetup<LLVM> setup;
  501. TProgramBuilder& pb = *setup.PgmBuilder;
  502. const auto dataType = pb.NewDecimalType(10, 2);
  503. const auto data0 = pb.NewDecimalLiteral(333, 10, 2);
  504. const auto data1 = pb.NewDecimalLiteral(-100, 10, 2);
  505. const auto data2 = pb.NewDecimalLiteral(-120, 10, 2);
  506. const auto data3 = pb.NewDecimalLiteral(3, 10, 2);
  507. const auto data4 = pb.NewDecimalLiteral(77, 10, 2);
  508. const auto data5 = pb.NewDecimalLiteral(122, 10, 2);
  509. const auto data6 = pb.NewDecimalLiteral(1223, 10, 2);
  510. const auto data7 = pb.NewDecimalLiteral(-999, 10, 2);
  511. const auto data8 = pb.NewDecimalLiteral(0, 10, 2);
  512. const auto data9 = pb.NewDecimalLiteral(-3003003003LL, 10, 2);
  513. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8, data9});
  514. const auto pgmReturn = pb.Map(list,
  515. [&](TRuntimeNode item) {
  516. return pb.DecimalMul(item, data0);
  517. });
  518. const auto graph = setup.BuildGraph(pgmReturn);
  519. const auto iterator = graph->GetValue().GetListIterator();
  520. NUdf::TUnboxedValue item;
  521. UNIT_ASSERT(iterator.Next(item));
  522. UNIT_ASSERT(item.GetInt128() == 1109);
  523. UNIT_ASSERT(iterator.Next(item));
  524. UNIT_ASSERT(item.GetInt128() == -333);
  525. UNIT_ASSERT(iterator.Next(item));
  526. UNIT_ASSERT(item.GetInt128() == -400);
  527. UNIT_ASSERT(iterator.Next(item));
  528. UNIT_ASSERT(item.GetInt128() == 10);
  529. UNIT_ASSERT(iterator.Next(item));
  530. UNIT_ASSERT(item.GetInt128() == 256);
  531. UNIT_ASSERT(iterator.Next(item));
  532. UNIT_ASSERT(item.GetInt128() == 406);
  533. UNIT_ASSERT(iterator.Next(item));
  534. UNIT_ASSERT(item.GetInt128() == 4073);
  535. UNIT_ASSERT(iterator.Next(item));
  536. UNIT_ASSERT(item.GetInt128() == -3327);
  537. UNIT_ASSERT(iterator.Next(item));
  538. UNIT_ASSERT(item.GetInt128() == 0);
  539. UNIT_ASSERT(iterator.Next(item));
  540. UNIT_ASSERT(item.GetInt128() == -NYql::NDecimal::Inf());
  541. UNIT_ASSERT(!iterator.Next(item));
  542. UNIT_ASSERT(!iterator.Next(item));
  543. }
  544. Y_UNIT_TEST_LLVM(TestMulUInt) {
  545. TSetup<LLVM> setup;
  546. TProgramBuilder& pb = *setup.PgmBuilder;
  547. const auto dataType = pb.NewDataType(NUdf::TDataType<ui16>::Id);
  548. const auto data0 = pb.NewDecimalLiteral(-333, 7, 2);
  549. const auto data1 = pb.NewDataLiteral<ui16>(0);
  550. const auto data2 = pb.NewDataLiteral<ui16>(1);
  551. const auto data3 = pb.NewDataLiteral<ui16>(2);
  552. const auto data4 = pb.NewDataLiteral<ui16>(3);
  553. const auto data5 = pb.NewDataLiteral<ui16>(10);
  554. const auto data6 = pb.NewDataLiteral<ui16>(100);
  555. const auto data7 = pb.NewDataLiteral<ui16>(1000);
  556. const auto data8 = pb.NewDataLiteral<ui16>(10000);
  557. const auto data9 = pb.NewDataLiteral<ui16>(65535);
  558. const auto list = pb.NewList(dataType, {data1, data2, data3, data4, data5, data6, data7, data8, data9});
  559. const auto pgmReturn = pb.Map(list,
  560. [&](TRuntimeNode item) {
  561. return pb.DecimalMul(data0, item);
  562. });
  563. const auto graph = setup.BuildGraph(pgmReturn);
  564. const auto iterator = graph->GetValue().GetListIterator();
  565. NUdf::TUnboxedValue item;
  566. UNIT_ASSERT(iterator.Next(item));
  567. UNIT_ASSERT(item.GetInt128() == 0);
  568. UNIT_ASSERT(iterator.Next(item));
  569. UNIT_ASSERT(item.GetInt128() == -333);
  570. UNIT_ASSERT(iterator.Next(item));
  571. UNIT_ASSERT(item.GetInt128() == -666);
  572. UNIT_ASSERT(iterator.Next(item));
  573. UNIT_ASSERT(item.GetInt128() == -999);
  574. UNIT_ASSERT(iterator.Next(item));
  575. UNIT_ASSERT(item.GetInt128() == -3330);
  576. UNIT_ASSERT(iterator.Next(item));
  577. UNIT_ASSERT(item.GetInt128() == -33300);
  578. UNIT_ASSERT(iterator.Next(item));
  579. UNIT_ASSERT(item.GetInt128() == -333000);
  580. UNIT_ASSERT(iterator.Next(item));
  581. UNIT_ASSERT(item.GetInt128() == -3330000);
  582. UNIT_ASSERT(iterator.Next(item));
  583. UNIT_ASSERT(item.GetInt128() == -NYql::NDecimal::Inf());
  584. UNIT_ASSERT(!iterator.Next(item));
  585. UNIT_ASSERT(!iterator.Next(item));
  586. }
  587. Y_UNIT_TEST_LLVM(TestMulTinyInt) {
  588. TSetup<LLVM> setup;
  589. TProgramBuilder& pb = *setup.PgmBuilder;
  590. const auto dataType = pb.NewDataType(NUdf::TDataType<i8>::Id);
  591. const auto data0 = pb.NewDecimalLiteral(3631400, 32, 4);
  592. const auto data1 = pb.NewDataLiteral<i8>(0);
  593. const auto data2 = pb.NewDataLiteral<i8>(1);
  594. const auto data3 = pb.NewDataLiteral<i8>(-1);
  595. const auto data4 = pb.NewDataLiteral<i8>(3);
  596. const auto data5 = pb.NewDataLiteral<i8>(-3);
  597. const auto data6 = pb.NewDataLiteral<i8>(100);
  598. const auto data7 = pb.NewDataLiteral<i8>(-100);
  599. const auto data8 = pb.NewDataLiteral<i8>(127);
  600. const auto data9 = pb.NewDataLiteral<i8>(-128);
  601. const auto list = pb.NewList(dataType, {data1, data2, data3, data4, data5, data6, data7, data8, data9});
  602. const auto pgmReturn = pb.Map(list,
  603. [&](TRuntimeNode item) {
  604. return pb.DecimalMul(data0, item);
  605. });
  606. const auto graph = setup.BuildGraph(pgmReturn);
  607. const auto iterator = graph->GetValue().GetListIterator();
  608. NUdf::TUnboxedValue item;
  609. UNIT_ASSERT(iterator.Next(item));
  610. UNIT_ASSERT(item.GetInt128() == 0);
  611. UNIT_ASSERT(iterator.Next(item));
  612. UNIT_ASSERT(item.GetInt128() == 3631400);
  613. UNIT_ASSERT(iterator.Next(item));
  614. UNIT_ASSERT(item.GetInt128() == -3631400);
  615. UNIT_ASSERT(iterator.Next(item));
  616. UNIT_ASSERT(item.GetInt128() == 10894200);
  617. UNIT_ASSERT(iterator.Next(item));
  618. UNIT_ASSERT(item.GetInt128() == -10894200);
  619. UNIT_ASSERT(iterator.Next(item));
  620. UNIT_ASSERT(item.GetInt128() == 363140000);
  621. UNIT_ASSERT(iterator.Next(item));
  622. UNIT_ASSERT(item.GetInt128() == -363140000);
  623. UNIT_ASSERT(iterator.Next(item));
  624. UNIT_ASSERT(item.GetInt128() == 461187800);
  625. UNIT_ASSERT(iterator.Next(item));
  626. UNIT_ASSERT(item.GetInt128() == -464819200);
  627. UNIT_ASSERT(!iterator.Next(item));
  628. UNIT_ASSERT(!iterator.Next(item));
  629. }
  630. Y_UNIT_TEST_LLVM(TestCastAndMulTinyInt) {
  631. TSetup<LLVM> setup;
  632. TProgramBuilder& pb = *setup.PgmBuilder;
  633. const auto dataType = pb.NewDecimalType(32, 4);
  634. const auto data0 = pb.NewDataLiteral<i8>(1);
  635. const auto data1 = pb.NewDecimalLiteral(3145926, 32, 4);
  636. const auto data2 = pb.NewDecimalLiteral(-3145926, 32, 4);
  637. const auto list = pb.NewList(dataType, {data1, data2});
  638. const auto pgmReturn = pb.Map(list,
  639. [&](TRuntimeNode item) {
  640. return pb.NewTuple({pb.DecimalMul(item, data0), pb.DecimalMul(item, pb.ToDecimal(data0, 32, 4))});
  641. });
  642. const auto graph = setup.BuildGraph(pgmReturn);
  643. const auto iterator = graph->GetValue().GetListIterator();
  644. NUdf::TUnboxedValue item;
  645. UNIT_ASSERT(iterator.Next(item));
  646. UNIT_ASSERT(item.GetElement(0).GetInt128() == 3145926);
  647. UNIT_ASSERT(item.GetElement(1).GetInt128() == 3145926);
  648. UNIT_ASSERT(iterator.Next(item));
  649. UNIT_ASSERT(item.GetElement(0).GetInt128() == -3145926);
  650. UNIT_ASSERT(item.GetElement(1).GetInt128() == -3145926);
  651. UNIT_ASSERT(!iterator.Next(item));
  652. UNIT_ASSERT(!iterator.Next(item));
  653. }
  654. Y_UNIT_TEST_LLVM(TestLongintMul) {
  655. TSetup<LLVM> setup;
  656. TProgramBuilder& pb = *setup.PgmBuilder;
  657. const auto dataType = pb.NewDecimalType(10, 0);
  658. const auto data0 = pb.NewDecimalLiteral(333, 10, 0);
  659. const auto data1 = pb.NewDecimalLiteral(-100, 10, 0);
  660. const auto data2 = pb.NewDecimalLiteral(-120, 10, 0);
  661. const auto data3 = pb.NewDecimalLiteral(3, 10, 0);
  662. const auto data4 = pb.NewDecimalLiteral(77, 10, 0);
  663. const auto data5 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 10, 0);
  664. const auto data6 = pb.NewDecimalLiteral(30030031, 10, 0);
  665. const auto data7 = pb.NewDecimalLiteral(-30030031, 10, 0);
  666. const auto data8 = pb.NewDecimalLiteral(0, 10, 0);
  667. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8});
  668. const auto pgmReturn = pb.Map(list,
  669. [&](TRuntimeNode item) {
  670. return pb.DecimalMul(item, data0);
  671. });
  672. const auto graph = setup.BuildGraph(pgmReturn);
  673. const auto iterator = graph->GetValue().GetListIterator();
  674. NUdf::TUnboxedValue item;
  675. UNIT_ASSERT(iterator.Next(item));
  676. UNIT_ASSERT(item.GetInt128() == 110889);
  677. UNIT_ASSERT(iterator.Next(item));
  678. UNIT_ASSERT(item.GetInt128() == -33300);
  679. UNIT_ASSERT(iterator.Next(item));
  680. UNIT_ASSERT(item.GetInt128() == -39960);
  681. UNIT_ASSERT(iterator.Next(item));
  682. UNIT_ASSERT(item.GetInt128() == 999);
  683. UNIT_ASSERT(iterator.Next(item));
  684. UNIT_ASSERT(item.GetInt128() == 25641);
  685. UNIT_ASSERT(iterator.Next(item));
  686. UNIT_ASSERT(item.GetInt128() == NYql::NDecimal::Nan());
  687. UNIT_ASSERT(iterator.Next(item));
  688. UNIT_ASSERT(item.GetInt128() == NYql::NDecimal::Inf());
  689. UNIT_ASSERT(iterator.Next(item));
  690. UNIT_ASSERT(item.GetInt128() == -NYql::NDecimal::Inf());
  691. UNIT_ASSERT(iterator.Next(item));
  692. UNIT_ASSERT(item.GetInt128() == 0);
  693. UNIT_ASSERT(!iterator.Next(item));
  694. UNIT_ASSERT(!iterator.Next(item));
  695. }
  696. Y_UNIT_TEST_LLVM(TestScaleUp) {
  697. TSetup<LLVM> setup;
  698. TProgramBuilder& pb = *setup.PgmBuilder;
  699. const auto dataType = pb.NewDecimalType(10, 2);
  700. const auto data0 = pb.NewDecimalLiteral(333, 10, 2);
  701. const auto data1 = pb.NewDecimalLiteral(-100, 10, 2);
  702. const auto data2 = pb.NewDecimalLiteral(-120, 10, 2);
  703. const auto data3 = pb.NewDecimalLiteral(3, 10, 2);
  704. const auto data4 = pb.NewDecimalLiteral(77, 10, 2);
  705. const auto data5 = pb.NewDecimalLiteral(122, 10, 2);
  706. const auto data6 = pb.NewDecimalLiteral(1223, 10, 2);
  707. const auto data7 = pb.NewDecimalLiteral(-999, 10, 2);
  708. const auto data8 = pb.NewDecimalLiteral(0, 10, 2);
  709. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8});
  710. const auto pgmReturn = pb.Map(list,
  711. [&](TRuntimeNode item) {
  712. return pb.ToDecimal(item, 12, 4);
  713. });
  714. const auto graph = setup.BuildGraph(pgmReturn);
  715. const auto iterator = graph->GetValue().GetListIterator();
  716. NUdf::TUnboxedValue item;
  717. UNIT_ASSERT(iterator.Next(item));
  718. UNIT_ASSERT(item.GetInt128() == 33300);
  719. UNIT_ASSERT(iterator.Next(item));
  720. UNIT_ASSERT(item.GetInt128() == -10000);
  721. UNIT_ASSERT(iterator.Next(item));
  722. UNIT_ASSERT(item.GetInt128() == -12000);
  723. UNIT_ASSERT(iterator.Next(item));
  724. UNIT_ASSERT(item.GetInt128() == 300);
  725. UNIT_ASSERT(iterator.Next(item));
  726. UNIT_ASSERT(item.GetInt128() == 7700);
  727. UNIT_ASSERT(iterator.Next(item));
  728. UNIT_ASSERT(item.GetInt128() == 12200);
  729. UNIT_ASSERT(iterator.Next(item));
  730. UNIT_ASSERT(item.GetInt128() == 122300);
  731. UNIT_ASSERT(iterator.Next(item));
  732. UNIT_ASSERT(item.GetInt128() == -99900);
  733. UNIT_ASSERT(iterator.Next(item));
  734. UNIT_ASSERT(item.GetInt128() == 0);
  735. UNIT_ASSERT(!iterator.Next(item));
  736. UNIT_ASSERT(!iterator.Next(item));
  737. }
  738. Y_UNIT_TEST_LLVM(TestScaleDown) {
  739. TSetup<LLVM> setup;
  740. TProgramBuilder& pb = *setup.PgmBuilder;
  741. const auto dataType = pb.NewDecimalType(10, 2);
  742. const auto data0 = pb.NewDecimalLiteral(-251, 10, 2);
  743. const auto data1 = pb.NewDecimalLiteral(-250, 10, 2);
  744. const auto data2 = pb.NewDecimalLiteral(-150, 10, 2);
  745. const auto data3 = pb.NewDecimalLiteral(-51, 10, 2);
  746. const auto data4 = pb.NewDecimalLiteral(50, 10, 2);
  747. const auto data5 = pb.NewDecimalLiteral(50, 10, 2);
  748. const auto data6 = pb.NewDecimalLiteral(51, 10, 2);
  749. const auto data7 = pb.NewDecimalLiteral(150, 10, 2);
  750. const auto data8 = pb.NewDecimalLiteral(250, 10, 2);
  751. const auto data9 = pb.NewDecimalLiteral(251, 10, 2);
  752. const auto list = pb.NewList(dataType, {data0, data1, data2, data3, data4, data5, data6, data7, data8, data9});
  753. const auto pgmReturn = pb.Map(list,
  754. [&](TRuntimeNode item) {
  755. return pb.ToDecimal(item, 8, 0);
  756. });
  757. const auto graph = setup.BuildGraph(pgmReturn);
  758. const auto iterator = graph->GetValue().GetListIterator();
  759. NUdf::TUnboxedValue item;
  760. UNIT_ASSERT(iterator.Next(item));
  761. UNIT_ASSERT(item.GetInt128() == -3);
  762. UNIT_ASSERT(iterator.Next(item));
  763. UNIT_ASSERT(item.GetInt128() == -2);
  764. UNIT_ASSERT(iterator.Next(item));
  765. UNIT_ASSERT(item.GetInt128() == -2);
  766. UNIT_ASSERT(iterator.Next(item));
  767. UNIT_ASSERT(item.GetInt128() == -1);
  768. UNIT_ASSERT(iterator.Next(item));
  769. UNIT_ASSERT(item.GetInt128() == 0);
  770. UNIT_ASSERT(iterator.Next(item));
  771. UNIT_ASSERT(item.GetInt128() == 0);
  772. UNIT_ASSERT(iterator.Next(item));
  773. UNIT_ASSERT(item.GetInt128() == 1);
  774. UNIT_ASSERT(iterator.Next(item));
  775. UNIT_ASSERT(item.GetInt128() == 2);
  776. UNIT_ASSERT(iterator.Next(item));
  777. UNIT_ASSERT(item.GetInt128() == 2);
  778. UNIT_ASSERT(iterator.Next(item));
  779. UNIT_ASSERT(item.GetInt128() == 3);
  780. UNIT_ASSERT(!iterator.Next(item));
  781. UNIT_ASSERT(!iterator.Next(item));
  782. }
  783. Y_UNIT_TEST_LLVM(TestMinMax) {
  784. TSetup<LLVM> setup;
  785. TProgramBuilder& pb = *setup.PgmBuilder;
  786. const auto data1 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 13, 2);
  787. const auto data2 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 13, 2);
  788. const auto data3 = pb.NewDecimalLiteral(314, 13, 2);
  789. const auto data4 = pb.NewDecimalLiteral(-213, 13, 2);
  790. const auto data5 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 13, 2);
  791. const auto dataType = pb.NewDecimalType(13, 2);
  792. const auto list = pb.NewList(dataType, {data1, data2, data3, data4, data5});
  793. const auto pgmReturn = pb.FlatMap(list,
  794. [&](TRuntimeNode left) {
  795. return pb.Map(list,
  796. [&](TRuntimeNode right) {
  797. return pb.NewTuple({pb.Min(left, right), pb.Max(left, right)});
  798. });
  799. });
  800. const auto graph = setup.BuildGraph(pgmReturn);
  801. const auto iterator = graph->GetValue().GetListIterator();
  802. NUdf::TUnboxedValue item;
  803. UNIT_ASSERT(iterator.Next(item));
  804. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  805. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  806. UNIT_ASSERT(iterator.Next(item));
  807. UNIT_ASSERT(item.GetElement(0).GetInt128() == +NYql::NDecimal::Inf());
  808. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  809. UNIT_ASSERT(iterator.Next(item));
  810. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  811. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  812. UNIT_ASSERT(iterator.Next(item));
  813. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  814. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  815. UNIT_ASSERT(iterator.Next(item));
  816. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  817. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  818. UNIT_ASSERT(iterator.Next(item));
  819. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  820. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Inf());
  821. UNIT_ASSERT(iterator.Next(item));
  822. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  823. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Inf());
  824. UNIT_ASSERT(iterator.Next(item));
  825. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  826. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  827. UNIT_ASSERT(iterator.Next(item));
  828. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  829. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  830. UNIT_ASSERT(iterator.Next(item));
  831. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  832. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  833. UNIT_ASSERT(iterator.Next(item));
  834. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  835. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  836. UNIT_ASSERT(iterator.Next(item));
  837. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  838. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  839. UNIT_ASSERT(iterator.Next(item));
  840. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  841. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  842. UNIT_ASSERT(iterator.Next(item));
  843. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  844. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  845. UNIT_ASSERT(iterator.Next(item));
  846. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  847. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  848. UNIT_ASSERT(iterator.Next(item));
  849. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  850. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  851. UNIT_ASSERT(iterator.Next(item));
  852. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  853. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  854. UNIT_ASSERT(iterator.Next(item));
  855. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  856. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  857. UNIT_ASSERT(iterator.Next(item));
  858. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  859. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  860. UNIT_ASSERT(iterator.Next(item));
  861. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  862. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  863. UNIT_ASSERT(iterator.Next(item));
  864. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  865. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  866. UNIT_ASSERT(iterator.Next(item));
  867. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  868. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  869. UNIT_ASSERT(iterator.Next(item));
  870. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  871. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  872. UNIT_ASSERT(iterator.Next(item));
  873. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  874. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  875. UNIT_ASSERT(iterator.Next(item));
  876. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  877. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  878. UNIT_ASSERT(!iterator.Next(item));
  879. UNIT_ASSERT(!iterator.Next(item));
  880. }
  881. Y_UNIT_TEST_LLVM(TestAggrMinMax) {
  882. TSetup<LLVM> setup;
  883. TProgramBuilder& pb = *setup.PgmBuilder;
  884. const auto data1 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 13, 2);
  885. const auto data2 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 13, 2);
  886. const auto data3 = pb.NewDecimalLiteral(314, 13, 2);
  887. const auto data4 = pb.NewDecimalLiteral(-213, 13, 2);
  888. const auto data5 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 13, 2);
  889. const auto dataType = pb.NewDecimalType(13, 2);
  890. const auto list = pb.NewList(dataType, {data1, data2, data3, data4, data5});
  891. const auto pgmReturn = pb.FlatMap(list,
  892. [&](TRuntimeNode left) {
  893. return pb.Map(list,
  894. [&](TRuntimeNode right) {
  895. return pb.NewTuple({pb.AggrMin(left, right), pb.AggrMax(left, right)});
  896. });
  897. });
  898. const auto graph = setup.BuildGraph(pgmReturn);
  899. const auto iterator = graph->GetValue().GetListIterator();
  900. NUdf::TUnboxedValue item;
  901. UNIT_ASSERT(iterator.Next(item));
  902. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  903. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  904. UNIT_ASSERT(iterator.Next(item));
  905. UNIT_ASSERT(item.GetElement(0).GetInt128() == +NYql::NDecimal::Inf());
  906. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  907. UNIT_ASSERT(iterator.Next(item));
  908. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  909. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  910. UNIT_ASSERT(iterator.Next(item));
  911. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  912. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  913. UNIT_ASSERT(iterator.Next(item));
  914. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  915. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  916. UNIT_ASSERT(iterator.Next(item));
  917. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  918. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  919. UNIT_ASSERT(iterator.Next(item));
  920. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  921. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Inf());
  922. UNIT_ASSERT(iterator.Next(item));
  923. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  924. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  925. UNIT_ASSERT(iterator.Next(item));
  926. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  927. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  928. UNIT_ASSERT(iterator.Next(item));
  929. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  930. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  931. UNIT_ASSERT(iterator.Next(item));
  932. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  933. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  934. UNIT_ASSERT(iterator.Next(item));
  935. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  936. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  937. UNIT_ASSERT(iterator.Next(item));
  938. UNIT_ASSERT(item.GetElement(0).GetInt128() == 314);
  939. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  940. UNIT_ASSERT(iterator.Next(item));
  941. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  942. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  943. UNIT_ASSERT(iterator.Next(item));
  944. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  945. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  946. UNIT_ASSERT(iterator.Next(item));
  947. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  948. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  949. UNIT_ASSERT(iterator.Next(item));
  950. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  951. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  952. UNIT_ASSERT(iterator.Next(item));
  953. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  954. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  955. UNIT_ASSERT(iterator.Next(item));
  956. UNIT_ASSERT(item.GetElement(0).GetInt128() == -213);
  957. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  958. UNIT_ASSERT(iterator.Next(item));
  959. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  960. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  961. UNIT_ASSERT(iterator.Next(item));
  962. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  963. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  964. UNIT_ASSERT(iterator.Next(item));
  965. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  966. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  967. UNIT_ASSERT(iterator.Next(item));
  968. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  969. UNIT_ASSERT(item.GetElement(1).GetInt128() == 314);
  970. UNIT_ASSERT(iterator.Next(item));
  971. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  972. UNIT_ASSERT(item.GetElement(1).GetInt128() == -213);
  973. UNIT_ASSERT(iterator.Next(item));
  974. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  975. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  976. UNIT_ASSERT(!iterator.Next(item));
  977. UNIT_ASSERT(!iterator.Next(item));
  978. }
  979. Y_UNIT_TEST_LLVM(TestAddSub) {
  980. TSetup<LLVM> setup;
  981. TProgramBuilder& pb = *setup.PgmBuilder;
  982. const auto data1 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 13, 2);
  983. const auto data2 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 13, 2);
  984. const auto data3 = pb.NewDecimalLiteral(314, 13, 2);
  985. const auto data4 = pb.NewDecimalLiteral(-213, 13, 2);
  986. const auto data5 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 13, 2);
  987. const auto dataType = pb.NewDecimalType(13, 2);
  988. const auto list = pb.NewList(dataType, {data1, data2, data3, data4, data5});
  989. const auto pgmReturn = pb.FlatMap(list,
  990. [&](TRuntimeNode left) {
  991. return pb.Map(list,
  992. [&](TRuntimeNode right) {
  993. return pb.NewTuple({pb.Add(left, right), pb.Sub(left, right)});
  994. });
  995. });
  996. const auto graph = setup.BuildGraph(pgmReturn);
  997. const auto iterator = graph->GetValue().GetListIterator();
  998. NUdf::TUnboxedValue item;
  999. UNIT_ASSERT(iterator.Next(item));
  1000. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1001. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1002. UNIT_ASSERT(iterator.Next(item));
  1003. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1004. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1005. UNIT_ASSERT(iterator.Next(item));
  1006. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1007. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1008. UNIT_ASSERT(iterator.Next(item));
  1009. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1010. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1011. UNIT_ASSERT(iterator.Next(item));
  1012. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1013. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1014. UNIT_ASSERT(iterator.Next(item));
  1015. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1016. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1017. UNIT_ASSERT(iterator.Next(item));
  1018. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  1019. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1020. UNIT_ASSERT(iterator.Next(item));
  1021. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  1022. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Inf());
  1023. UNIT_ASSERT(iterator.Next(item));
  1024. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  1025. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Inf());
  1026. UNIT_ASSERT(iterator.Next(item));
  1027. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1028. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Inf());
  1029. UNIT_ASSERT(iterator.Next(item));
  1030. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1031. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1032. UNIT_ASSERT(iterator.Next(item));
  1033. UNIT_ASSERT(item.GetElement(0).GetInt128() == +NYql::NDecimal::Inf());
  1034. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  1035. UNIT_ASSERT(iterator.Next(item));
  1036. UNIT_ASSERT(item.GetElement(0).GetInt128() == 628);
  1037. UNIT_ASSERT(item.GetElement(1).GetInt128() == 0);
  1038. UNIT_ASSERT(iterator.Next(item));
  1039. UNIT_ASSERT(item.GetElement(0).GetInt128() == 101);
  1040. UNIT_ASSERT(item.GetElement(1).GetInt128() == 527);
  1041. UNIT_ASSERT(iterator.Next(item));
  1042. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  1043. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  1044. UNIT_ASSERT(iterator.Next(item));
  1045. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1046. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1047. UNIT_ASSERT(iterator.Next(item));
  1048. UNIT_ASSERT(item.GetElement(0).GetInt128() == +NYql::NDecimal::Inf());
  1049. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  1050. UNIT_ASSERT(iterator.Next(item));
  1051. UNIT_ASSERT(item.GetElement(0).GetInt128() == 101);
  1052. UNIT_ASSERT(item.GetElement(1).GetInt128() == -527);
  1053. UNIT_ASSERT(iterator.Next(item));
  1054. UNIT_ASSERT(item.GetElement(0).GetInt128() == -426);
  1055. UNIT_ASSERT(item.GetElement(1).GetInt128() == 0);
  1056. UNIT_ASSERT(iterator.Next(item));
  1057. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  1058. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  1059. UNIT_ASSERT(iterator.Next(item));
  1060. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1061. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1062. UNIT_ASSERT(iterator.Next(item));
  1063. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1064. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  1065. UNIT_ASSERT(iterator.Next(item));
  1066. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  1067. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  1068. UNIT_ASSERT(iterator.Next(item));
  1069. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  1070. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  1071. UNIT_ASSERT(iterator.Next(item));
  1072. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  1073. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1074. UNIT_ASSERT(!iterator.Next(item));
  1075. UNIT_ASSERT(!iterator.Next(item));
  1076. }
  1077. Y_UNIT_TEST_LLVM(TestCompares) {
  1078. TSetup<LLVM> setup;
  1079. TProgramBuilder& pb = *setup.PgmBuilder;
  1080. const auto data1l = pb.NewDecimalLiteral(-7, 10, 0);
  1081. const auto data2l = pb.NewDecimalLiteral(3, 10, 0);
  1082. const auto data3l = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 10, 0);
  1083. const auto data4l = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 10, 0);
  1084. const auto data5l = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 10, 0);
  1085. const auto data1r = pb.NewDecimalLiteral(-700, 7, 2);
  1086. const auto data2r = pb.NewDecimalLiteral(300, 7, 2);
  1087. const auto data3r = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 7, 2);
  1088. const auto data4r = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 7, 2);
  1089. const auto data5r = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 7, 2);
  1090. auto pairType = pb.NewTupleType({pb.NewDecimalType(10, 0), pb.NewDecimalType(7, 2)});
  1091. const auto list = pb.NewList(pairType, {
  1092. pb.NewTuple({data1l, data1r}),
  1093. pb.NewTuple({data1l, data2r}),
  1094. pb.NewTuple({data1l, data3r}),
  1095. pb.NewTuple({data1l, data4r}),
  1096. pb.NewTuple({data1l, data5r}),
  1097. pb.NewTuple({data2l, data1r}),
  1098. pb.NewTuple({data2l, data2r}),
  1099. pb.NewTuple({data2l, data3r}),
  1100. pb.NewTuple({data2l, data4r}),
  1101. pb.NewTuple({data2l, data5r}),
  1102. pb.NewTuple({data3l, data1r}),
  1103. pb.NewTuple({data3l, data2r}),
  1104. pb.NewTuple({data3l, data3r}),
  1105. pb.NewTuple({data3l, data4r}),
  1106. pb.NewTuple({data3l, data5r}),
  1107. pb.NewTuple({data4l, data1r}),
  1108. pb.NewTuple({data4l, data2r}),
  1109. pb.NewTuple({data4l, data3r}),
  1110. pb.NewTuple({data4l, data4r}),
  1111. pb.NewTuple({data4l, data5r}),
  1112. pb.NewTuple({data5l, data1r}),
  1113. pb.NewTuple({data5l, data2r}),
  1114. pb.NewTuple({data5l, data3r}),
  1115. pb.NewTuple({data5l, data4r}),
  1116. pb.NewTuple({data5l, data5r}),
  1117. });
  1118. const auto pgmReturn = pb.Map(list,
  1119. [&](TRuntimeNode item) {
  1120. return pb.NewTuple({
  1121. pb.Equals(pb.Nth(item, 0), pb.Nth(item, 1)),
  1122. pb.NotEquals(pb.Nth(item, 0), pb.Nth(item, 1)),
  1123. pb.Less(pb.Nth(item, 0), pb.Nth(item, 1)),
  1124. pb.LessOrEqual(pb.Nth(item, 0), pb.Nth(item, 1)),
  1125. pb.Greater(pb.Nth(item, 0), pb.Nth(item, 1)),
  1126. pb.GreaterOrEqual(pb.Nth(item, 0), pb.Nth(item, 1))
  1127. });
  1128. });
  1129. const auto graph = setup.BuildGraph(pgmReturn);
  1130. const auto iterator = graph->GetValue().GetListIterator();
  1131. NUdf::TUnboxedValue item;
  1132. UNIT_ASSERT(iterator.Next(item));
  1133. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1134. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1135. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1136. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1137. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1138. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1139. UNIT_ASSERT(iterator.Next(item));
  1140. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1141. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1142. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1143. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1144. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1145. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1146. UNIT_ASSERT(iterator.Next(item));
  1147. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1148. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1149. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1150. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1151. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1152. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1153. UNIT_ASSERT(iterator.Next(item));
  1154. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1155. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1156. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1157. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1158. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1159. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1160. UNIT_ASSERT(iterator.Next(item));
  1161. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1162. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1163. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1164. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1165. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1166. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1167. UNIT_ASSERT(iterator.Next(item));
  1168. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1169. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1170. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1171. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1172. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1173. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1174. UNIT_ASSERT(iterator.Next(item));
  1175. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1176. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1177. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1178. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1179. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1180. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1181. UNIT_ASSERT(iterator.Next(item));
  1182. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1183. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1184. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1185. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1186. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1187. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1188. UNIT_ASSERT(iterator.Next(item));
  1189. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1190. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1191. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1192. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1193. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1194. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1195. UNIT_ASSERT(iterator.Next(item));
  1196. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1197. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1198. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1199. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1200. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1201. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1202. UNIT_ASSERT(iterator.Next(item));
  1203. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1204. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1205. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1206. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1207. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1208. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1209. UNIT_ASSERT(iterator.Next(item));
  1210. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1211. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1212. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1213. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1214. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1215. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1216. UNIT_ASSERT(iterator.Next(item));
  1217. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1218. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1219. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1220. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1221. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1222. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1223. UNIT_ASSERT(iterator.Next(item));
  1224. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1225. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1226. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1227. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1228. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1229. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1230. UNIT_ASSERT(iterator.Next(item));
  1231. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1232. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1233. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1234. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1235. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1236. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1237. UNIT_ASSERT(iterator.Next(item));
  1238. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1239. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1240. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1241. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1242. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1243. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1244. UNIT_ASSERT(iterator.Next(item));
  1245. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1246. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1247. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1248. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1249. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1250. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1251. UNIT_ASSERT(iterator.Next(item));
  1252. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1253. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1254. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1255. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1256. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1257. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1258. UNIT_ASSERT(iterator.Next(item));
  1259. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1260. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1261. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1262. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1263. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1264. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1265. UNIT_ASSERT(iterator.Next(item));
  1266. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1267. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1268. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1269. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1270. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1271. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1272. UNIT_ASSERT(iterator.Next(item));
  1273. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1274. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1275. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1276. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1277. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1278. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1279. UNIT_ASSERT(iterator.Next(item));
  1280. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1281. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1282. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1283. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1284. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1285. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1286. UNIT_ASSERT(iterator.Next(item));
  1287. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1288. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1289. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1290. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1291. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1292. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1293. UNIT_ASSERT(iterator.Next(item));
  1294. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1295. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1296. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1297. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1298. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1299. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1300. UNIT_ASSERT(iterator.Next(item));
  1301. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1302. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1303. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1304. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1305. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1306. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1307. UNIT_ASSERT(!iterator.Next(item));
  1308. UNIT_ASSERT(!iterator.Next(item));
  1309. }
  1310. Y_UNIT_TEST_LLVM(TestComparesWithIntegral) {
  1311. TSetup<LLVM> setup;
  1312. TProgramBuilder& pb = *setup.PgmBuilder;
  1313. auto optType = pb.NewOptionalType(pb.NewDataType(NUdf::TDataType<i64>::Id));
  1314. const auto data1l = pb.NewOptional(pb.NewDataLiteral<i64>(-7LL));
  1315. const auto data2l = pb.NewOptional(pb.NewDataLiteral<i64>(3LL));
  1316. const auto data3l = pb.NewEmptyOptional(optType);
  1317. const auto data4l = pb.NewOptional(pb.NewDataLiteral<i64>(std::numeric_limits<i64>::min()));
  1318. const auto data5l = pb.NewOptional(pb.NewDataLiteral<i64>(std::numeric_limits<i64>::max()));
  1319. const auto data1r = pb.NewDecimalLiteral(-7000000000000000000LL, 20, 18);
  1320. const auto data2r = pb.NewDecimalLiteral(3000000000000000000LL, 20, 18);
  1321. const auto data3r = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 20, 18);
  1322. const auto data4r = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 20, 18);
  1323. const auto data5r = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 20, 18);
  1324. auto pairType = pb.NewTupleType({optType, pb.NewDecimalType(20, 18)});
  1325. const auto list = pb.NewList(pairType, {
  1326. pb.NewTuple({data1l, data1r}),
  1327. pb.NewTuple({data1l, data2r}),
  1328. pb.NewTuple({data1l, data3r}),
  1329. pb.NewTuple({data1l, data4r}),
  1330. pb.NewTuple({data1l, data5r}),
  1331. pb.NewTuple({data2l, data1r}),
  1332. pb.NewTuple({data2l, data2r}),
  1333. pb.NewTuple({data2l, data3r}),
  1334. pb.NewTuple({data2l, data4r}),
  1335. pb.NewTuple({data2l, data5r}),
  1336. pb.NewTuple({data3l, data1r}),
  1337. pb.NewTuple({data3l, data2r}),
  1338. pb.NewTuple({data3l, data3r}),
  1339. pb.NewTuple({data3l, data4r}),
  1340. pb.NewTuple({data3l, data5r}),
  1341. pb.NewTuple({data4l, data1r}),
  1342. pb.NewTuple({data4l, data2r}),
  1343. pb.NewTuple({data4l, data3r}),
  1344. pb.NewTuple({data4l, data4r}),
  1345. pb.NewTuple({data4l, data5r}),
  1346. pb.NewTuple({data5l, data1r}),
  1347. pb.NewTuple({data5l, data2r}),
  1348. pb.NewTuple({data5l, data3r}),
  1349. pb.NewTuple({data5l, data4r}),
  1350. pb.NewTuple({data5l, data5r}),
  1351. });
  1352. const auto pgmReturn = pb.Map(list,
  1353. [&](TRuntimeNode item) {
  1354. return pb.NewTuple({
  1355. pb.Equals(pb.Nth(item, 0), pb.Nth(item, 1)),
  1356. pb.NotEquals(pb.Nth(item, 0), pb.Nth(item, 1)),
  1357. pb.Less(pb.Nth(item, 0), pb.Nth(item, 1)),
  1358. pb.LessOrEqual(pb.Nth(item, 0), pb.Nth(item, 1)),
  1359. pb.Greater(pb.Nth(item, 0), pb.Nth(item, 1)),
  1360. pb.GreaterOrEqual(pb.Nth(item, 0), pb.Nth(item, 1))
  1361. });
  1362. });
  1363. const auto graph = setup.BuildGraph(pgmReturn);
  1364. const auto iterator = graph->GetValue().GetListIterator();
  1365. NUdf::TUnboxedValue item;
  1366. UNIT_ASSERT(iterator.Next(item));
  1367. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1368. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1369. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1370. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1371. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1372. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1373. UNIT_ASSERT(iterator.Next(item));
  1374. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1375. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1376. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1377. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1378. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1379. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1380. UNIT_ASSERT(iterator.Next(item));
  1381. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1382. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1383. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1384. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1385. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1386. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1387. UNIT_ASSERT(iterator.Next(item));
  1388. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1389. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1390. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1391. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1392. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1393. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1394. UNIT_ASSERT(iterator.Next(item));
  1395. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1396. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1397. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1398. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1399. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1400. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1401. UNIT_ASSERT(iterator.Next(item));
  1402. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1403. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1404. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1405. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1406. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1407. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1408. UNIT_ASSERT(iterator.Next(item));
  1409. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1410. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1411. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1412. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1413. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1414. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1415. UNIT_ASSERT(iterator.Next(item));
  1416. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1417. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1418. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1419. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1420. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1421. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1422. UNIT_ASSERT(iterator.Next(item));
  1423. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1424. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1425. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1426. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1427. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1428. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1429. UNIT_ASSERT(iterator.Next(item));
  1430. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1431. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1432. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1433. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1434. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1435. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1436. UNIT_ASSERT(iterator.Next(item));
  1437. UNIT_ASSERT(!item.GetElement(0)); // ==
  1438. UNIT_ASSERT(!item.GetElement(1)); // !=
  1439. UNIT_ASSERT(!item.GetElement(2)); // <
  1440. UNIT_ASSERT(!item.GetElement(3)); // <=
  1441. UNIT_ASSERT(!item.GetElement(4)); // >
  1442. UNIT_ASSERT(!item.GetElement(5)); // >=
  1443. UNIT_ASSERT(iterator.Next(item));
  1444. UNIT_ASSERT(!item.GetElement(0)); // ==
  1445. UNIT_ASSERT(!item.GetElement(1)); // !=
  1446. UNIT_ASSERT(!item.GetElement(2)); // <
  1447. UNIT_ASSERT(!item.GetElement(3)); // <=
  1448. UNIT_ASSERT(!item.GetElement(4)); // >
  1449. UNIT_ASSERT(!item.GetElement(5)); // >=
  1450. UNIT_ASSERT(iterator.Next(item));
  1451. UNIT_ASSERT(!item.GetElement(0)); // ==
  1452. UNIT_ASSERT(!item.GetElement(1)); // !=
  1453. UNIT_ASSERT(!item.GetElement(2)); // <
  1454. UNIT_ASSERT(!item.GetElement(3)); // <=
  1455. UNIT_ASSERT(!item.GetElement(4)); // >
  1456. UNIT_ASSERT(!item.GetElement(5)); // >=
  1457. UNIT_ASSERT(iterator.Next(item));
  1458. UNIT_ASSERT(!item.GetElement(0)); // ==
  1459. UNIT_ASSERT(!item.GetElement(1)); // !=
  1460. UNIT_ASSERT(!item.GetElement(2)); // <
  1461. UNIT_ASSERT(!item.GetElement(3)); // <=
  1462. UNIT_ASSERT(!item.GetElement(4)); // >
  1463. UNIT_ASSERT(!item.GetElement(5)); // >=
  1464. UNIT_ASSERT(iterator.Next(item));
  1465. UNIT_ASSERT(!item.GetElement(0)); // ==
  1466. UNIT_ASSERT(!item.GetElement(1)); // !=
  1467. UNIT_ASSERT(!item.GetElement(2)); // <
  1468. UNIT_ASSERT(!item.GetElement(3)); // <=
  1469. UNIT_ASSERT(!item.GetElement(4)); // >
  1470. UNIT_ASSERT(!item.GetElement(5)); // >=
  1471. UNIT_ASSERT(iterator.Next(item));
  1472. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1473. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1474. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1475. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1476. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1477. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1478. UNIT_ASSERT(iterator.Next(item));
  1479. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1480. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1481. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1482. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1483. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1484. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1485. UNIT_ASSERT(iterator.Next(item));
  1486. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1487. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1488. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1489. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1490. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1491. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1492. UNIT_ASSERT(iterator.Next(item));
  1493. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1494. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1495. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1496. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1497. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1498. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1499. UNIT_ASSERT(iterator.Next(item));
  1500. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1501. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1502. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1503. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1504. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1505. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1506. UNIT_ASSERT(iterator.Next(item));
  1507. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1508. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1509. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1510. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1511. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1512. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1513. UNIT_ASSERT(iterator.Next(item));
  1514. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1515. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1516. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1517. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1518. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1519. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1520. UNIT_ASSERT(iterator.Next(item));
  1521. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1522. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1523. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1524. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1525. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1526. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1527. UNIT_ASSERT(iterator.Next(item));
  1528. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1529. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1530. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1531. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1532. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1533. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1534. UNIT_ASSERT(iterator.Next(item));
  1535. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1536. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1537. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1538. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1539. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1540. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1541. UNIT_ASSERT(!iterator.Next(item));
  1542. UNIT_ASSERT(!iterator.Next(item));
  1543. }
  1544. Y_UNIT_TEST_LLVM(TestAggrCompares) {
  1545. TSetup<LLVM> setup;
  1546. TProgramBuilder& pb = *setup.PgmBuilder;
  1547. const auto data1 = pb.NewDecimalLiteral(-7, 10, 0);
  1548. const auto data2 = pb.NewDecimalLiteral(3, 10, 0);
  1549. const auto data3 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 10, 0);
  1550. const auto data4 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 10, 0);
  1551. const auto data5 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 10, 0);
  1552. auto pairType = pb.NewTupleType({pb.NewDecimalType(10, 0), pb.NewDecimalType(10, 0)});
  1553. const auto list = pb.NewList(pairType, {
  1554. pb.NewTuple({data1, data1}),
  1555. pb.NewTuple({data1, data2}),
  1556. pb.NewTuple({data1, data3}),
  1557. pb.NewTuple({data1, data4}),
  1558. pb.NewTuple({data1, data5}),
  1559. pb.NewTuple({data2, data1}),
  1560. pb.NewTuple({data2, data2}),
  1561. pb.NewTuple({data2, data3}),
  1562. pb.NewTuple({data2, data4}),
  1563. pb.NewTuple({data2, data5}),
  1564. pb.NewTuple({data3, data1}),
  1565. pb.NewTuple({data3, data2}),
  1566. pb.NewTuple({data3, data3}),
  1567. pb.NewTuple({data3, data4}),
  1568. pb.NewTuple({data3, data5}),
  1569. pb.NewTuple({data4, data1}),
  1570. pb.NewTuple({data4, data2}),
  1571. pb.NewTuple({data4, data3}),
  1572. pb.NewTuple({data4, data4}),
  1573. pb.NewTuple({data4, data5}),
  1574. pb.NewTuple({data5, data1}),
  1575. pb.NewTuple({data5, data2}),
  1576. pb.NewTuple({data5, data3}),
  1577. pb.NewTuple({data5, data4}),
  1578. pb.NewTuple({data5, data5}),
  1579. });
  1580. const auto pgmReturn = pb.Map(list,
  1581. [&](TRuntimeNode item) {
  1582. return pb.NewTuple({
  1583. pb.AggrEquals(pb.Nth(item, 0), pb.Nth(item, 1)),
  1584. pb.AggrNotEquals(pb.Nth(item, 0), pb.Nth(item, 1)),
  1585. pb.AggrLess(pb.Nth(item, 0), pb.Nth(item, 1)),
  1586. pb.AggrLessOrEqual(pb.Nth(item, 0), pb.Nth(item, 1)),
  1587. pb.AggrGreater(pb.Nth(item, 0), pb.Nth(item, 1)),
  1588. pb.AggrGreaterOrEqual(pb.Nth(item, 0), pb.Nth(item, 1))
  1589. });
  1590. });
  1591. const auto graph = setup.BuildGraph(pgmReturn);
  1592. const auto iterator = graph->GetValue().GetListIterator();
  1593. NUdf::TUnboxedValue item;
  1594. UNIT_ASSERT(iterator.Next(item));
  1595. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1596. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1597. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1598. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1599. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1600. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1601. UNIT_ASSERT(iterator.Next(item));
  1602. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1603. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1604. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1605. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1606. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1607. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1608. UNIT_ASSERT(iterator.Next(item));
  1609. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1610. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1611. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1612. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1613. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1614. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1615. UNIT_ASSERT(iterator.Next(item));
  1616. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1617. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1618. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1619. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1620. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1621. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1622. UNIT_ASSERT(iterator.Next(item));
  1623. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1624. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1625. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1626. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1627. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1628. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1629. UNIT_ASSERT(iterator.Next(item));
  1630. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1631. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1632. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1633. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1634. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1635. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1636. UNIT_ASSERT(iterator.Next(item));
  1637. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1638. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1639. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1640. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1641. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1642. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1643. UNIT_ASSERT(iterator.Next(item));
  1644. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1645. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1646. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1647. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1648. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1649. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1650. UNIT_ASSERT(iterator.Next(item));
  1651. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1652. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1653. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1654. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1655. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1656. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1657. UNIT_ASSERT(iterator.Next(item));
  1658. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1659. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1660. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1661. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1662. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1663. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1664. UNIT_ASSERT(iterator.Next(item));
  1665. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1666. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1667. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1668. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1669. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1670. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1671. UNIT_ASSERT(iterator.Next(item));
  1672. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1673. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1674. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1675. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1676. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1677. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1678. UNIT_ASSERT(iterator.Next(item));
  1679. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1680. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1681. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1682. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1683. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1684. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1685. UNIT_ASSERT(iterator.Next(item));
  1686. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1687. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1688. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1689. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1690. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1691. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1692. UNIT_ASSERT(iterator.Next(item));
  1693. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1694. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1695. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1696. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1697. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1698. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1699. UNIT_ASSERT(iterator.Next(item));
  1700. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1701. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1702. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1703. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1704. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1705. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1706. UNIT_ASSERT(iterator.Next(item));
  1707. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1708. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1709. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1710. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1711. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1712. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1713. UNIT_ASSERT(iterator.Next(item));
  1714. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1715. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1716. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1717. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1718. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1719. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1720. UNIT_ASSERT(iterator.Next(item));
  1721. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1722. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1723. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1724. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1725. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1726. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1727. UNIT_ASSERT(iterator.Next(item));
  1728. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1729. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1730. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1731. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1732. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1733. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1734. UNIT_ASSERT(iterator.Next(item));
  1735. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1736. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1737. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1738. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1739. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1740. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1741. UNIT_ASSERT(iterator.Next(item));
  1742. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1743. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1744. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1745. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1746. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1747. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1748. UNIT_ASSERT(iterator.Next(item));
  1749. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1750. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1751. UNIT_ASSERT(item.GetElement(2).template Get<bool>()); // <
  1752. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1753. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1754. UNIT_ASSERT(!item.GetElement(5).template Get<bool>()); // >=
  1755. UNIT_ASSERT(iterator.Next(item));
  1756. UNIT_ASSERT(!item.GetElement(0).template Get<bool>()); // ==
  1757. UNIT_ASSERT(item.GetElement(1).template Get<bool>()); // !=
  1758. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1759. UNIT_ASSERT(!item.GetElement(3).template Get<bool>()); // <=
  1760. UNIT_ASSERT(item.GetElement(4).template Get<bool>()); // >
  1761. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1762. UNIT_ASSERT(iterator.Next(item));
  1763. UNIT_ASSERT(item.GetElement(0).template Get<bool>()); // ==
  1764. UNIT_ASSERT(!item.GetElement(1).template Get<bool>()); // !=
  1765. UNIT_ASSERT(!item.GetElement(2).template Get<bool>()); // <
  1766. UNIT_ASSERT(item.GetElement(3).template Get<bool>()); // <=
  1767. UNIT_ASSERT(!item.GetElement(4).template Get<bool>()); // >
  1768. UNIT_ASSERT(item.GetElement(5).template Get<bool>()); // >=
  1769. UNIT_ASSERT(!iterator.Next(item));
  1770. UNIT_ASSERT(!iterator.Next(item));
  1771. }
  1772. Y_UNIT_TEST_LLVM(TestIncDec) {
  1773. TSetup<LLVM> setup;
  1774. TProgramBuilder& pb = *setup.PgmBuilder;
  1775. const auto data1 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 4, 1);
  1776. const auto data2 = pb.NewDecimalLiteral(-9999, 4, 1);
  1777. const auto data3 = pb.NewDecimalLiteral(-7, 4, 1);
  1778. const auto data4 = pb.NewDecimalLiteral(0, 4, 1);
  1779. const auto data5 = pb.NewDecimalLiteral(13, 4, 1);
  1780. const auto data6 = pb.NewDecimalLiteral(9999, 4, 1);
  1781. const auto data7 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 4, 1);
  1782. const auto data8 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 4, 1);
  1783. const auto list = pb.NewList(pb.NewDecimalType(4, 1), {data1, data2, data3, data4, data5, data6, data7, data8});
  1784. const auto pgmReturn = pb.Map(list,
  1785. [&](TRuntimeNode item) {
  1786. return pb.NewTuple({pb.Increment(item), pb.Decrement(item)});
  1787. });
  1788. const auto graph = setup.BuildGraph(pgmReturn);
  1789. const auto iterator = graph->GetValue().GetListIterator();
  1790. NUdf::TUnboxedValue item;
  1791. UNIT_ASSERT(iterator.Next(item));
  1792. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  1793. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  1794. UNIT_ASSERT(iterator.Next(item));
  1795. UNIT_ASSERT(item.GetElement(0).GetInt128() == -9998);
  1796. UNIT_ASSERT(item.GetElement(1).GetInt128() == -NYql::NDecimal::Inf());
  1797. UNIT_ASSERT(iterator.Next(item));
  1798. UNIT_ASSERT(item.GetElement(0).GetInt128() == -6);
  1799. UNIT_ASSERT(item.GetElement(1).GetInt128() == -8);
  1800. UNIT_ASSERT(iterator.Next(item));
  1801. UNIT_ASSERT(item.GetElement(0).GetInt128() == +1);
  1802. UNIT_ASSERT(item.GetElement(1).GetInt128() == -1);
  1803. UNIT_ASSERT(iterator.Next(item));
  1804. UNIT_ASSERT(item.GetElement(0).GetInt128() == 14);
  1805. UNIT_ASSERT(item.GetElement(1).GetInt128() == 12);
  1806. UNIT_ASSERT(iterator.Next(item));
  1807. UNIT_ASSERT(item.GetElement(0).GetInt128() == +NYql::NDecimal::Inf());
  1808. UNIT_ASSERT(item.GetElement(1).GetInt128() == 9998);
  1809. UNIT_ASSERT(iterator.Next(item));
  1810. UNIT_ASSERT(item.GetElement(0).GetInt128() == +NYql::NDecimal::Inf());
  1811. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  1812. UNIT_ASSERT(iterator.Next(item));
  1813. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1814. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1815. UNIT_ASSERT(!iterator.Next(item));
  1816. UNIT_ASSERT(!iterator.Next(item));
  1817. }
  1818. Y_UNIT_TEST_LLVM(TestMinusAbs) {
  1819. TSetup<LLVM> setup;
  1820. TProgramBuilder& pb = *setup.PgmBuilder;
  1821. const auto data1 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 10, 1);
  1822. const auto data3 = pb.NewDecimalLiteral(-7, 10, 1);
  1823. const auto data4 = pb.NewDecimalLiteral(0, 10, 1);
  1824. const auto data5 = pb.NewDecimalLiteral(13, 10, 1);
  1825. const auto data7 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 10, 1);
  1826. const auto data8 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 10, 1);
  1827. const auto list = pb.NewList(pb.NewDecimalType(10, 1), {data1, data3, data4, data5, data7, data8});
  1828. const auto pgmReturn = pb.Map(list,
  1829. [&](TRuntimeNode item) {
  1830. return pb.NewTuple({pb.Minus(item), pb.Abs(item)});
  1831. });
  1832. const auto graph = setup.BuildGraph(pgmReturn);
  1833. const auto iterator = graph->GetValue().GetListIterator();
  1834. NUdf::TUnboxedValue item;
  1835. UNIT_ASSERT(iterator.Next(item));
  1836. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Inf());
  1837. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Inf());
  1838. UNIT_ASSERT(iterator.Next(item));
  1839. UNIT_ASSERT(item.GetElement(0).GetInt128() == 7);
  1840. UNIT_ASSERT(item.GetElement(1).GetInt128() == 7);
  1841. UNIT_ASSERT(iterator.Next(item));
  1842. UNIT_ASSERT(item.GetElement(0).GetInt128() == 0);
  1843. UNIT_ASSERT(item.GetElement(1).GetInt128() == 0);
  1844. UNIT_ASSERT(iterator.Next(item));
  1845. UNIT_ASSERT(item.GetElement(0).GetInt128() == -13);
  1846. UNIT_ASSERT(item.GetElement(1).GetInt128() == +13);
  1847. UNIT_ASSERT(iterator.Next(item));
  1848. UNIT_ASSERT(item.GetElement(0).GetInt128() == -NYql::NDecimal::Inf());
  1849. UNIT_ASSERT(item.GetElement(1).GetInt128() == +NYql::NDecimal::Inf());
  1850. UNIT_ASSERT(iterator.Next(item));
  1851. UNIT_ASSERT(item.GetElement(0).GetInt128() == NYql::NDecimal::Nan());
  1852. UNIT_ASSERT(item.GetElement(1).GetInt128() == NYql::NDecimal::Nan());
  1853. UNIT_ASSERT(!iterator.Next(item));
  1854. UNIT_ASSERT(!iterator.Next(item));
  1855. }
  1856. Y_UNIT_TEST_LLVM(TestFromString) {
  1857. TSetup<LLVM> setup;
  1858. TProgramBuilder& pb = *setup.PgmBuilder;
  1859. const auto data0 = pb.NewDataLiteral<NUdf::EDataSlot::String>("0.0");
  1860. const auto data1 = pb.NewDataLiteral<NUdf::EDataSlot::String>("NAN");
  1861. const auto data2 = pb.NewDataLiteral<NUdf::EDataSlot::String>("1.0");
  1862. const auto data3 = pb.NewDataLiteral<NUdf::EDataSlot::String>("-.1");
  1863. const auto data4 = pb.NewDataLiteral<NUdf::EDataSlot::String>("3.1415926");
  1864. const auto data5 = pb.NewDataLiteral<NUdf::EDataSlot::String>("+inf");
  1865. const auto data6 = pb.NewDataLiteral<NUdf::EDataSlot::String>("-INF");
  1866. const auto data7 = pb.NewDataLiteral<NUdf::EDataSlot::String>(".123E+2");
  1867. const auto data8 = pb.NewDataLiteral<NUdf::EDataSlot::String>("56.78e-3");
  1868. const auto type = pb.NewDataType(NUdf::TDataType<char*>::Id);
  1869. const auto list = pb.NewList(type, {data0, data1, data2, data3, data4, data5, data6, data7, data8});
  1870. const auto pgmReturn = pb.Map(list,
  1871. [&](TRuntimeNode item) {
  1872. return pb.StrictFromString(item, pb.NewDecimalType(10, 7));
  1873. });
  1874. const auto graph = setup.BuildGraph(pgmReturn);
  1875. const auto iterator = graph->GetValue().GetListIterator();
  1876. NUdf::TUnboxedValue item;
  1877. UNIT_ASSERT(iterator.Next(item));
  1878. UNIT_ASSERT(item.GetInt128() == 0);
  1879. UNIT_ASSERT(iterator.Next(item));
  1880. UNIT_ASSERT(item.GetInt128() == NYql::NDecimal::Nan());
  1881. UNIT_ASSERT(iterator.Next(item));
  1882. UNIT_ASSERT(item.GetInt128() == 10000000);
  1883. UNIT_ASSERT(iterator.Next(item));
  1884. UNIT_ASSERT(item.GetInt128() == -1000000);
  1885. UNIT_ASSERT(iterator.Next(item));
  1886. UNIT_ASSERT(item.GetInt128() == 31415926);
  1887. UNIT_ASSERT(iterator.Next(item));
  1888. UNIT_ASSERT(item.GetInt128() == +NYql::NDecimal::Inf());
  1889. UNIT_ASSERT(iterator.Next(item));
  1890. UNIT_ASSERT(item.GetInt128() == -NYql::NDecimal::Inf());
  1891. UNIT_ASSERT(iterator.Next(item));
  1892. UNIT_ASSERT(item.GetInt128() == 123000000);
  1893. UNIT_ASSERT(iterator.Next(item));
  1894. UNIT_ASSERT(item.GetInt128() == 567800);
  1895. UNIT_ASSERT(!iterator.Next(item));
  1896. UNIT_ASSERT(!iterator.Next(item));
  1897. }
  1898. Y_UNIT_TEST_LLVM(TestToString) {
  1899. TSetup<LLVM> setup;
  1900. TProgramBuilder& pb = *setup.PgmBuilder;
  1901. const auto data0 = pb.NewDecimalLiteral(0, 10, 7);
  1902. const auto data1 = pb.NewDecimalLiteral(NYql::NDecimal::Nan(), 10, 7);
  1903. const auto data2 = pb.NewDecimalLiteral(10000000, 10, 7);
  1904. const auto data3 = pb.NewDecimalLiteral(-1000000, 10, 7);
  1905. const auto data4 = pb.NewDecimalLiteral(31415926, 10, 7);
  1906. const auto data5 = pb.NewDecimalLiteral(+NYql::NDecimal::Inf(), 10, 7);
  1907. const auto data6 = pb.NewDecimalLiteral(-NYql::NDecimal::Inf(), 10, 7);
  1908. const auto type = pb.NewDecimalType(10, 7);
  1909. const auto list = pb.NewList(type, {data0, data1, data2, data3, data4, data5, data6});
  1910. const auto pgmReturn = pb.Map(list,
  1911. [&](TRuntimeNode item) {
  1912. return pb.ToString(item);
  1913. });
  1914. const auto graph = setup.BuildGraph(pgmReturn);
  1915. const auto iterator = graph->GetValue().GetListIterator();
  1916. NUdf::TUnboxedValue item;
  1917. UNIT_ASSERT(iterator.Next(item));
  1918. UNBOXED_VALUE_STR_EQUAL(item, "0");
  1919. UNIT_ASSERT(iterator.Next(item));
  1920. UNBOXED_VALUE_STR_EQUAL(item, "nan");
  1921. UNIT_ASSERT(iterator.Next(item));
  1922. UNBOXED_VALUE_STR_EQUAL(item, "1");
  1923. UNIT_ASSERT(iterator.Next(item));
  1924. UNBOXED_VALUE_STR_EQUAL(item, "-0.1");
  1925. UNIT_ASSERT(iterator.Next(item));
  1926. UNBOXED_VALUE_STR_EQUAL(item, "3.1415926");
  1927. UNIT_ASSERT(iterator.Next(item));
  1928. UNBOXED_VALUE_STR_EQUAL(item, "inf");
  1929. UNIT_ASSERT(iterator.Next(item));
  1930. UNBOXED_VALUE_STR_EQUAL(item, "-inf");
  1931. UNIT_ASSERT(!iterator.Next(item));
  1932. UNIT_ASSERT(!iterator.Next(item));
  1933. }
  1934. Y_UNIT_TEST_LLVM(TestFromStringToDouble) {
  1935. TSetup<LLVM> setup;
  1936. TProgramBuilder& pb = *setup.PgmBuilder;
  1937. const auto type = pb.NewDataType(NUdf::TDataType<char*>::Id);
  1938. const auto data0 = pb.NewDataLiteral<NUdf::EDataSlot::String>("0");
  1939. const auto data1 = pb.NewDataLiteral<NUdf::EDataSlot::String>("+3.332873");
  1940. const auto data2 = pb.NewDataLiteral<NUdf::EDataSlot::String>("-3.332873");
  1941. const auto data3 = pb.NewDataLiteral<NUdf::EDataSlot::String>("+3.1415926");
  1942. const auto data4 = pb.NewDataLiteral<NUdf::EDataSlot::String>("-3.1415926");
  1943. const auto list = pb.NewList(type, {data0, data1, data2, data3, data4});
  1944. const auto pgmReturn = pb.Map(list,
  1945. [&](TRuntimeNode item) {
  1946. return pb.Convert(pb.FromString(item, pb.NewDecimalType(35,25)), pb.NewDataType(NUdf::TDataType<double>::Id));
  1947. });
  1948. const auto graph = setup.BuildGraph(pgmReturn);
  1949. const auto iterator = graph->GetValue().GetListIterator();
  1950. NUdf::TUnboxedValue item;
  1951. UNIT_ASSERT(iterator.Next(item));
  1952. UNIT_ASSERT_VALUES_EQUAL(item.Get<double>(), 0.);
  1953. UNIT_ASSERT(iterator.Next(item));
  1954. UNIT_ASSERT_VALUES_EQUAL(item.Get<double>(), +3.332873);
  1955. UNIT_ASSERT(iterator.Next(item));
  1956. UNIT_ASSERT_VALUES_EQUAL(item.Get<double>(), -3.332873);
  1957. UNIT_ASSERT(iterator.Next(item));
  1958. UNIT_ASSERT_VALUES_EQUAL(item.Get<double>(), +3.1415926);
  1959. UNIT_ASSERT(iterator.Next(item));
  1960. UNIT_ASSERT_VALUES_EQUAL(item.Get<double>(), -3.1415926);
  1961. UNIT_ASSERT(!iterator.Next(item));
  1962. UNIT_ASSERT(!iterator.Next(item));
  1963. }
  1964. Y_UNIT_TEST_LLVM(TestFromUtf8ToFloat) {
  1965. TSetup<LLVM> setup;
  1966. TProgramBuilder& pb = *setup.PgmBuilder;
  1967. const auto type = pb.NewDataType(NUdf::TDataType<NUdf::TUtf8>::Id);
  1968. const auto data0 = pb.NewDataLiteral<NUdf::EDataSlot::Utf8>("0");
  1969. const auto data1 = pb.NewDataLiteral<NUdf::EDataSlot::Utf8>("+24.75");
  1970. const auto data2 = pb.NewDataLiteral<NUdf::EDataSlot::Utf8>("-24.75");
  1971. const auto data3 = pb.NewDataLiteral<NUdf::EDataSlot::Utf8>("+42.42");
  1972. const auto data4 = pb.NewDataLiteral<NUdf::EDataSlot::Utf8>("-42.42");
  1973. const auto list = pb.NewList(type, {data0, data1, data2, data3, data4});
  1974. const auto pgmReturn = pb.Map(list,
  1975. [&](TRuntimeNode item) {
  1976. return pb.Convert(pb.FromString(item, pb.NewDecimalType(35,25)), pb.NewDataType(NUdf::TDataType<float>::Id));
  1977. });
  1978. const auto graph = setup.BuildGraph(pgmReturn);
  1979. const auto iterator = graph->GetValue().GetListIterator();
  1980. NUdf::TUnboxedValue item;
  1981. UNIT_ASSERT(iterator.Next(item));
  1982. UNIT_ASSERT_VALUES_EQUAL(item.Get<float>(), 0.f);
  1983. UNIT_ASSERT(iterator.Next(item));
  1984. UNIT_ASSERT_VALUES_EQUAL(item.Get<float>(), +24.75f);
  1985. UNIT_ASSERT(iterator.Next(item));
  1986. UNIT_ASSERT_VALUES_EQUAL(item.Get<float>(), -24.75f);
  1987. UNIT_ASSERT(iterator.Next(item));
  1988. UNIT_ASSERT_VALUES_EQUAL(item.Get<float>(), +42.42f);
  1989. UNIT_ASSERT(iterator.Next(item));
  1990. UNIT_ASSERT_VALUES_EQUAL(item.Get<float>(), -42.42f);
  1991. UNIT_ASSERT(!iterator.Next(item));
  1992. UNIT_ASSERT(!iterator.Next(item));
  1993. }
  1994. }
  1995. }
  1996. }