Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

How to handle complex or and ands #18

Open
ishwor-mis opened this issue Apr 15, 2015 · 8 comments
Open

How to handle complex or and ands #18

ishwor-mis opened this issue Apr 15, 2015 · 8 comments

Comments

@ishwor-mis
Copy link

Is it possible to handle a case where we need to handle complex or and and filters as the filter below?

$filter=Name eq 'John' and LastName eq 'Doe' or MiddleName eq 'mdle' and emailAddress eq '[email protected]'

Here I am trying to do the following

select * from sometable where Name='John' and (LastName='Doe' or MiddleName='mdle') and emailAddress='[email protected]'

@Hakaze
Copy link

Hakaze commented Aug 22, 2015

So far it seems this parser is not capable of having (a and b) or (c and d). Since this is not a farfetched use case, it would be great to have this feature!

@armw4
Copy link

armw4 commented Sep 1, 2015

@Hakaze agreed

@armw4
Copy link

armw4 commented Sep 1, 2015

It needs to handle operator precedence properly.

@DannyDouglass
Copy link

👍

@DannyDouglass
Copy link

@ishwor-mis can you provide any insight on this issue?

@armw4
Copy link

armw4 commented Sep 15, 2015

What I have found is that if you want to do something like:

$filter=Name eq 'John' and LastName eq 'Doe' or MiddleName eq 'mdle' and emailAddress eq '[email protected]'

You must help this parser out by using grouping operators (, and ). If you do this, the parser will do a much better job at constructing the Abstract Syntax Tree (AST).

So I would change the aforementioned filter to:

$filter=(Name eq 'John' and LastName eq 'Doe') or (MiddleName eq 'mdle' and emailAddress eq '[email protected]')

The resulting AST will be much different (Array based), but will be straightforward enough to decompose/map (via recursion).

@mkasberg
Copy link

mkasberg commented Apr 9, 2016

The PEG grammar used still doesn't handle operator precedence correctly. But now that #23 is merged, there is a simple workaround - just use parenthesis in your $filter clause.

@armw4
Copy link

armw4 commented Apr 9, 2016

You mean like I did above? That's worked for some time now

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants