15five / scim2-filter-parser

A customizable parser/transpiler for SCIM2.0 filters
Other
23 stars 8 forks source link

Issue with "=" operator and Transpile to python condition #15

Closed mohankumaru closed 4 years ago

mohankumaru commented 4 years ago

Hi,

I see that "=" is getting replaced by "==", which does not hold good for other operators like "ne" , "ge", "le",which are getting mapped to "!==", ">==", "<==". It is suppose to be "!=", ">=", "<=".

Example:-
"emails[type ne \"work\"]" gets transpiled to emails.type !== "work" expected result: - emails.type != "work"

And,

I was trying to transpile ast to python condition instead of sql syntax, which required minor changes. Below is how i am trying it;

sql = {
            'eq': '=',
            'ne': '!=',
            'co': 'LIKE',
            'sw': 'LIKE',
            'ew': 'LIKE',
            'pr': 'is not None',
            'gt': '>',
            'ge': '>=',
            'lt': '<',
            'le': '<=',
        }

for instance, 'pr' i replaced with python equivalent 'is not None' . I was looking for a way to write python equivalents for 'sw','ew' and 'co', by using startswith() and other python functions. Can you point out what part should be modified?

logston commented 4 years ago

Great find! I'll be able to take a look at this tomorrow.

logston commented 4 years ago

It looks like (based on the unit test I've posted above) that the first part of your comment is not taking place. Ie. There is no "double equals" replacement going on. If you have a unit test to show that such replacement is going on, I'm happy to take a look at it.

As for the second part of this issue, the SQL dict is embedded in the lookup_op method. https://github.com/15five/scim2-filter-parser/blob/master/src/scim2_filter_parser/transpilers/sql.py#L172 That can easily be moved to a class level attribute though so that it can be overridden in subclasses. I'll do that now.

logston commented 4 years ago

Done. If you want, you can fork the repo and use this branch to make your Python port easier.