Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
package com.apple.foundationdb.record.provider.foundationdb.cursors;

import com.apple.foundationdb.annotation.API;
import com.apple.foundationdb.tuple.ByteArrayUtil;

Check notice on line 24 in fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/provider/foundationdb/cursors/KeyComparisons.java

View workflow job for this annotation

GitHub Actions / coverage

File coverage: 100.0% (25/25 lines) | Changed lines: 100.0% (2/2 lines)
import com.google.protobuf.ByteString;

import java.util.Comparator;
import java.util.List;
Expand All @@ -43,6 +44,8 @@
return 1;
} else if (o1 instanceof byte[]) {
return ByteArrayUtil.compareUnsigned((byte[])o1, (byte[])o2);
} else if (o1 instanceof ByteString) {
return ByteString.unsignedLexicographicalComparator().compare((ByteString)o1, (ByteString)o2);
} else if (o1 instanceof List) {
return KeyComparisons.KEY_COMPARATOR.compare((List<Object>)o1, (List<Object>)o2);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,32 @@ void testUnionOrdered3() throws Exception {
}
}

/**
* Union legs that tie on {@code num_value_2} have to be compared on the ordered bytes of {@code str_value_indexed}.
*/
@DualPlannerTest
void testUnionOrderedOverlappingRanges() throws Exception {
final RecordMetaDataHook hook = indexHook("order_desc_nulls_last");
loadRecords(hook);
final RecordQuery query = RecordQuery.newBuilder()
.setRecordType("MySimpleRecord")
.setSort(fullOrderingKey("order_desc_nulls_last"))
.setFilter(Query.or(
Query.and(Query.field("num_value_2").equalsValue(101),
Query.field("str_value_indexed").greaterThanOrEquals("a"), Query.field("str_value_indexed").lessThan("b")),
Query.and(Query.field("num_value_2").equalsValue(101),
Query.field("str_value_indexed").greaterThan("a"), Query.field("str_value_indexed").lessThanOrEquals("b"))))
.build();
try (FDBRecordContext context = openContext()) {
openSimpleRecordStore(context, hook);
final RecordQueryPlan plan = planner.planQuery(query).getPlan();
final List<Long> actual = plan.execute(recordStore)
.map(r -> r.getPrimaryKey().getLong(0))
.asList().join();
assertEquals(List.of(5L, 4L, 3L), actual);
}
}

@DualPlannerTest
void testCoveringOrdered() throws Exception {
final RecordMetaDataHook hook = indexHook("order_desc_nulls_last");
Expand Down
Loading