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

Fix evaluation of is not defined expression #108

Merged
merged 1 commit into from
Sep 11, 2024

Conversation

mariofusco
Copy link
Member

No description provided.

@mariofusco mariofusco requested a review from tkobayas September 11, 2024 09:56

@Override
public Function1<PrototypeFactInstance, Object> asFunction(Prototype prototype) {
return delegate.asFunction(prototype).andThen( result -> result == Prototype.UNDEFINED_VALUE ? ADMITTED_UNDEFINED_VALUE : result );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main fix and it is necessary to workaround the fact that on the Drools side it prevents any constraint evaluation, returning false, when it meets an UNDEFINED_VALUE. I preferred to avoid modifying Drools and fix the problem only here. However I believe that, with this trick, it is not bad that an undefined value is actually evaluated only for this constraint (which is the only one that we know at the moment where this is necessary) and not for each and every constraint that at that point will have to deal with it for no reason.

return ExistsField.INSTANCE;
case ExistsField.NEGATED_EXPRESSION_NAME:
// IsNotDefinedExpression behaves as an existential not only when used alone
return ruleContext.getCondition().isSingleCondition() ? ExistsField.INSTANCE : NegatedExistsField.INSTANCE;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I'm clearly making a distinction between the case when the IsNotDefinedExpression is used alone, when it is evaluated as our not existential operator, or in conjuction with another constraint, when it is simply the negation of IsDefinedExpression.

@mariofusco mariofusco merged commit 6b70da0 into kiegroup:main Sep 11, 2024
1 check passed
@mariofusco mariofusco deleted the not_def_fix branch September 11, 2024 12:40
tkobayas pushed a commit to tkobayas/drools-ansible-rulebook-integration that referenced this pull request Sep 13, 2024
mariofusco added a commit that referenced this pull request Sep 13, 2024
* Adding isNotDefined test (#105)

* Clarify IsNotDefined operator behaviour when used alone (#106)

* Fix evaluation of is not defined expression (#108)

---------

Co-authored-by: Mario Fusco <[email protected]>
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

Successfully merging this pull request may close these issues.

2 participants