dmn-tck / tck

Decision Model and Notation Technology Compatibility Kit
https://dmn-tck.github.io/tck
51 stars 36 forks source link

What is the result of a filter that is not a boolean? #129

Closed etirelli closed 6 years ago

etirelli commented 6 years ago

The spec says, on page 113:

[1, 2, 3, 4][item > 2] = [3, 4]
[ {x:1, y:2}, {x:2, y:3} ][x=1] = {x:1, y:2}

And:

The filter expression is evaluated for each item in list, and a list containing only items where the filter expression is true is returned.

Based on the above, what is the result when a filter evaluates to a non-boolean value and/or to an error?

E.g.:

{ 
    a list : [ { a : false, b : 2 }, { a : null, b : 3 }, { b : 4 }, { a : true, b : 5 } ],
    r : a list[a] 
}.r

Our understanding is that this should:

The result of the expression then would be:

[ { a : true, b : 5 } ]
DanielThanner commented 6 years ago

The spec additionally says in table 54 on page 127 (row 3, column 4): "e1 is a list and type(FEEL(e2, s')) is boolean"

Conclusion: If e2 is not a boolean type (true or false) the expression is not applicable.

I think the complete result of the filter expression should be null.

etirelli commented 6 years ago

@DanielThanner the main reason for my question is because of the "if" statement that says (page 120):

A conditional if a then b else c is equal to b if a is true, and equal to c otherwise.

And Gary confirmed that:

(if "foo" then 1 else 2) = 2

Page 113, on filters, says:

The filter expression is evaluated for each item in list, and a list containing only items where the filter expression is true is returned.

To be honest, my current implementation returns null, as you mentioned. But the above wording makes me think we might be wrong.

DanielThanner commented 6 years ago

May be we should create a OMG ticket to clarify that issue for DMN 1.2.

etirelli commented 6 years ago

I sent the question to Gary just in case. Once we hear from him we can open a ticket if necessary.

garyhallmark commented 6 years ago

I think its worth an issue for the RTF. Table 59 (after ballot 13): Semantics of lists is unclear. The table should be captioned "Semantics of filters". It is unclear how to interpret Applicability. Must the expression be true for every list item? How is applicability related to the domain of the inputs to the filter? If an input is out of its specified domain, the the result must be null. But its not clear here...

opatrascoiu commented 6 years ago

FEEL has a 3-value logic. Hence returning only those elements for which the filter returns true makes sense as true != null .

I believe SQL takes the same approach. Same thing happens in Java if the filter returns nulland is compared against Boolean.TRUE.

agilepro commented 6 years ago

RTF discussed. Last comment above is correct. Closing.