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

Question: Comparing Distinct Arrays of Objects #258

Open
mahirk opened this issue Mar 11, 2021 · 5 comments
Open

Question: Comparing Distinct Arrays of Objects #258

mahirk opened this issue Mar 11, 2021 · 5 comments

Comments

@mahirk
Copy link
Contributor

mahirk commented Mar 11, 2021

Hello,

I am trying to compare an array of objects to check for a specific set of objects to be present in any of them, but not across all of them, specifically lets take this rule:

const arrayRule = {
        conditions: {
            any: [
                {
                    all: [
                        {
                            fact: 'data',
                            path: '$.[*].equalityTest',
                            operator: 'equal',
                            value: 50,
                        },
                        {
                            fact: 'data',
                            path: '$.[*].anotherTest',
                            operator: 'equal',
                            value: 50,
                        },
                    ],
                },
            ],
        },
        event: {
            type: 'arrayRule',
        },
    };

This is the first iteration of the rule I came up with, it is incorrect, but I wanted to give an idea of what I am aiming for.

Specifically here, we have a rule where I want equalityTest to equal 50 and anotherTest to also equal 50. But I want them to equal those values in the same object, such that:
THIS SHOULD RETURN FALSE

 const facts = {
                data: [
                    {
                        anotherIntegerFact: 1,
                        equalityTest: 50,
                    },
                    {
                        anotherIntegerFact: 50,
                        equalityTest: 40,
                    },
                ],
            };

THIS SHOULD RETURN TRUE

 const facts = {
                data: [
                    {
                        anotherIntegerFact: 50,
                        equalityTest: 50,
                    },
                    {
                        anotherIntegerFact: 40,
                        equalityTest: 40,
                    },
                ],
            };

Would love any suggestions or ideas on a way to tackle this. One thought was I could write my own operator and add it to the registry of operators on our end, but before I did so, I wanted to validate that is needed.

Thanks

@mahirk
Copy link
Contributor Author

mahirk commented Mar 11, 2021

@CacheControl Tagging you because I am unsure of the policy on issues here, thank you in advance!

@alexthehurst
Copy link

We have a similar need. Given an array of objects, I want to return true if and only if one of the objects (evaluated by itself) matches multiple conditions.

@vindu25
Copy link

vindu25 commented Jul 25, 2022

We have similar use case, can someone suggest any ideas around it.

@OmarKhattab
Copy link

Any updates on this? @mahirk @alexthehurst @vindu25

@alexthehurst
Copy link

@OmarKhattab I no longer remember what caused us to hit this issue, but this kind of requirement can probably be worked around with custom operators, which we've since learned are pretty easy to implement in JRE. If you provide samples of what kind of data you want to match, I might be able to give suggestions on implementation.

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

4 participants