2020import static feast .storage .common .testing .TestUtil .field ;
2121import static feast .storage .connectors .bigquery .writer .FeatureSetSpecToTableSchema .*;
2222import static org .hamcrest .CoreMatchers .*;
23+ import static org .hamcrest .Matchers .containsInAnyOrder ;
2324import static org .junit .Assert .*;
2425import static org .mockito .Mockito .*;
2526import static org .mockito .MockitoAnnotations .initMocks ;
@@ -464,7 +465,7 @@ public void featureRowCompressShouldPackAndUnpackSuccessfully() {
464465 PCollection <FeatureRow > result =
465466 p .apply (Create .of (inputWithNulls ))
466467 .apply ("KV" , ParDo .of (new ExtractKV ()))
467- .apply (new CompactFeatureRows (1000 ))
468+ .apply (new CompactFeatureRows (10000 ))
468469 .apply ("Flat" , ParDo .of (new FlatMap ()));
469470
470471 List <FeatureRow > inputWithoutNulls = dropNullFeature (input );
@@ -480,7 +481,15 @@ public void featureRowCompressShouldPackAndUnpackSuccessfully() {
480481 .addAllFields (copyFieldsWithout (rowWithNull , "entity" , "null_value" ))
481482 .build ());
482483
483- PAssert .that (result ).containsInAnyOrder (inputWithoutNulls );
484+ PAssert .that (result )
485+ .satisfies (
486+ actual -> {
487+ List <FeatureRow > actualSorted = sortFeaturesByName (Lists .newArrayList (actual ));
488+ List <FeatureRow > expectedSorted = sortFeaturesByName (inputWithoutNulls );
489+
490+ assertThat (actualSorted , containsInAnyOrder (expectedSorted .toArray ()));
491+ return null ;
492+ });
484493 p .run ();
485494 }
486495
@@ -490,10 +499,7 @@ private List<FeatureRow> dropNullFeature(List<FeatureRow> input) {
490499 r ->
491500 FeatureRow .newBuilder ()
492501 .setFeatureSet (r .getFeatureSet ())
493- .addAllFields (
494- r .getFieldsList ().stream ()
495- .filter (f -> !f .getName ().equals ("null_value" ))
496- .collect (Collectors .toList ()))
502+ .addAllFields (copyFieldsWithout (r , "null_value" ))
497503 .build ())
498504 .collect (Collectors .toList ());
499505 }
@@ -505,6 +511,21 @@ private List<FieldProto.Field> copyFieldsWithout(FeatureRow row, String... excep
505511 .collect (Collectors .toList ());
506512 }
507513
514+ public static List <FeatureRow > sortFeaturesByName (List <FeatureRow > rows ) {
515+ return rows .stream ()
516+ .map (
517+ row -> {
518+ List <FieldProto .Field > fieldsList = Lists .newArrayList (row .getFieldsList ());
519+ fieldsList .sort (Comparator .comparing (FieldProto .Field ::getName ));
520+
521+ return FeatureRow .newBuilder ()
522+ .setFeatureSet (row .getFeatureSet ())
523+ .addAllFields (fieldsList )
524+ .build ();
525+ })
526+ .collect (Collectors .toList ());
527+ }
528+
508529 public static class TableAnswer implements Answer <Table >, Serializable {
509530 TableId tableId ;
510531 TableDefinition tableDefinition ;
0 commit comments