Skip to content

Commit 99656aa

Browse files
committed
Add a nulls test case using Editions syntax.
1 parent 95b8fec commit 99656aa

2 files changed

Lines changed: 101 additions & 0 deletions

File tree

fdb-record-layer-core/src/test/java/com/apple/foundationdb/record/provider/foundationdb/query/FDBRecordStoreNullQueryTest.java

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.apple.foundationdb.record.TestRecordsNulls2Proto;
2727
import com.apple.foundationdb.record.TestRecordsNulls3Proto;
2828
import com.apple.foundationdb.record.TestRecordsNulls3ExplicitProto;
29+
import com.apple.foundationdb.record.TestRecordsNullsEditionsProto;
2930
import com.apple.foundationdb.record.TestRecordsTupleFieldsProto;
3031
import com.apple.foundationdb.record.TupleFieldsProto;
3132
import com.apple.foundationdb.record.metadata.Key;
@@ -113,6 +114,10 @@ protected static RecordMetaData proto3ExplicitMetaData() {
113114
return RecordMetaData.newBuilder().setRecords(TestRecordsNulls3ExplicitProto.getDescriptor()).getRecordMetaData();
114115
}
115116

117+
protected static RecordMetaData protoEditionsMetaData() {
118+
return RecordMetaData.newBuilder().setRecords(TestRecordsNullsEditionsProto.getDescriptor()).getRecordMetaData();
119+
}
120+
116121
@FunctionalInterface
117122
interface RecordBuilder<M extends Message> {
118123
M build(@Nonnull String name, @Nullable Integer intValue, @Nullable String stringValue);
@@ -192,6 +197,18 @@ protected static TestRecordsNulls3ExplicitProto.MyNullRecord buildRecord3Explici
192197
return builder.build();
193198
}
194199

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+
195212
protected <M extends Message> void saveTestRecords(@Nonnull RecordBuilder<M> builder) {
196213
recordStore.saveRecord(builder.build("empty", null, null));
197214
recordStore.saveRecord(builder.build("default", 0, ""));
@@ -429,6 +446,53 @@ public void testProto3Explicit() {
429446
}
430447
}
431448

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+
432496
@Test
433497
public void testCompareSerialization() throws Exception {
434498
final TestRecordsNulls2Proto.MyNullRecord emptyProto2 = buildRecord2("record", null, null);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* test_records_nulls_editions.proto
3+
*
4+
* This source file is part of the FoundationDB open source project
5+
*
6+
* Copyright 2026 Apple Inc. and the FoundationDB project authors
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
edition = "2023";
21+
22+
package com.apple.foundationdb.record.testnullseditions;
23+
24+
option java_package = "com.apple.foundationdb.record";
25+
option java_outer_classname = "TestRecordsNullsEditionsProto";
26+
27+
import "record_metadata_options.proto";
28+
29+
message MyNullRecord {
30+
string name = 1 [(field).primary_key = true];
31+
string string_value = 2 [(field).index = {}];
32+
int32 int_value = 3 [(field).index = {}];
33+
}
34+
35+
message RecordTypeUnion {
36+
MyNullRecord _MyNullRecord = 1;
37+
}

0 commit comments

Comments
 (0)