12
12
import io .deephaven .engine .table .impl .QueryTable ;
13
13
import io .deephaven .engine .table .impl .UpdateErrorReporter ;
14
14
import io .deephaven .engine .table .impl .util .AsyncClientErrorNotifier ;
15
+ import io .deephaven .engine .table .impl .util .ColumnHolder ;
15
16
import io .deephaven .engine .testutil .ControlledUpdateGraph ;
16
17
import io .deephaven .engine .testutil .EvalNugget ;
17
18
import io .deephaven .engine .table .impl .TableDefaults ;
29
30
import junit .framework .TestCase ;
30
31
import org .jetbrains .annotations .NotNull ;
31
32
import org .junit .After ;
33
+ import org .junit .Assert ;
32
34
import org .junit .Before ;
33
35
import org .junit .Test ;
34
36
import org .junit .experimental .categories .Category ;
35
37
36
38
import java .time .Duration ;
37
39
import java .util .*;
38
40
41
+ import static io .deephaven .api .updateby .UpdateByOperation .*;
39
42
import static io .deephaven .engine .testutil .GenerateTableUpdates .generateAppends ;
40
43
import static io .deephaven .engine .testutil .TstUtils .*;
41
44
import static io .deephaven .engine .testutil .testcase .RefreshingTableTestCase .simulateShiftAwareStep ;
42
- import static io .deephaven .engine .util .TableTools .col ;
43
- import static io .deephaven .engine .util .TableTools .intCol ;
45
+ import static io .deephaven .engine .util .TableTools .*;
44
46
import static io .deephaven .time .DateTimeUtils .MINUTE ;
45
47
46
48
@ Category (OutOfBandTest .class )
@@ -138,9 +140,9 @@ protected Table e() {
138
140
UpdateByOperation .RollingMin ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (5 ),
139
141
makeOpColNames (columnNamesArray , "_rollmintimerev" , "Sym" , "ts" , "boolCol" )),
140
142
141
- UpdateByOperation . RollingMax (50 , 50 ,
143
+ RollingMax (50 , 50 ,
142
144
makeOpColNames (columnNamesArray , "_rollmaxticksrev" , "Sym" , "ts" , "boolCol" )),
143
- UpdateByOperation . RollingMax ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (5 ),
145
+ RollingMax ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (5 ),
144
146
makeOpColNames (columnNamesArray , "_rollmaxtimerev" , "Sym" , "ts" , "boolCol" )),
145
147
146
148
// Excluding 'bigDecimalCol' because we need fuzzy matching which doesn't exist for BD
@@ -154,8 +156,8 @@ protected Table e() {
154
156
UpdateByOperation .Ema (skipControl , "ts" , 10 * MINUTE ,
155
157
makeOpColNames (columnNamesArray , "_ema" , "Sym" , "ts" , "boolCol" )),
156
158
UpdateByOperation .CumSum (makeOpColNames (columnNamesArray , "_sum" , "Sym" , "ts" )),
157
- UpdateByOperation . CumMin (makeOpColNames (columnNamesArray , "_min" , "boolCol" )),
158
- UpdateByOperation . CumMax (makeOpColNames (columnNamesArray , "_max" , "boolCol" )),
159
+ CumMin (makeOpColNames (columnNamesArray , "_min" , "boolCol" )),
160
+ CumMax (makeOpColNames (columnNamesArray , "_max" , "boolCol" )),
159
161
UpdateByOperation
160
162
.CumProd (makeOpColNames (columnNamesArray , "_prod" , "Sym" , "ts" , "boolCol" )));
161
163
final UpdateByControl control = UpdateByControl .builder ().useRedirection (redirected ).build ();
@@ -272,38 +274,36 @@ public void testInMemoryColumn() {
272
274
final Collection <? extends UpdateByOperation > clauses = List .of (
273
275
UpdateByOperation .Fill (),
274
276
275
- UpdateByOperation . RollingGroup (50 , 50 ,
277
+ RollingGroup (50 , 50 ,
276
278
makeOpColNames (columnNamesArray , "_rollgroupfwdrev" , "Sym" , "ts" )),
277
- UpdateByOperation . RollingGroup ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (5 ),
279
+ RollingGroup ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (5 ),
278
280
makeOpColNames (columnNamesArray , "_rollgrouptimefwdrev" , "Sym" , "ts" )),
279
281
280
- UpdateByOperation . RollingSum (100 , 0 ,
282
+ RollingSum (100 , 0 ,
281
283
makeOpColNames (columnNamesArray , "_rollsumticksrev" , "Sym" , "ts" , "boolCol" )),
282
- UpdateByOperation . RollingSum ("ts" , Duration .ofMinutes (15 ), Duration .ofMinutes (0 ),
284
+ RollingSum ("ts" , Duration .ofMinutes (15 ), Duration .ofMinutes (0 ),
283
285
makeOpColNames (columnNamesArray , "_rollsumtimerev" , "Sym" , "ts" , "boolCol" )),
284
286
285
- UpdateByOperation . RollingAvg (100 , 0 ,
287
+ RollingAvg (100 , 0 ,
286
288
makeOpColNames (columnNamesArray , "_rollavgticksrev" , "Sym" , "ts" , "boolCol" )),
287
- UpdateByOperation . RollingAvg ("ts" , Duration .ofMinutes (15 ), Duration .ofMinutes (0 ),
289
+ RollingAvg ("ts" , Duration .ofMinutes (15 ), Duration .ofMinutes (0 ),
288
290
makeOpColNames (columnNamesArray , "_rollavgtimerev" , "Sym" , "ts" , "boolCol" )),
289
291
290
- UpdateByOperation . RollingMin (100 , 0 ,
292
+ RollingMin (100 , 0 ,
291
293
makeOpColNames (columnNamesArray , "_rollminticksrev" , "Sym" , "ts" , "boolCol" )),
292
- UpdateByOperation . RollingMin ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (0 ),
294
+ RollingMin ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (0 ),
293
295
makeOpColNames (columnNamesArray , "_rollmintimerev" , "Sym" , "ts" , "boolCol" )),
294
296
295
- UpdateByOperation . RollingMax (100 , 0 ,
297
+ RollingMax (100 , 0 ,
296
298
makeOpColNames (columnNamesArray , "_rollmaxticksrev" , "Sym" , "ts" , "boolCol" )),
297
- UpdateByOperation . RollingMax ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (0 ),
299
+ RollingMax ("ts" , Duration .ofMinutes (5 ), Duration .ofMinutes (0 ),
298
300
makeOpColNames (columnNamesArray , "_rollmaxtimerev" , "Sym" , "ts" , "boolCol" )),
299
301
300
- UpdateByOperation .Ema (skipControl , "ts" , 10 * MINUTE ,
301
- makeOpColNames (columnNamesArray , "_ema" , "Sym" , "ts" , "boolCol" )),
302
- UpdateByOperation .CumSum (makeOpColNames (columnNamesArray , "_sum" , "Sym" , "ts" )),
303
- UpdateByOperation .CumMin (makeOpColNames (columnNamesArray , "_min" , "boolCol" )),
304
- UpdateByOperation .CumMax (makeOpColNames (columnNamesArray , "_max" , "boolCol" )),
305
- UpdateByOperation
306
- .CumProd (makeOpColNames (columnNamesArray , "_prod" , "Sym" , "ts" , "boolCol" )));
302
+ Ema (skipControl , "ts" , 10 * MINUTE , makeOpColNames (columnNamesArray , "_ema" , "Sym" , "ts" , "boolCol" )),
303
+ CumSum (makeOpColNames (columnNamesArray , "_sum" , "Sym" , "ts" )),
304
+ CumMin (makeOpColNames (columnNamesArray , "_min" , "boolCol" )),
305
+ CumMax (makeOpColNames (columnNamesArray , "_max" , "boolCol" )),
306
+ CumProd (makeOpColNames (columnNamesArray , "_prod" , "Sym" , "ts" , "boolCol" )));
307
307
final UpdateByControl control = UpdateByControl .builder ().useRedirection (false ).build ();
308
308
309
309
final Table table = result .t .updateBy (control , clauses , ColumnName .from ("Sym" ));
@@ -322,4 +322,76 @@ public void run() {
322
322
}
323
323
});
324
324
}
325
+
326
+ @ Test
327
+ public void testResultColumnOrdering () {
328
+ final Table source = emptyTable (5 ).update ("X=ii" );
329
+
330
+ final ColumnHolder <?> x = longCol ("X" , 0 , 1 , 2 , 3 , 4 );
331
+ final ColumnHolder <?> cumMin = longCol ("cumMin" , 0 , 0 , 0 , 0 , 0 );
332
+ final ColumnHolder <?> cumMax = longCol ("cumMax" , 0 , 1 , 2 , 3 , 4 );
333
+ final ColumnHolder <?> rollingMin = longCol ("rollingMin" , 0 , 0 , 1 , 2 , 3 );
334
+ final ColumnHolder <?> rollingMax = longCol ("rollingMax" , 0 , 1 , 2 , 3 , 4 );
335
+
336
+ final Table result_1 = source .updateBy (List .of (
337
+ CumMin ("cumMin=X" ),
338
+ CumMax ("cumMax=X" ),
339
+ RollingMin (2 , "rollingMin=X" ),
340
+ RollingMax (2 , "rollingMax=X" )));
341
+ final Table expected_1 = TableTools .newTable (x , cumMin , cumMax , rollingMin , rollingMax );
342
+ Assert .assertEquals ("" , diff (result_1 , expected_1 , 10 ));
343
+
344
+ final Table result_2 = source .updateBy (List .of (
345
+ CumMax ("cumMax=X" ),
346
+ CumMin ("cumMin=X" ),
347
+ RollingMax (2 , "rollingMax=X" ),
348
+ RollingMin (2 , "rollingMin=X" )));
349
+ final Table expected_2 = TableTools .newTable (x , cumMax , cumMin , rollingMax , rollingMin );
350
+ Assert .assertEquals ("" , diff (result_2 , expected_2 , 10 ));
351
+
352
+ final Table result_3 = source .updateBy (List .of (
353
+ RollingMin (2 , "rollingMin=X" ),
354
+ RollingMax (2 , "rollingMax=X" ),
355
+ CumMin ("cumMin=X" ),
356
+ CumMax ("cumMax=X" )));
357
+ final Table expected_3 = TableTools .newTable (x , rollingMin , rollingMax , cumMin , cumMax );
358
+ Assert .assertEquals ("" , diff (result_3 , expected_3 , 10 ));
359
+
360
+ final Table result_4 = source .updateBy (List .of (
361
+ RollingMax (2 , "rollingMax=X" ),
362
+ RollingMin (2 , "rollingMin=X" ),
363
+ CumMax ("cumMax=X" ),
364
+ CumMin ("cumMin=X" )));
365
+ final Table expected_4 = TableTools .newTable (x , rollingMax , rollingMin , cumMax , cumMin );
366
+ Assert .assertEquals ("" , diff (result_4 , expected_4 , 10 ));
367
+
368
+ final Table result_5 = source .updateBy (List .of (
369
+ CumMin ("cumMin=X" ),
370
+ RollingMin (2 , "rollingMin=X" ),
371
+ CumMax ("cumMax=X" ),
372
+ RollingMax (2 , "rollingMax=X" )));
373
+ final Table expected_5 = TableTools .newTable (x , cumMin , rollingMin , cumMax , rollingMax );
374
+ Assert .assertEquals ("" , diff (result_5 , expected_5 , 10 ));
375
+
376
+ // Trickiest one, since we internally combine groupBy operations.
377
+ final Table source_2 = source .update ("Y=ii % 2" );
378
+ final Table result_6 = source_2 .updateBy (List .of (
379
+ CumMin ("cumMin=X" ),
380
+ RollingGroup (2 , "rollingGroupY=Y" ),
381
+ RollingMin (2 , "rollingMin=X" ),
382
+ CumMax ("cumMax=X" ),
383
+ RollingGroup (2 , "rollingGroupX=X" ),
384
+ RollingMax (2 , "rollingMax=X" )));
385
+
386
+ Assert .assertArrayEquals (result_6 .getDefinition ().getColumnNamesArray (),
387
+ new String [] {
388
+ "X" ,
389
+ "Y" ,
390
+ "cumMin" ,
391
+ "rollingGroupY" ,
392
+ "rollingMin" ,
393
+ "cumMax" ,
394
+ "rollingGroupX" ,
395
+ "rollingMax" });
396
+ }
325
397
}
0 commit comments