Skip to content

Seemingly inconsistent null handling in List Operators tests #118

Description

@dehall

We've found 2 tests in CqlListOperatorsTest that appear to have inconsistent handling of nulls:

  1. ProperContains9: { 'a', null } properly includes 'a' ==> null
    <test name="ProperContains9" version="1.0">
    <capability code="list-operators" />
    <expression>{ 'a', null } properly includes 'a'</expression>
    <output>null</output>
    </test>

This one we believe is correct. From the ProperContains spec,

this operator returns true if the given element is in the list, and it is not the only element in the list, using equality semantics, with the exception that null elements are considered equal.

(Note we interpret "not the only element" to mean "not the only unique element" here, and a pseudocode for how we would implement ProperContains is list.any?(e -> givenElement == e) and list.any?(e -> givenElement != e) )

In this example, the given element 'a' is in the list, but by the usual equality semantics, null == 'a' evaluates to null, and so evaluating "is it the only element in the list?" must evaluate to null as well and that bubbles up into the overall result.

and

  1. ContainsNullFirst: { null, 'b', 'c' } contains 'a' ==> false
    <test name="ContainsNullFirst" version="1.0">
    <capability code="list-operators" />
    <expression>{ null, 'b', 'c' } contains 'a'</expression>
    <output>false</output>
    </test>

This one we believe is incorrect, and the expected output should instead be null

From the Contains spec,

this operator returns true if the given element is in the list, using equality semantics, with the exception that null elements are considered equal.

In this example, again we have an equality comparison that results in null: null == 'a', none of the comparisons result in true, and so as before this should bubble up to be null for the overall result.

Are we maybe missing something? Or possibly should we be interpreting the null-equality semantics differently in one of these cases?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions