You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Harold Roussel <ha...@gmail.com> on 2021/01/09 23:47:12 UTC

Getting notified of parenthesis in ExpressionVisitor when parsing a $filter.

Hello,

I'm currently working on a OData layer (through olingo) that needs to 
format SOAP requests to a backend system, especially for the case of 
using a $filter.

So far I've had good success with simple, non ambiguous linear 
expressions like

A and B and C or D

as I can construct a sequence of XML nodes to the backend representing 
the various conditions and the operators.  Note that this backend system 
takes a flat sequence on nodes with an operator describing the 
connection of the current evaluation result with the next node.  So if I 
have the following $filter expression,

$filter=productType eq 'components' and brand eq 'ABC'

it will produce something like,

<criteria>
     <nodeOperator>AND</nodeOperator>
     <fieldName>productType</fieldName>
     <operator>EQ</operator>
     <value>components</value>
</criteria>
<criteria>
     <nodeOperator>NONE</nodeOperator>
     <fieldName>brand</fieldName>
     <operator>EQ</operator>
     <value>ABC</value>
</criteria>

The last criteria always has the nodeOperator "NONE" since no criteria 
follows.

In case you wonder why I don't evaluate the expression on each result as 
they come in, well it's because there could be millions of results.  So 
I need to send the query to the backend to retrieve only the matching 
results.

So, finally my question is, how could I get the parenthesis in an 
expression like follows in the ExpressionVisitor,

$filter=productType eq 'components' and (brand eq 'ABC' or brand eq 'DEF')

as I must produce an output for my backend service that would look like,

<criteria>
     <nodeOperator>AND</nodeOperator>
     <fieldName>productType</fieldName>
     <operator>EQ</operator>
     <value>components</value>
</criteria>
<criteria>
     <nodeOperator>OPEN_PAR</nodeOperator>
</criteria>
<criteria>
     <nodeOperator>OR</nodeOperator>
     <fieldName>brand</fieldName>
     <operator>EQ</operator>
     <value>ABC</value>
</criteria>
<criteria>
     <nodeOperator>NONE</nodeOperator>
     <fieldName>brand</fieldName>
     <operator>EQ</operator>
     <value>DEF</value>
</criteria>
<criteria>
     <nodeOperator>CLOSE_PAR</nodeOperator>
</criteria>

Is it possible to extend the ExpressionVisitor to achieve this?

Thanks,
Harold



Re: Getting notified of parenthesis in ExpressionVisitor when parsing a $filter.

Posted by Harold Roussel <ha...@gmail.com>.
Answering my own post.  I realized I can just assume that in 
visitBinaryOperator for example, when getting two criteria I'll just 
wrap them in parenthesis.

Harold

On 2021-01-09 6:47 p.m., Harold Roussel wrote:
> Hello,
>
> I'm currently working on a OData layer (through olingo) that needs to 
> format SOAP requests to a backend system, especially for the case of 
> using a $filter.
>
> So far I've had good success with simple, non ambiguous linear 
> expressions like
>
> A and B and C or D
>
> as I can construct a sequence of XML nodes to the backend representing 
> the various conditions and the operators.  Note that this backend 
> system takes a flat sequence on nodes with an operator describing the 
> connection of the current evaluation result with the next node.  So if 
> I have the following $filter expression,
>
> $filter=productType eq 'components' and brand eq 'ABC'
>
> it will produce something like,
>
> <criteria>
>     <nodeOperator>AND</nodeOperator>
>     <fieldName>productType</fieldName>
>     <operator>EQ</operator>
>     <value>components</value>
> </criteria>
> <criteria>
>     <nodeOperator>NONE</nodeOperator>
>     <fieldName>brand</fieldName>
>     <operator>EQ</operator>
>     <value>ABC</value>
> </criteria>
>
> The last criteria always has the nodeOperator "NONE" since no criteria 
> follows.
>
> In case you wonder why I don't evaluate the expression on each result 
> as they come in, well it's because there could be millions of 
> results.  So I need to send the query to the backend to retrieve only 
> the matching results.
>
> So, finally my question is, how could I get the parenthesis in an 
> expression like follows in the ExpressionVisitor,
>
> $filter=productType eq 'components' and (brand eq 'ABC' or brand eq 
> 'DEF')
>
> as I must produce an output for my backend service that would look like,
>
> <criteria>
>     <nodeOperator>AND</nodeOperator>
>     <fieldName>productType</fieldName>
>     <operator>EQ</operator>
>     <value>components</value>
> </criteria>
> <criteria>
>     <nodeOperator>OPEN_PAR</nodeOperator>
> </criteria>
> <criteria>
>     <nodeOperator>OR</nodeOperator>
>     <fieldName>brand</fieldName>
>     <operator>EQ</operator>
>     <value>ABC</value>
> </criteria>
> <criteria>
>     <nodeOperator>NONE</nodeOperator>
>     <fieldName>brand</fieldName>
>     <operator>EQ</operator>
>     <value>DEF</value>
> </criteria>
> <criteria>
>     <nodeOperator>CLOSE_PAR</nodeOperator>
> </criteria>
>
> Is it possible to extend the ExpressionVisitor to achieve this?
>
> Thanks,
> Harold
>
>