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

OJAI testing doesn't support LESS condition in queries #8

Open
sanejkom opened this issue Sep 18, 2020 · 2 comments
Open

OJAI testing doesn't support LESS condition in queries #8

sanejkom opened this issue Sep 18, 2020 · 2 comments

Comments

@sanejkom
Copy link

When I built the query using the find(query) method on the DocumentStore where in the query there was a LESS condition, only the values that were equal to the value got returned.
My query condition: condition.is("expiration", QueryCondition.Op.LESS, 123L)

After some debugging I found that class ConditionEvaluator seems to only support EQUALS operation.

Can you verify if the comparison in that class is done correctly in the framework?
Is there a way to test conditions other than EQUALS?

Best regards

@j03810w
Copy link

j03810w commented Mar 29, 2021

I got this to work by altering the ConditionEvaluator#cmp function to accept the compareOperator:

    private boolean cmp(Value value, KeyValue keyValue, Dbfilters.CompareOpProto compareOpProto) {
        if (value.getType() == Value.Type.NULL) {
            return keyValue.getType().getCode() == Value.TYPE_CODE_NULL;
        }
        //assume that the objects are comparable
        Comparable c1 = (Comparable) value.getObject();
        Comparable c2 = (Comparable) keyValue.getObject();
        switch (compareOpProto) {
            case LESS:
                return c1.compareTo(c2) < 0;
            case LESS_OR_EQUAL:
                return c1.compareTo(c2) <= 0;
            case EQUAL:
                return c1.compareTo(c2) == 0;
            case GREATER:
                return c1.compareTo(c2) > 0;
            case GREATER_OR_EQUAL:
                return c1.compareTo(c2) >= 0;
            case NO_OP:
                return true;
            case NOT_EQUAL:
                return c1.compareTo(c2) != 0;
            default:
                throw new IllegalStateException("not sure how you got here");
        }
    }

@anicolaspp
Copy link
Owner

send a PR and I will look into it. @j03810w

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

3 participants