Skip to content

Commit 2e7a00a

Browse files
author
Oleksii Moskalenko
authored
output only once (#858)
1 parent 000982a commit 2e7a00a

2 files changed

Lines changed: 34 additions & 13 deletions

File tree

storage/connectors/bigquery/src/main/java/feast/storage/connectors/bigquery/writer/BigQueryWrite.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,14 @@ public void process(ProcessContext c) {
218218
@ProcessElement
219219
public void process(ProcessContext c) {
220220
CoGbkResult result = c.element().getValue();
221+
boolean ready = result.getAll(successTag).iterator().hasNext();
222+
if (!ready) {
223+
return;
224+
}
225+
221226
result
222-
.getAll(successTag)
223-
.forEach(
224-
success ->
225-
result
226-
.getAll(inputTag)
227-
.forEach(
228-
rows -> rows.getFeatureRows().forEachRemaining(c::output)));
227+
.getAll(inputTag)
228+
.forEach(rows -> rows.getFeatureRows().forEachRemaining(c::output));
229229
}
230230
}));
231231
}

storage/connectors/bigquery/src/test/java/feast/storage/connectors/bigquery/writer/BigQuerySinkTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static feast.storage.common.testing.TestUtil.field;
2121
import static feast.storage.connectors.bigquery.writer.FeatureSetSpecToTableSchema.*;
2222
import static org.hamcrest.CoreMatchers.*;
23+
import static org.hamcrest.Matchers.containsInAnyOrder;
2324
import static org.junit.Assert.*;
2425
import static org.mockito.Mockito.*;
2526
import 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

Comments
 (0)