Skip to content

Commit fc8bbde

Browse files
committed
is distinct from
1 parent abf60b7 commit fc8bbde

File tree

6 files changed

+299
-51
lines changed

6 files changed

+299
-51
lines changed

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/expressions/Comparisons.java

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -234,30 +234,15 @@ public static Object toClassWithRealEquals(@Nullable Object obj) {
234234

235235
@SuppressWarnings("unchecked")
236236
public static int compare(@Nullable Object fieldValue, @Nullable Object comparand) {
237-
if (fieldValue == null) {
238-
if (comparand == null) {
239-
return 0;
240-
} else {
241-
return -1;
242-
}
243-
} else if (comparand == null) {
244-
return 1;
245-
} else {
246-
return toComparable(fieldValue).compareTo(toComparable(comparand));
247-
}
237+
return toComparable(fieldValue).compareTo(toComparable(comparand));
248238
}
249239

250-
@Nullable
251240
@SpotBugsSuppressWarnings("NP_BOOLEAN_RETURN_NULL")
252-
private static Boolean compareEquals(Object value, Object comparand) {
253-
if (value == null || comparand == null) {
254-
return null;
241+
private static boolean compareEquals(@Nonnull Object value, @Nonnull Object comparand) {
242+
if (value instanceof Message) {
243+
return MessageHelpers.compareMessageEquals(value, comparand);
255244
} else {
256-
if (value instanceof Message) {
257-
return MessageHelpers.compareMessageEquals(value, comparand);
258-
} else {
259-
return toClassWithRealEquals(value).equals(toClassWithRealEquals(comparand));
260-
}
245+
return toClassWithRealEquals(value).equals(toClassWithRealEquals(comparand));
261246
}
262247
}
263248

@@ -301,6 +286,9 @@ private static Boolean compareStartsWith(@Nullable Object value, @Nullable Objec
301286
@Nullable
302287
@SpotBugsSuppressWarnings("NP_BOOLEAN_RETURN_NULL")
303288
private static Boolean compareLike(@Nullable Object value, @Nullable Object pattern) {
289+
if (value == null) {
290+
return null;
291+
}
304292
if (!(value instanceof String)) {
305293
throw new RecordCoreException("Illegal comparand value type: " + value);
306294
}
@@ -639,7 +627,6 @@ public enum Type {
639627
STARTS_WITH,
640628
NOT_NULL(false, true),
641629
IS_NULL(true, true),
642-
NOT_DISTINCT_FROM(false),
643630
IN,
644631
TEXT_CONTAINS_ALL(true),
645632
TEXT_CONTAINS_ALL_WITHIN(true),
@@ -651,7 +638,9 @@ public enum Type {
651638
@API(API.Status.EXPERIMENTAL)
652639
SORT(false),
653640
@API(API.Status.EXPERIMENTAL)
654-
LIKE;
641+
LIKE,
642+
IS_DISTINCT_FROM(true),
643+
NOT_DISTINCT_FROM(false);
655644

656645
@Nonnull
657646
private static final Supplier<BiMap<Type, PComparisonType>> protoEnumBiMapSupplier =
@@ -724,30 +713,44 @@ public static Type invertComparisonType(@Nonnull final Comparisons.Type type) {
724713
@Nullable
725714
@SpotBugsSuppressWarnings("NP_BOOLEAN_RETURN_NULL")
726715
public static Boolean evalComparison(@Nonnull Type type, @Nullable Object value, @Nullable Object comparand) {
727-
if (value == null) {
728-
return null;
729-
}
730716
switch (type) {
731717
case STARTS_WITH:
732718
return compareStartsWith(value, comparand);
733719
case IN:
734720
return compareIn(value, comparand);
735721
case EQUALS:
722+
if (value == null || comparand == null) {
723+
return null;
724+
}
736725
return compareEquals(value, comparand);
737726
case NOT_EQUALS:
738-
if (comparand == null) {
727+
if (value == null || comparand == null) {
739728
return null;
740729
}
741730
return !compareEquals(value, comparand);
731+
case IS_DISTINCT_FROM:
732+
return !compareNotDistinctFrom(value, comparand);
742733
case NOT_DISTINCT_FROM:
743734
return compareNotDistinctFrom(value, comparand);
744735
case LESS_THAN:
736+
if (value == null || comparand == null) {
737+
return null;
738+
}
745739
return compare(value, comparand) < 0;
746740
case LESS_THAN_OR_EQUALS:
741+
if (value == null || comparand == null) {
742+
return null;
743+
}
747744
return compare(value, comparand) <= 0;
748745
case GREATER_THAN:
746+
if (value == null || comparand == null) {
747+
return null;
748+
}
749749
return compare(value, comparand) > 0;
750750
case GREATER_THAN_OR_EQUALS:
751+
if (value == null || comparand == null) {
752+
return null;
753+
}
751754
return compare(value, comparand) >= 0;
752755
case LIKE:
753756
return compareLike(value, comparand);

fdb-record-layer-core/src/main/java/com/apple/foundationdb/record/query/plan/cascades/predicates/RangeConstraints.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ private boolean canBeUsedInScanPrefix(@Nonnull final Comparisons.Comparison comp
730730
case NOT_NULL:
731731
case IS_NULL:
732732
case NOT_DISTINCT_FROM:
733+
case IS_DISTINCT_FROM:
733734
return true;
734735
case TEXT_CONTAINS_ALL:
735736
case TEXT_CONTAINS_ALL_WITHIN:

0 commit comments

Comments
 (0)