5
5
#include < ydb/library/yql/minikql/mkql_string_util.h>
6
6
7
7
#include < ydb/library/yql/minikql/computation/mkql_computation_node_holders.h>
8
+ #include < ydb/library/yql/minikql/computation/mock_spiller_factory_ut.h>
8
9
9
10
#include < cstring>
10
- #include < random>
11
11
#include < algorithm>
12
12
13
13
namespace NKikimr {
@@ -30,6 +30,7 @@ using TBaseComputation = TMutableComputationNode<TTestStreamWrapper>;
30
30
{}
31
31
private:
32
32
NUdf::EFetchStatus Fetch (NUdf::TUnboxedValue& result) override {
33
+
33
34
constexpr auto size = Y_ARRAY_SIZE (g_TestYieldStreamData);
34
35
if (Index == size) {
35
36
return NUdf::EFetchStatus::Finish;
@@ -47,6 +48,7 @@ using TBaseComputation = TMutableComputationNode<TTestStreamWrapper>;
47
48
items[1 ] = NUdf::TUnboxedValuePod (MakeString (ToString (val)));
48
49
49
50
++Index;
51
+
50
52
return NUdf::EFetchStatus::Ok;
51
53
}
52
54
@@ -996,8 +998,13 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideCombinerPerfTest) {
996
998
#endif
997
999
#if !defined(MKQL_RUNTIME_VERSION) || MKQL_RUNTIME_VERSION >= 29u
998
1000
Y_UNIT_TEST_SUITE (TMiniKQLWideLastCombinerTest) {
999
- Y_UNIT_TEST_LLVM (TestLongStringsRefCounting) {
1000
- TSetup<LLVM> setup;
1001
+ Y_UNIT_TEST_LLVM_SPILLING (TestLongStringsRefCounting) {
1002
+ // Currently LLVM version doesn't support spilling.
1003
+ if (LLVM && SPILLING) return ;
1004
+ // callable WideLastCombinerWithSpilling was introduced in 49 version of runtime
1005
+ if (MKQL_RUNTIME_VERSION < 49U && SPILLING) return ;
1006
+
1007
+ TSetup<LLVM, SPILLING> setup;
1001
1008
TProgramBuilder& pb = *setup.PgmBuilder ;
1002
1009
1003
1010
const auto dataType = pb.NewDataType (NUdf::TDataType<const char *>::Id);
@@ -1035,7 +1042,12 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1035
1042
1036
1043
const auto list = pb.NewList (tupleType, {data1, data2, data3, data4, data5, data6, data7, data8, data9});
1037
1044
1038
- const auto pgmReturn = pb.Collect (pb.NarrowMap (pb.WideLastCombiner (pb.ExpandMap (pb.ToFlow (list),
1045
+ auto wideLastCombinerCollable = &TProgramBuilder::WideLastCombiner;
1046
+ if (SPILLING) {
1047
+ wideLastCombinerCollable = &TProgramBuilder::WideLastCombinerWithSpilling;
1048
+ }
1049
+
1050
+ const auto pgmReturn = pb.Collect (pb.NarrowMap ((pb.*wideLastCombinerCollable)(pb.ExpandMap (pb.ToFlow (list),
1039
1051
[&](TRuntimeNode item) -> TRuntimeNode::TList { return {pb.Nth (item, 0U ), pb.Nth (item, 1U )}; }),
1040
1052
[&](TRuntimeNode::TList items) -> TRuntimeNode::TList { return {items.front ()}; },
1041
1053
[&](TRuntimeNode::TList keys, TRuntimeNode::TList items) -> TRuntimeNode::TList {
@@ -1059,22 +1071,37 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1059
1071
));
1060
1072
1061
1073
const auto graph = setup.BuildGraph (pgmReturn);
1074
+ if (SPILLING) {
1075
+ graph->GetContext ().SpillerFactory = std::make_shared<TMockSpillerFactory>();
1076
+ }
1062
1077
const auto iterator = graph->GetValue ().GetListIterator ();
1078
+
1079
+ std::unordered_set<TString> expected {
1080
+ " key one" ,
1081
+ " very long value 2 / key two" ,
1082
+ " very long key one" ,
1083
+ " very long value 8 / very long value 7 / very long value 6"
1084
+ };
1085
+
1063
1086
NUdf::TUnboxedValue item;
1064
- UNIT_ASSERT (iterator. Next (item));
1065
- UNBOXED_VALUE_STR_EQUAL (item, " key one " );
1066
- UNIT_ASSERT (iterator. Next (item) );
1067
- UNBOXED_VALUE_STR_EQUAL (item, " very long value 2 / key two " );
1068
- UNIT_ASSERT (iterator. Next (item) );
1069
- UNBOXED_VALUE_STR_EQUAL (item, " very long key one " );
1070
- UNIT_ASSERT (iterator. Next (item) );
1071
- UNBOXED_VALUE_STR_EQUAL (item, " very long value 8 / very long value 7 / very long value 6 " );
1087
+ while (!expected. empty ()) {
1088
+ UNIT_ASSERT (iterator. Next (item) );
1089
+ TString actual = item. AsStringRef (). Data ( );
1090
+
1091
+ auto it = expected. find (actual );
1092
+ UNIT_ASSERT (it != expected. end () );
1093
+ expected. erase (it );
1094
+ }
1072
1095
UNIT_ASSERT (!iterator.Next (item));
1073
1096
UNIT_ASSERT (!iterator.Next (item));
1074
1097
}
1075
1098
1076
- Y_UNIT_TEST_LLVM (TestLongStringsPasstroughtRefCounting) {
1077
- TSetup<LLVM> setup;
1099
+ Y_UNIT_TEST_LLVM_SPILLING (TestLongStringsPasstroughtRefCounting) {
1100
+ // Currently LLVM version doesn't support spilling.
1101
+ if (LLVM && SPILLING) return ;
1102
+ // callable WideLastCombinerWithSpilling was introduced in 49 version of runtime
1103
+ if (MKQL_RUNTIME_VERSION < 49U && SPILLING) return ;
1104
+ TSetup<LLVM, SPILLING> setup;
1078
1105
TProgramBuilder& pb = *setup.PgmBuilder ;
1079
1106
1080
1107
const auto dataType = pb.NewDataType (NUdf::TDataType<const char *>::Id);
@@ -1111,7 +1138,11 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1111
1138
1112
1139
const auto list = pb.NewList (tupleType, {data1, data2, data3, data4, data5, data6, data7, data8, data9});
1113
1140
1114
- const auto pgmReturn = pb.Collect (pb.NarrowMap (pb.WideLastCombiner (pb.ExpandMap (pb.ToFlow (list),
1141
+ auto wideLastCombinerCollable = &TProgramBuilder::WideLastCombiner;
1142
+ if (SPILLING) {
1143
+ wideLastCombinerCollable = &TProgramBuilder::WideLastCombinerWithSpilling;
1144
+ }
1145
+ const auto pgmReturn = pb.Collect (pb.NarrowMap ((pb.*wideLastCombinerCollable)(pb.ExpandMap (pb.ToFlow (list),
1115
1146
[&](TRuntimeNode item) -> TRuntimeNode::TList { return {pb.Nth (item, 0U ), pb.Nth (item, 1U )}; }),
1116
1147
[&](TRuntimeNode::TList items) -> TRuntimeNode::TList { return {items.front ()}; },
1117
1148
[&](TRuntimeNode::TList keys, TRuntimeNode::TList items) -> TRuntimeNode::TList {
@@ -1134,22 +1165,40 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1134
1165
));
1135
1166
1136
1167
const auto graph = setup.BuildGraph (pgmReturn);
1168
+ if (SPILLING) {
1169
+ graph->GetContext ().SpillerFactory = std::make_shared<TMockSpillerFactory>();
1170
+ }
1137
1171
const auto iterator = graph->GetValue ().GetListIterator ();
1172
+
1173
+ std::unordered_set<TString> expected {
1174
+ " very long value 1 / key one / very long value 1 / key one" ,
1175
+ " very long value 3 / key two / very long value 2 / key two" ,
1176
+ " very long value 4 / very long key one / very long value 4 / very long key one" ,
1177
+ " very long value 9 / very long key two / very long value 5 / very long key two"
1178
+ };
1179
+
1138
1180
NUdf::TUnboxedValue item;
1139
- UNIT_ASSERT (iterator. Next (item));
1140
- UNBOXED_VALUE_STR_EQUAL (item, " very long value 1 / key one / very long value 1 / key one " );
1141
- UNIT_ASSERT (iterator. Next (item) );
1142
- UNBOXED_VALUE_STR_EQUAL (item, " very long value 3 / key two / very long value 2 / key two " );
1143
- UNIT_ASSERT (iterator. Next (item) );
1144
- UNBOXED_VALUE_STR_EQUAL (item, " very long value 4 / very long key one / very long value 4 / very long key one " );
1145
- UNIT_ASSERT (iterator. Next (item) );
1146
- UNBOXED_VALUE_STR_EQUAL (item, " very long value 9 / very long key two / very long value 5 / very long key two " );
1181
+ while (!expected. empty ()) {
1182
+ UNIT_ASSERT (iterator. Next (item) );
1183
+ TString actual = item. AsStringRef (). Data ( );
1184
+
1185
+ auto it = expected. find (actual );
1186
+ UNIT_ASSERT (it != expected. end () );
1187
+ expected. erase (it );
1188
+ }
1147
1189
UNIT_ASSERT (!iterator.Next (item));
1148
1190
UNIT_ASSERT (!iterator.Next (item));
1149
1191
}
1150
1192
1151
- Y_UNIT_TEST_LLVM (TestDoNotCalculateUnusedInput) {
1152
- TSetup<LLVM> setup;
1193
+ Y_UNIT_TEST_LLVM_SPILLING (TestDoNotCalculateUnusedInput) {
1194
+ // Test is broken. Remove this if after YQL-18808.
1195
+ if (SPILLING) return ;
1196
+
1197
+ // Currently LLVM version doesn't support spilling.
1198
+ if (LLVM && SPILLING) return ;
1199
+ // callable WideLastCombinerWithSpilling was introduced in 49 version of runtime
1200
+ if (MKQL_RUNTIME_VERSION < 49U && SPILLING) return ;
1201
+ TSetup<LLVM, SPILLING> setup;
1153
1202
TProgramBuilder& pb = *setup.PgmBuilder ;
1154
1203
1155
1204
const auto dataType = pb.NewDataType (NUdf::TDataType<const char *>::Id);
@@ -1183,7 +1232,11 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1183
1232
1184
1233
const auto landmine = pb.NewDataLiteral <NUdf::EDataSlot::String>(" ACHTUNG MINEN!" );
1185
1234
1186
- const auto pgmReturn = pb.Collect (pb.NarrowMap (pb.WideLastCombiner (pb.ExpandMap (pb.ToFlow (list),
1235
+ auto wideLastCombinerCollable = &TProgramBuilder::WideLastCombiner;
1236
+ if (SPILLING) {
1237
+ wideLastCombinerCollable = &TProgramBuilder::WideLastCombinerWithSpilling;
1238
+ }
1239
+ const auto pgmReturn = pb.Collect (pb.NarrowMap ((pb.*wideLastCombinerCollable)(pb.ExpandMap (pb.ToFlow (list),
1187
1240
[&](TRuntimeNode item) -> TRuntimeNode::TList { return {pb.Nth (item, 0U ), pb.Unwrap (pb.Nth (item, 1U ), landmine, __FILE__, __LINE__, 0 ), pb.Nth (item, 2U )}; }),
1188
1241
[&](TRuntimeNode::TList items) -> TRuntimeNode::TList { return {items.front ()}; },
1189
1242
[&](TRuntimeNode::TList keys, TRuntimeNode::TList items) -> TRuntimeNode::TList {
@@ -1207,18 +1260,34 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1207
1260
));
1208
1261
1209
1262
const auto graph = setup.BuildGraph (pgmReturn);
1263
+ if (SPILLING) {
1264
+ graph->GetContext ().SpillerFactory = std::make_shared<TMockSpillerFactory>();
1265
+ }
1266
+ std::unordered_set<TString> expected {
1267
+ " key one / value 2 / value 1 / value 5 / value 4" ,
1268
+ " key two / value 4 / value 3 / value 3 / value 2"
1269
+ };
1270
+
1210
1271
const auto iterator = graph->GetValue ().GetListIterator ();
1211
1272
NUdf::TUnboxedValue item;
1212
- UNIT_ASSERT (iterator.Next (item));
1213
- UNBOXED_VALUE_STR_EQUAL (item, " key one / value 2 / value 1 / value 5 / value 4" );
1214
- UNIT_ASSERT (iterator.Next (item));
1215
- UNBOXED_VALUE_STR_EQUAL (item, " key two / value 4 / value 3 / value 3 / value 2" );
1273
+ while (!expected.empty ()) {
1274
+ UNIT_ASSERT (iterator.Next (item));
1275
+ TString actual = item.AsStringRef ().Data ();
1276
+
1277
+ auto it = expected.find (actual);
1278
+ UNIT_ASSERT (it != expected.end ());
1279
+ expected.erase (it);
1280
+ }
1216
1281
UNIT_ASSERT (!iterator.Next (item));
1217
1282
UNIT_ASSERT (!iterator.Next (item));
1218
1283
}
1219
1284
1220
- Y_UNIT_TEST_LLVM (TestDoNotCalculateUnusedOutput) {
1221
- TSetup<LLVM> setup;
1285
+ Y_UNIT_TEST_LLVM_SPILLING (TestDoNotCalculateUnusedOutput) {
1286
+ // Currently LLVM version doesn't support spilling.
1287
+ if (LLVM && SPILLING) return ;
1288
+ // callable WideLastCombinerWithSpilling was introduced in 49 version of runtime
1289
+ if (MKQL_RUNTIME_VERSION < 49U && SPILLING) return ;
1290
+ TSetup<LLVM, SPILLING> setup;
1222
1291
TProgramBuilder& pb = *setup.PgmBuilder ;
1223
1292
1224
1293
const auto dataType = pb.NewDataType (NUdf::TDataType<const char *>::Id);
@@ -1252,7 +1321,11 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1252
1321
1253
1322
const auto landmine = pb.NewDataLiteral <NUdf::EDataSlot::String>(" ACHTUNG MINEN!" );
1254
1323
1255
- const auto pgmReturn = pb.Collect (pb.NarrowMap (pb.WideLastCombiner (pb.ExpandMap (pb.ToFlow (list),
1324
+ auto wideLastCombinerCollable = &TProgramBuilder::WideLastCombiner;
1325
+ if (SPILLING) {
1326
+ wideLastCombinerCollable = &TProgramBuilder::WideLastCombinerWithSpilling;
1327
+ }
1328
+ const auto pgmReturn = pb.Collect (pb.NarrowMap ((pb.*wideLastCombinerCollable)(pb.ExpandMap (pb.ToFlow (list),
1256
1329
[&](TRuntimeNode item) -> TRuntimeNode::TList { return {pb.Nth (item, 0U ), pb.Nth (item, 1U ), pb.Nth (item, 2U )}; }),
1257
1330
[&](TRuntimeNode::TList items) -> TRuntimeNode::TList { return {items.front ()}; },
1258
1331
[&](TRuntimeNode::TList, TRuntimeNode::TList items) -> TRuntimeNode::TList {
@@ -1268,26 +1341,46 @@ Y_UNIT_TEST_SUITE(TMiniKQLWideLastCombinerTest) {
1268
1341
));
1269
1342
1270
1343
const auto graph = setup.BuildGraph (pgmReturn);
1344
+ if (SPILLING) {
1345
+ graph->GetContext ().SpillerFactory = std::make_shared<TMockSpillerFactory>();
1346
+ }
1347
+ std::unordered_set<TString> expected {
1348
+ " key one: value 1, value 4, value 5, value 1, value 2" ,
1349
+ " key two: value 2, value 3, value 3, value 4"
1350
+ };
1351
+
1271
1352
const auto iterator = graph->GetValue ().GetListIterator ();
1272
1353
NUdf::TUnboxedValue item;
1273
- UNIT_ASSERT (iterator.Next (item));
1274
- UNBOXED_VALUE_STR_EQUAL (item, " key one: value 1, value 4, value 5, value 1, value 2" );
1275
- UNIT_ASSERT (iterator.Next (item));
1276
- UNBOXED_VALUE_STR_EQUAL (item, " key two: value 2, value 3, value 3, value 4" );
1354
+ while (!expected.empty ()) {
1355
+ UNIT_ASSERT (iterator.Next (item));
1356
+ TString actual = item.AsStringRef ().Data ();
1357
+
1358
+ auto it = expected.find (actual);
1359
+ UNIT_ASSERT (it != expected.end ());
1360
+ expected.erase (it);
1361
+ }
1277
1362
UNIT_ASSERT (!iterator.Next (item));
1278
1363
UNIT_ASSERT (!iterator.Next (item));
1279
1364
}
1280
1365
1281
- Y_UNIT_TEST_LLVM (TestThinAllLambdas) {
1282
- TSetup<LLVM> setup;
1366
+ Y_UNIT_TEST_LLVM_SPILLING (TestThinAllLambdas) {
1367
+ // Currently LLVM version doesn't support spilling.
1368
+ if (LLVM && SPILLING) return ;
1369
+ // callable WideLastCombinerWithSpilling was introduced in 49 version of runtime
1370
+ if (MKQL_RUNTIME_VERSION < 49U && SPILLING) return ;
1371
+ TSetup<LLVM, SPILLING> setup;
1283
1372
TProgramBuilder& pb = *setup.PgmBuilder ;
1284
1373
1285
1374
const auto tupleType = pb.NewTupleType ({});
1286
1375
const auto data = pb.NewTuple ({});
1287
1376
1288
1377
const auto list = pb.NewList (tupleType, {data, data, data, data});
1289
1378
1290
- const auto pgmReturn = pb.Collect (pb.NarrowMap (pb.WideLastCombiner (pb.ExpandMap (pb.ToFlow (list),
1379
+ auto wideLastCombinerCollable = &TProgramBuilder::WideLastCombiner;
1380
+ if (SPILLING) {
1381
+ wideLastCombinerCollable = &TProgramBuilder::WideLastCombinerWithSpilling;
1382
+ }
1383
+ const auto pgmReturn = pb.Collect (pb.NarrowMap ((pb.*wideLastCombinerCollable)(pb.ExpandMap (pb.ToFlow (list),
1291
1384
[](TRuntimeNode) -> TRuntimeNode::TList { return {}; }),
1292
1385
[](TRuntimeNode::TList items) { return items; },
1293
1386
[](TRuntimeNode::TList, TRuntimeNode::TList items) { return items; },
0 commit comments