Open APIs

 View Only
  • 1.  What is the expected behavior of a filter when AND is mixed with OR?

    Posted Oct 10, 2023 10:14

    Hello, 

    I have a problem with understanding filter behavior. It is shown in TMF630 part 1 (also in part 6 in the context of ORing jsonPath filters) that two operations are supported:

    1. AND, e.g. attr1=val1&attr2=val2
    2. OR, e.g. attr1=val1;attr2=val2

    If the expression involves only two attributes or only one kind or logical operation, it is simple to deduce the outcome. However, when we mix AND with OR, what is the correct behavior? Lets take for example the following expression:

    att1=val1;att2=val2&attr1=val3

    If we assume that AND has higher precedence then it should be evaluated first. Is that correct? If it is, it means that it is impossible to create a condition in the following format: (con1 OR con2) AND (con3 OR con4).

    And what if we exchange att1 with att2, like this:

     att2=val2;att1=val1&attr1=val3

    TMF630 states that the same attribute on both sides of AND results in oring. Does that mean that the result of changed expression is the same as att2=val2;att1=val1,val3?

    Thank you in advance for the answer

    Best regards



    ------------------------------
    Piotr Ledwoń
    Suntech S.A.
    ------------------------------


  • 2.  RE: What is the expected behavior of a filter when AND is mixed with OR?

    Posted Oct 11, 2023 01:33

    Hi Piotr,

    Agree we are missing some self-explanatory example about filter with AND and OR combination in TMF630 Part 1 section 4.4.

    n The logical AND operation is performed over the attributes that are separated by an ampersand (&) in the query.

    n Multiple values can be passed only in the case of strict equality (=). In this case, the logical OR operation is performed over the list of comma-separated values.

    n An explicit logical OR operation can be set by separating the statements with a semicolon (;). An explicit OR (;) operation takes precedence over the AND (&) operation.

    Example:

    catalog/item?size%3D%3Dsmall%2Cmedium%26price%3C10%3Bsize%3D%3Dbig&price%3E100

    i.e. catalog/item?size==small,medium&price<10;size==big&price>100 (non encoded)

    This filter returns items that match the following criteria:

    • Size is either small or medium (size==small,medium) AND (&) price is lower than 10 (price<10)

    OR (;)

    • Size is big (size==big) AND (&) price is higher than 100 (price>100)


    ------------------------------
    Christophe MICHEL
    Amdocs Management Limited
    ------------------------------



  • 3.  RE: What is the expected behavior of a filter when AND is mixed with OR?

    Posted Oct 11, 2023 01:34

    Complex queries should be done using JSONPath syntax as described in TMF630 Part 6 JSON Path extension. This provides a clear syntax for arbitrarily complicated queries.

    Note that the IETF Working Group on JSON Path recently submitted a final draft IETF standard to IESG for Publication as an RFC. The next version of TMF630 Part 6 should be refactored to align and reference with this standard, so we have very clear guidance.



    ------------------------------
    Vance Shipley
    SigScale
    ------------------------------



  • 4.  RE: What is the expected behavior of a filter when AND is mixed with OR?

    Posted Oct 11, 2023 01:44

    Echoing Vance on top of my previous post:

    In addition to the below examples, each filter query can also support JSON Path as 'filter' selector, e.g.  "?filter=childResource[?(@.attribute==value)]", to apply for multiple occurences matching childResource.attribute==value.

    Example (same as previous): 

    catalog/item?filter=size==90,100&price<10;size==110&price>100 (non encoded)

    is similar to JSON Path:

    catalog/item?filter=$[?((@.size==90||@.size==100)&&@.price<10)],$[?(@.size==110&&@.price>100)]

    which is indeed much more flexible approach.



    ------------------------------
    Christophe MICHEL
    Amdocs Management Limited
    ------------------------------



  • 5.  RE: What is the expected behavior of a filter when AND is mixed with OR?

    Posted Oct 11, 2023 02:58
    Edited by Piotr Ledwoń Oct 11, 2023 03:00

    Thanks, your answers clarified most of the issues.

    I understand that jsonPath might be better for writing queries, but I am writing a parser for the query string. One thing still is unclear to me. You wrote:

    "Multiple values can be passed only in the case of strict equality (=). In this case, the logical OR operation is performed over the list of comma-separated values.".

    I understand it like this: attr=val1,val2 is OK, attr>val1,val2 is not. However, what about attr=value1&attr=value2? It is stated in TMF630 4.4 that it should result in oring, so unless it will be changed in later revisions, this should also be supported. Can I mix it with other conditions? Can I just assume, that whenever it appears within one AND condition, it just collapses to OR, like in the example below?

    E.g.  attr1=val1&attr2=val2&attr1=val3;attr4=val4 => attr1=val1,val3&attr2=val2;attr4=val4



    ------------------------------
    Piotr Ledwoń
    Suntech S.A.
    ------------------------------



  • 6.  RE: What is the expected behavior of a filter when AND is mixed with OR?

    Posted Oct 11, 2023 03:34

    First, the all attention from previous posts above regarding JSON-Path is about recommendation, which especially flies for any newly introduced API. It is surely understood legacy APIs already in place have the original filter pattern, and are yet to support.

    Then, there is a reason why multiple values can be passed only in the case of strict equality: it is not meaningful for other operators (e.g. attr>val1,val2 is basically same as attr>val where val is min(val1,val2)).

    Similarly there is not point in checking attr=value1&attr=value2 as it will return no result (as long as value1 <> value2, so attr cannot match both at the same time). 



    ------------------------------
    Christophe MICHEL
    Amdocs Management Limited
    ------------------------------