Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

contains should contain either value or nested expression #8

Open
Recvi opened this issue Apr 6, 2023 · 2 comments
Open

contains should contain either value or nested expression #8

Recvi opened this issue Apr 6, 2023 · 2 comments

Comments

@Recvi
Copy link

Recvi commented Apr 6, 2023

Hi, really great project!

I'm implementing a Custom Visitor, and it seems from: https://github.com/jazdw/rql-parser/blob/main/src/main/antlr4/net/jazdw/rql/Rql.g4
that contains PredicateOperator can only have a value and not a nested expression.

What I am trying to accomplish is to query a specific field (name) from a list of objects (categories) with multiple values (in operator):
Query:

and(
    in(
      globalProductReferenceId.id, (123567, 891011)
    ),
    in(
      group, (service, addon)
    ),
    contains(
      categories,
      in(
        name,
        (mobile, Roaming)
      )
    )
  )
[
    {
        "name": "TEST",
        "description": "TEST",
        "label": "TEST",
        "status": "TEST",
        "categories": [
            {
                "name": "mobile",
                "id": "TEST"
            },
            {
                "name": "TEST",
                "id": "TEST_2"
            }
        ],
        "globalProductReferenceId": {
            "id": "123567"
        },
        "group": "service"
    },
    {
        "name": "TEST",
        "description": "TEST",
        "label": "TEST",
        "status": "TEST",
        "categories": [
            {
                "name": "mobile",
                "id": "TEST"
            }
        ],
        "globalProductReferenceId": {
            "id": "891011"
        },
        "group": "addon"
    }
]

Do you have any suggestion on how to proceed?

@terrypacker
Copy link

@Recvi we have used the library to filter lists of Pojos by allowing the properties in the query to use the dot notation so your query could look like this perhaps?

and(
    in(
      globalProductReferenceId.id, (123567, 891011)
    ),
    in(
      group, (service, addon)
    ),
    in(
      categories.name, (mobile, Roaming)
    )
)

Here is our implementation:

https://github.com/MangoAutomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/db/query/pojo/RQLFilterJavaBean.java

And the implementation of contains and in:
https://github.com/MangoAutomation/ma-core-public/blob/main/Core/src/com/infiniteautomation/mango/db/query/pojo/RQLFilter.java

The public code we have using it for complex objects is too convoluted to be useful for a reference to you so here is a test showing the usage but on simple types:
https://github.com/MangoAutomation/ma-core-public/blob/main/Core/src-test/com/infiniteautomation/mango/db/query/pojo/RQLFilterJavaBeanTest.java

@Recvi
Copy link
Author

Recvi commented Apr 6, 2023

Thank you @terrypacker, for your response! Your solutions seems like an interesting alternative.
In my case, I want to gather the different inputs into separate collections, cause I want to perform multiple invocations to different retrieval services, so I opted for a Custom Visitor implementation that simply gathers the arguments into different Collections based on the propertyName, have a look at the code in the gist below:

https://gist.github.com/Recvi/9e11c752d5499cb8bcff50af28a81e95

The reason I opted for the contains operator instead of the in is because the categories field is an array, and that's my understanding of how to define a query that matches at least one element of an array.
In the gist code, you may see, as per your suggestion, I opted for an approach that fits the current grammar:

and(
    in(
      globalProductReferenceId.id, (123567, 891011)
    ),
    in(
      group, (service, addon)
    ),
    contains(
      categories.name,
        (mobile, Roaming)
    )
  )

But it still seems, like a limitation not having nested expressions inside contains.

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

No branches or pull requests

2 participants