|
26 | 26 | import com.apple.foundationdb.record.TestRecordsNulls2Proto; |
27 | 27 | import com.apple.foundationdb.record.TestRecordsNulls3Proto; |
28 | 28 | import com.apple.foundationdb.record.TestRecordsNulls3ExplicitProto; |
| 29 | +import com.apple.foundationdb.record.TestRecordsNullsEditionsProto; |
29 | 30 | import com.apple.foundationdb.record.TestRecordsTupleFieldsProto; |
30 | 31 | import com.apple.foundationdb.record.TupleFieldsProto; |
31 | 32 | import com.apple.foundationdb.record.metadata.Key; |
@@ -113,6 +114,10 @@ protected static RecordMetaData proto3ExplicitMetaData() { |
113 | 114 | return RecordMetaData.newBuilder().setRecords(TestRecordsNulls3ExplicitProto.getDescriptor()).getRecordMetaData(); |
114 | 115 | } |
115 | 116 |
|
| 117 | + protected static RecordMetaData protoEditionsMetaData() { |
| 118 | + return RecordMetaData.newBuilder().setRecords(TestRecordsNullsEditionsProto.getDescriptor()).getRecordMetaData(); |
| 119 | + } |
| 120 | + |
116 | 121 | @FunctionalInterface |
117 | 122 | interface RecordBuilder<M extends Message> { |
118 | 123 | M build(@Nonnull String name, @Nullable Integer intValue, @Nullable String stringValue); |
@@ -192,6 +197,18 @@ protected static TestRecordsNulls3ExplicitProto.MyNullRecord buildRecord3Explici |
192 | 197 | return builder.build(); |
193 | 198 | } |
194 | 199 |
|
| 200 | + protected static TestRecordsNullsEditionsProto.MyNullRecord buildRecordEditions(@Nonnull String name, @Nullable Integer intValue, @Nullable String stringValue) { |
| 201 | + TestRecordsNullsEditionsProto.MyNullRecord.Builder builder = TestRecordsNullsEditionsProto.MyNullRecord.newBuilder(); |
| 202 | + builder.setName(name); |
| 203 | + if (intValue != null) { |
| 204 | + builder.setIntValue(intValue); |
| 205 | + } |
| 206 | + if (stringValue != null) { |
| 207 | + builder.setStringValue(stringValue); |
| 208 | + } |
| 209 | + return builder.build(); |
| 210 | + } |
| 211 | + |
195 | 212 | protected <M extends Message> void saveTestRecords(@Nonnull RecordBuilder<M> builder) { |
196 | 213 | recordStore.saveRecord(builder.build("empty", null, null)); |
197 | 214 | recordStore.saveRecord(builder.build("default", 0, "")); |
@@ -429,6 +446,53 @@ public void testProto3Explicit() { |
429 | 446 | } |
430 | 447 | } |
431 | 448 |
|
| 449 | + // Explicit presence is now the default. |
| 450 | + @Test |
| 451 | + public void testProtoEditions() { |
| 452 | + try (FDBRecordContext context = openContext()) { |
| 453 | + createOrOpenRecordStore(context, protoEditionsMetaData()); |
| 454 | + saveTestRecords(FDBRecordStoreNullQueryTest::buildRecordEditions); |
| 455 | + |
| 456 | + assertThat(executeQuery(RecordQuery.newBuilder() |
| 457 | + .setRecordType("MyNullRecord") |
| 458 | + .setFilter(Query.field("int_value").equalsValue(2)) |
| 459 | + .build()), |
| 460 | + is(Collections.singletonList("two"))); |
| 461 | + assertThat(executeQuery(RecordQuery.newBuilder() |
| 462 | + .setRecordType("MyNullRecord") |
| 463 | + .setFilter(Query.field("string_value").equalsValue("B")) |
| 464 | + .build()), |
| 465 | + is(Collections.singletonList("two"))); |
| 466 | + |
| 467 | + assertThat(executeQuery(RecordQuery.newBuilder() |
| 468 | + .setRecordType("MyNullRecord") |
| 469 | + .setFilter(Query.field("int_value").isNull()) |
| 470 | + .build()), |
| 471 | + is(Collections.singletonList("empty"))); |
| 472 | + assertThat(executeQuery(RecordQuery.newBuilder() |
| 473 | + .setRecordType("MyNullRecord") |
| 474 | + .setFilter(Query.field("int_value").equalsValue(0)) |
| 475 | + .build()), |
| 476 | + is(Collections.singletonList("default"))); |
| 477 | + assertThat(executeQuery(RecordQuery.newBuilder() |
| 478 | + .setRecordType("MyNullRecord") |
| 479 | + .setFilter(Query.field("string_value").isNull()) |
| 480 | + .build()), |
| 481 | + is(Collections.singletonList("empty"))); |
| 482 | + assertThat(executeQuery(RecordQuery.newBuilder() |
| 483 | + .setRecordType("MyNullRecord") |
| 484 | + .setFilter(Query.field("string_value").equalsValue("")) |
| 485 | + .build()), |
| 486 | + is(Collections.singletonList("default"))); |
| 487 | + |
| 488 | + assertThat(executeQuery(RecordQuery.newBuilder() |
| 489 | + .setRecordType("MyNullRecord") |
| 490 | + .setSort(Key.Expressions.field("int_value")) |
| 491 | + .build()), |
| 492 | + is(Arrays.asList("empty", "minus", "default", "one", "two"))); |
| 493 | + } |
| 494 | + } |
| 495 | + |
432 | 496 | @Test |
433 | 497 | public void testCompareSerialization() throws Exception { |
434 | 498 | final TestRecordsNulls2Proto.MyNullRecord emptyProto2 = buildRecord2("record", null, null); |
|
0 commit comments