Skip to content

Commit

Permalink
Update behavior of included operator (#1353)
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival authored Apr 19, 2024
1 parent 75801fe commit fe5c101
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,12 @@ public static Object[][] dataMethod() {
"cql/CqlIntervalOperatorsTest/Expand/ExpandPer1",
"cql/CqlIntervalOperatorsTest/Expand/ExpandPer2Days",
"cql/CqlIntervalOperatorsTest/Expand/ExpandPerMinute",
"cql/CqlListOperatorsTest/Contains/ContainsABNullHasNull",
"cql/CqlListOperatorsTest/Distinct/DistinctANullANull",
"cql/CqlListOperatorsTest/Distinct/DistinctNullNullNull",
"cql/CqlListOperatorsTest/Equivalent/Equivalent123AndABC",
"cql/CqlListOperatorsTest/Equivalent/Equivalent123AndString123",
"cql/CqlListOperatorsTest/Equivalent/EquivalentABCAnd123",
"cql/CqlListOperatorsTest/Flatten/FlattenListNullAndNull",
"cql/CqlListOperatorsTest/In/InNullAnd1Null",
"cql/CqlListOperatorsTest/In/InNullEmpty",
"cql/CqlListOperatorsTest/IncludedIn/IncludedInNullRight",
"cql/CqlListOperatorsTest/Includes/IncludesNullLeft",
"cql/CqlListOperatorsTest/Includes/IncludesNullRight",
"cql/CqlListOperatorsTest/IndexOf/IndexOfEmptyNull",
"cql/CqlListOperatorsTest/IndexOf/IndexOfNullIn1Null",
"cql/CqlListOperatorsTest/NotEqual/NotEqual123AndABC",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,12 @@
</test>
<test name="IncludesNullLeft">
<expression>null includes {2}</expression>
<output>null</output>
<output>false</output>
</test>
<!-- this test is going to the ContainsEvaluator -->
<test name="IncludesNullRight">
<expression>{'s', 'a', 'm'} includes null</expression>
<output>null</output>
<output>false</output>
</test>
</group>
<group name="IncludedIn">
Expand Down Expand Up @@ -401,11 +401,11 @@
<!-- the following expression is going to the InEvaluator -->
<test name="IncludedInNullLeft">
<expression>null included in {2}</expression>
<output>null</output>
<output>false</output>
</test>
<test name="IncludedInNullRight">
<expression>{'s', 'a', 'm'} included in null</expression>
<output>null</output>
<output>false</output>
</test>
</group>
<group name="Indexer">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ public static Object internalEvaluate(Object left, Object right, Object expressi
if (left == null && right != null) {
return false;
}
if (right == null) {
return null;
}

// null left operand case
if (expression instanceof As) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@

public class InEvaluator {
public static Boolean in(Object left, Object right, String precision, State state) {
if (left == null) {
return null;
}

if (right == null) {
return false;
}
Expand Down Expand Up @@ -113,6 +109,12 @@ private static Boolean intervalIn(Object left, Interval right, String precision,
private static Boolean listIn(Object left, Iterable<?> right, State state) {
Boolean isEqual;
for (Object element : right) {
// Nulls are considered equivalent in lists
// Other elements use equality semantics
if (element == null && left == null) {
return true;
}

isEqual = EqualEvaluator.equal(left, element, state);
if ((isEqual != null && isEqual)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,15 @@ public static Boolean intervalIncludedIn(Interval left, Interval right, String p
}

public static Boolean listIncludedIn(Iterable<?> left, Iterable<?> right, State state) {
if (left == null) {
return true;
}
if (right == null) {
return false;
}

if (left == null) {
// For singleton values, include in is equivalent to in.
return InEvaluator.in(null, right, null, state);
}

for (Object element : left) {
Object in = InEvaluator.in(element, right, null, state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ public void test_all_interval_operators() {
arrList.add(new Time(15, 12, 13, 999));
Assert.assertTrue(EquivalentEvaluator.equivalent(value, arrList));

value = results.forExpression("ContainsABNullHasNull").value();
assertThat(value, is(true));

value = results.forExpression("ContainsNullFirst").value();
assertThat(value, is(false));

Expand Down Expand Up @@ -288,10 +291,10 @@ public void test_all_interval_operators() {
Assert.assertTrue(EquivalentEvaluator.equivalent(value, new Time(15, 59, 59, 999)));

value = results.forExpression("InNullEmpty").value();
assertThat(value, is(nullValue()));
assertThat(value, is(false));

value = results.forExpression("InNullAnd1Null").value();
assertThat(value, is(nullValue()));
assertThat(value, is(true));

value = results.forExpression("In1Null").value();
assertThat(value, is(false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4690,9 +4690,9 @@ define test_In_IsIn: TestMessage(In_IsIn, 'In_IsIn', toString(true), toString(In
define test_In_IsNotIn: TestMessage(not In_IsNotIn, 'In_IsNotIn', toString(false), toString(In_IsNotIn))
define test_In_TupleIsIn: TestMessage(In_TupleIsIn, 'In_TupleIsIn', toString(true), toString(In_TupleIsIn))
define test_In_TupleIsNotIn: TestMessage(not In_TupleIsNotIn, 'In_TupleIsNotIn', toString(false), toString(In_TupleIsNotIn))
define test_In_NullIn: TestMessage(In_NullIn is null, 'In_NullIn', 'null', toString(In_NullIn))
define test_In_NullIn: TestMessage(In_NullIn, 'In_NullIn', toString(true), toString(In_NullIn))
define test_In_InNull: TestMessage(not In_InNull, 'In_InNull', toString(false), toString(In_InNull))
define test_In_NullNotIn: TestMessage(In_NullNotIn is null, 'In_NullNotIn', 'null', toString(In_NullNotIn))
define test_In_NullNotIn: TestMessage(not In_NullNotIn, 'In_NullNotIn', toString(false), toString(In_NullNotIn))

// Contains
define Contains_IsIn: { 3, 4, 5 } contains 4
Expand All @@ -4708,8 +4708,8 @@ define test_Contains_IsNotIn: TestMessage(not Contains_IsNotIn, 'Contains_IsNotI
define test_Contains_TupleIsIn: TestMessage(Contains_TupleIsIn, 'Contains_TupleIsIn', toString(true), toString(Contains_TupleIsIn))
define test_Contains_TupleIsNotIn: TestMessage(not Contains_TupleIsNotIn, 'Contains_TupleIsNotIn', toString(false), toString(Contains_TupleIsNotIn))
define test_Contains_InNull: TestMessage(not Contains_InNull, 'Contains_InNull', toString(false), toString(Contains_InNull))
define test_Contains_NullIn: TestMessage(Contains_NullIn is null, 'Contains_NullIn', 'null', toString(Contains_NullIn))
define test_Contains_NullNotIn: TestMessage(Contains_NullNotIn is null, 'Contains_NullNotIn', 'null', toString(Contains_NullNotIn))
define test_Contains_NullIn: TestMessage(Contains_NullIn, 'Contains_NullIn', toString(true), toString(Contains_NullIn))
define test_Contains_NullNotIn: TestMessage(not Contains_NullNotIn, 'Contains_NullNotIn', toString(false), toString(Contains_NullNotIn))

// Includes
define Includes_IsIncluded: {1, 2, 3, 4, 5} includes {2, 3, 4}
Expand All @@ -4733,7 +4733,7 @@ define test_Includes_IsSame: TestMessage(Includes_IsSame, 'Includes_IsSame', toS
define test_Includes_IsNotIncluded: TestMessage(not Includes_IsNotIncluded, 'Includes_IsNotIncluded', toString(false), toString(Includes_IsNotIncluded))
define test_Includes_TuplesIncluded: TestMessage(Includes_TuplesIncluded, 'Includes_TuplesIncluded', toString(true), toString(Includes_TuplesIncluded))
define test_Includes_TuplesNotIncluded: TestMessage(not Includes_TuplesNotIncluded, 'Includes_TuplesNotIncluded', toString(false), toString(Includes_TuplesNotIncluded))
define test_Includes_NullIncluded: TestMessage(Includes_NullIncluded, 'Includes_NullIncluded', toString(true), toString(Includes_NullIncluded))
define test_Includes_NullIncluded: TestMessage(not Includes_NullIncluded, 'Includes_NullIncluded', toString(false), toString(Includes_NullIncluded))
define test_Includes_NullIncludes: TestMessage(not Includes_NullIncludes, 'Includes_NullIncludes', toString(false), toString(Includes_NullIncludes))
define test_Includes_DayIncluded: TestMessage(Includes_DayIncluded, 'Includes_DayIncluded', toString(true), toString(Includes_DayIncluded))
define test_Includes_DayNotIncluded: TestMessage(not Includes_DayNotIncluded, 'Includes_DayNotIncluded', toString(false), toString(Includes_DayNotIncluded))
Expand Down Expand Up @@ -4765,7 +4765,7 @@ define test_IncludedIn_IsNotIncluded: TestMessage(not IncludedIn_IsNotIncluded,
define test_IncludedIn_TuplesIncluded: TestMessage(IncludedIn_TuplesIncluded, 'IncludedIn_TuplesIncluded', toString(true), toString(IncludedIn_TuplesIncluded))
define test_IncludedIn_TuplesNotIncluded: TestMessage(not IncludedIn_TuplesNotIncluded, 'IncludedIn_TuplesNotIncluded', toString(false), toString(IncludedIn_TuplesNotIncluded))
define test_IncludedIn_NullIncludes: TestMessage(not IncludedIn_NullIncludes, 'IncludedIn_NullIncludes', toString(false), toString(IncludedIn_NullIncludes))
define test_IncludedIn_NullIncluded: TestMessage(IncludedIn_NullIncluded, 'IncludedIn_NullIncluded', toString(true), toString(IncludedIn_NullIncluded))
define test_IncludedIn_NullIncluded: TestMessage(not IncludedIn_NullIncluded, 'IncludedIn_NullIncluded', toString(false), toString(IncludedIn_NullIncluded))
define test_IncludedIn_DayIncluded: TestMessage(IncludedIn_DayIncluded, 'IncludedIn_DayIncluded', toString(true), toString(IncludedIn_DayIncluded))
define test_IncludedIn_DayNotIncluded: TestMessage(not IncludedIn_DayNotIncluded, 'IncludedIn_DayNotIncluded', toString(false), toString(IncludedIn_DayNotIncluded))
define test_IncludedIn_IntegerIncluded: TestMessage(IncludedIn_IntegerIncluded, 'IncludedIn_IntegerIncluded', toString(true), toString(IncludedIn_IntegerIncluded))
Expand Down

0 comments on commit fe5c101

Please sign in to comment.