22
22
import java .lang .reflect .Type ;
23
23
import java .sql .Timestamp ;
24
24
import java .util .*;
25
+ import java .util .function .Predicate ;
26
+ import java .util .stream .Collectors ;
25
27
26
28
import static gov .cdc .datacompareprocessor .share .StackTraceUtil .getStackTraceAsString ;
27
29
import static gov .cdc .datacompareprocessor .share .StringHelper .convertStringToList ;
@@ -125,6 +127,13 @@ public void processingData(PullerEventModel pullerEventModel) {
125
127
var remainList = processingRemainingData ( ignoreColList , pullerEventModel .getKeyColumn (), pullerEventModel .getFileName ());
126
128
differModels .addAll (remainList );
127
129
130
+ Predicate <DifferentModel > rdbPredicate = r -> r .getMissingColumn () != null && r .getMissingColumn ().contains ("is not exist in RDB" );
131
+ Predicate <DifferentModel > rdbModernPredicate = r -> r .getMissingColumn () != null && r .getMissingColumn ().contains ("is not exist in RDB_MODERN" );
132
+ processFirstFound (differModels , rdbPredicate );
133
+ processFirstFound (differModels , rdbModernPredicate );
134
+
135
+ differModels .sort (Comparator .comparing (DifferentModel ::getKey , Comparator .nullsFirst (Comparator .naturalOrder ())));
136
+
128
137
var stringValue = gson .toJson (differModels );
129
138
s3DataPullerService .uploadDataToS3 (
130
139
pullerEventModel .getFirstLayerRdbModernFolderName (),
@@ -175,6 +184,21 @@ public void processingData(PullerEventModel pullerEventModel) {
175
184
176
185
}
177
186
187
+ private void processFirstFound (List <DifferentModel > records , Predicate <DifferentModel > predicate ) {
188
+ Optional <DifferentModel > firstFound = records .stream ()
189
+ .filter (predicate )
190
+ .peek (r -> r .setKey (null ))
191
+ .findFirst ();
192
+
193
+ if (firstFound .isPresent ()) {
194
+ // Remove all that match the predicate
195
+ records .removeIf (predicate );
196
+
197
+ // Add the first found back to the list
198
+ records .add (firstFound .get ());
199
+ }
200
+ }
201
+
178
202
protected Map <String , Integer > getMaxIndexWithSource (PullerEventModel pullerEventModel ) {
179
203
Map <String , Integer > result = new HashMap <>();
180
204
@@ -273,6 +297,7 @@ protected List<DifferentModel> compareJsonFilesOnRemaining(String uniqueIdField,
273
297
274
298
275
299
StringBuilder diffBuilder = new StringBuilder ();
300
+ StringBuilder missingColBuilder = new StringBuilder ();
276
301
List <DifferentModel > differentModels = new ArrayList <>();
277
302
278
303
if (mapRdb .size () < mapRdbModern .size ()) {
@@ -284,6 +309,7 @@ protected List<DifferentModel> compareJsonFilesOnRemaining(String uniqueIdField,
284
309
mapRdb .remove (id );
285
310
mapRdbModern .remove (id );
286
311
List <String > differList = new ArrayList <>();
312
+ List <String > missingColList = new ArrayList <>();
287
313
288
314
for (String key : recordRdb .keySet ()) {
289
315
if (ignoreCols .contains (key )) {
@@ -308,11 +334,16 @@ protected List<DifferentModel> compareJsonFilesOnRemaining(String uniqueIdField,
308
334
309
335
}
310
336
else {
311
- diffBuilder .setLength (0 );
312
- diffBuilder .append (key ).append (": " )
313
- .append ("[RDB_VALUE: " ).append (valueRdb ).append ("], " )
314
- .append ("[RDB_MODERN_VALUE: COLUMN NOT EXIST]" ).trimToSize ();
315
- differList .add (diffBuilder .toString ());
337
+ missingColBuilder .setLength (0 );
338
+ missingColBuilder .append (key ).append (" is not exist in RDB_MODERN" ).trimToSize ();
339
+ missingColList .add (missingColBuilder .toString ());
340
+
341
+ //
342
+ // diffBuilder.setLength(0);
343
+ // diffBuilder.append(key).append(": ")
344
+ // .append("[RDB_VALUE: ").append(valueRdb).append("], ")
345
+ // .append("[RDB_MODERN_VALUE: COLUMN NOT EXIST]").trimToSize();
346
+ // differList.add(diffBuilder.toString());
316
347
}
317
348
318
349
}
@@ -330,14 +361,32 @@ protected List<DifferentModel> compareJsonFilesOnRemaining(String uniqueIdField,
330
361
}
331
362
diffBuilder .append ("]" );
332
363
364
+ missingColBuilder .setLength (0 );
365
+ missingColBuilder .append ("[" );
366
+ for (int i = 0 ; i < missingColList .size (); i ++) {
367
+
368
+ missingColBuilder .append (missingColList .get (i ));
369
+ // Add a comma if it's not the last element
370
+ if (i < missingColList .size () - 1 ) {
371
+ missingColBuilder .append ("," );
372
+ }
373
+ }
374
+ missingColBuilder .append ("]" );
375
+ differentModel .setMissingColumn (missingColBuilder .toString ().replaceAll ("\" " , "" ));
376
+
333
377
differentModel .setKey (id );
334
378
differentModel .setKeyColumn (uniqueIdField );
335
379
differentModel .setDifferentColumnAndValue (diffBuilder .toString ().replaceAll ("\" " , "" ));
336
-
337
- if (!differentModel .getDifferentColumnAndValue ().equals ("[]" )) {
380
+ if (!differentModel .getDifferentColumnAndValue ().equals ("[]" ))
381
+ {
382
+ differentModels .add (differentModel );
383
+ }
384
+ else if (!differentModel .getMissingColumn ().equals ("[]" ))
385
+ {
338
386
differentModels .add (differentModel );
339
387
}
340
388
389
+
341
390
}
342
391
343
392
}
@@ -351,6 +400,7 @@ protected List<DifferentModel> compareJsonFilesOnRemaining(String uniqueIdField,
351
400
mapRdb .remove (id );
352
401
mapRdbModern .remove (id );
353
402
List <String > differList = new ArrayList <>();
403
+ List <String > missingColList = new ArrayList <>();
354
404
355
405
for (String key : mapRdbModern .keySet ()) {
356
406
if (ignoreCols .contains (key )) {
@@ -375,11 +425,15 @@ protected List<DifferentModel> compareJsonFilesOnRemaining(String uniqueIdField,
375
425
376
426
}
377
427
else {
378
- diffBuilder .setLength (0 );
379
- diffBuilder .append (key ).append (": " )
380
- .append ("[RDB_VALUE: COLUMN NOT EXIST" )
381
- .append ("[RDB_MODERN_VALUE: " ).append (valueRdbModern ).append ("]" ).trimToSize ();
382
- differList .add (diffBuilder .toString ());
428
+ missingColBuilder .setLength (0 );
429
+ missingColBuilder .append (key ).append (" is not exist in RDB" ).trimToSize ();
430
+ missingColList .add (missingColBuilder .toString ());
431
+
432
+ // diffBuilder.setLength(0);
433
+ // diffBuilder.append(key).append(": ")
434
+ // .append("[RDB_VALUE: COLUMN NOT EXIST")
435
+ // .append("[RDB_MODERN_VALUE: ").append(valueRdbModern).append("]").trimToSize();
436
+ // differList.add(diffBuilder.toString());
383
437
}
384
438
385
439
}
@@ -397,13 +451,31 @@ protected List<DifferentModel> compareJsonFilesOnRemaining(String uniqueIdField,
397
451
}
398
452
diffBuilder .append ("]" );
399
453
454
+ missingColBuilder .setLength (0 );
455
+ missingColBuilder .append ("[" );
456
+ for (int i = 0 ; i < missingColList .size (); i ++) {
457
+
458
+ missingColBuilder .append (missingColList .get (i ));
459
+ // Add a comma if it's not the last element
460
+ if (i < missingColList .size () - 1 ) {
461
+ missingColBuilder .append ("," );
462
+ }
463
+ }
464
+ missingColBuilder .append ("]" );
465
+ differentModel .setMissingColumn (missingColBuilder .toString ().replaceAll ("\" " , "" ));
466
+
467
+
400
468
differentModel .setKey (id );
401
469
differentModel .setKeyColumn (uniqueIdField );
402
470
differentModel .setDifferentColumnAndValue (diffBuilder .toString ().replaceAll ("\" " , "" ));
403
471
404
472
if (!differentModel .getDifferentColumnAndValue ().equals ("[]" )) {
405
473
differentModels .add (differentModel );
406
474
}
475
+ else if (!differentModel .getMissingColumn ().equals ("[]" ))
476
+ {
477
+ differentModels .add (differentModel );
478
+ }
407
479
408
480
}
409
481
@@ -440,6 +512,7 @@ protected String compareJsonFiles(String fileRdbPath, String fileRdbModernPath,
440
512
}
441
513
442
514
StringBuilder diffBuilder = new StringBuilder ();
515
+ StringBuilder missingColBuilder = new StringBuilder ();
443
516
List <DifferentModel > differentModels = new ArrayList <>();
444
517
445
518
@@ -448,6 +521,7 @@ protected String compareJsonFiles(String fileRdbPath, String fileRdbModernPath,
448
521
DifferentModel differentModel = new DifferentModel ();
449
522
differentModel .setTable (pullerEventModel .getFileName ());
450
523
List <String > differList = new ArrayList <>();
524
+ List <String > missingColList = new ArrayList <>();
451
525
452
526
JsonObject recordRdb = mapRdb .get (id );
453
527
JsonObject recordRdbModern = mapRdbModern .get (id );
@@ -482,11 +556,15 @@ protected String compareJsonFiles(String fileRdbPath, String fileRdbModernPath,
482
556
483
557
}
484
558
else {
485
- diffBuilder .setLength (0 );
486
- diffBuilder .append (key ).append (": " )
487
- .append ("[RDB_VALUE: " ).append (valueRdb ).append ("], " )
488
- .append ("[RDB_MODERN_VALUE: COLUMN NOT EXIST]" ).trimToSize ();
489
- differList .add (diffBuilder .toString ());
559
+ // diffBuilder.setLength(0);
560
+ // diffBuilder.append(key).append(": ")
561
+ // .append("[RDB_VALUE: ").append(valueRdb).append("], ")
562
+ // .append("[RDB_MODERN_VALUE: COLUMN NOT EXIST]").trimToSize();
563
+ // differList.add(diffBuilder.toString());
564
+ missingColBuilder .setLength (0 );
565
+ missingColBuilder .append (key ).append (" is not exist in RDB_MODERN" ).trimToSize ();
566
+ missingColList .add (missingColBuilder .toString ());
567
+
490
568
}
491
569
492
570
}
@@ -499,12 +577,17 @@ protected String compareJsonFiles(String fileRdbPath, String fileRdbModernPath,
499
577
continue ;
500
578
}
501
579
502
- JsonElement valueRdbModern = recordRdbModern .get (key );
503
- diffBuilder .setLength (0 );
504
- diffBuilder .append (key ).append (": " )
505
- .append ("[RDB_VALUE: COLUMN NOT EXIST]" )
506
- .append ("[RDB_MODERN_VALUE: " ).append (valueRdbModern ).append ("]" ).trimToSize ();
507
- differList .add (diffBuilder .toString ());
580
+ // JsonElement valueRdbModern = recordRdbModern.get(key);
581
+ // diffBuilder.setLength(0);
582
+ // diffBuilder.append(key).append(": ")
583
+ // .append("[RDB_VALUE: COLUMN NOT EXIST]")
584
+ // .append("[RDB_MODERN_VALUE: ").append(valueRdbModern).append("]").trimToSize();
585
+ // differList.add(diffBuilder.toString());
586
+
587
+ missingColBuilder .setLength (0 );
588
+ missingColBuilder .append (key ).append (" is not exist in RDB" ).trimToSize ();
589
+ missingColList .add (missingColBuilder .toString ());
590
+
508
591
509
592
}
510
593
}
@@ -522,12 +605,29 @@ protected String compareJsonFiles(String fileRdbPath, String fileRdbModernPath,
522
605
}
523
606
diffBuilder .append ("]" );
524
607
608
+ missingColBuilder .setLength (0 );
609
+ missingColBuilder .append ("[" );
610
+ for (int i = 0 ; i < missingColList .size (); i ++) {
611
+
612
+ missingColBuilder .append (missingColList .get (i ));
613
+ // Add a comma if it's not the last element
614
+ if (i < missingColList .size () - 1 ) {
615
+ missingColBuilder .append ("," );
616
+ }
617
+ }
618
+ missingColBuilder .append ("]" );
619
+ differentModel .setMissingColumn (missingColBuilder .toString ().replaceAll ("\" " , "" ));
620
+
621
+
622
+
525
623
differentModel .setKey (id );
526
624
differentModel .setKeyColumn (uniqueIdField );
527
625
differentModel .setDifferentColumnAndValue (diffBuilder .toString ().replaceAll ("\" " , "" ));
528
626
529
627
if (!differentModel .getDifferentColumnAndValue ().equals ("[]" )) {
530
628
differentModels .add (differentModel );
629
+ } else if (!differentModel .getMissingColumn ().equals ("[]" )) {
630
+ differentModels .add (differentModel );
531
631
}
532
632
}
533
633
0 commit comments