Skip to content

Commit

Permalink
[DROOLS-7398] executable model doesn't resolve bind variable from ano…
Browse files Browse the repository at this point in the history
…ther pattern of the same type in method call in LHS for property reactivity (#5270) (#5339)

* [DROOLS-7398] executable model doesn't resolve bind variable from another pattern of the same type in method call in LHS for property reactivity

* - Add warn log

* - Add more tests
  • Loading branch information
tkobayas authored Jun 22, 2023
1 parent 93aab24 commit a6982e5
Show file tree
Hide file tree
Showing 20 changed files with 261 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -64,7 +65,7 @@ BetaMemory createBetaMemory(final RuleBaseConfiguration config,

void resetFactHandle(final ContextEntry[] context);

BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties);
BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties);

void init(BuildContext context, short betaNodeType);
void initIndexes(int depth, short betaNodeType, RuleBaseConfiguration config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
import java.io.ObjectOutput;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.IndexableConstraint;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -260,10 +262,10 @@ public BetaConstraints getOriginalConstraint() {
throw new UnsupportedOperationException();
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
BitMask mask = getEmptyPropertyReactiveMask(settableProperties.size());
for (BetaNodeFieldConstraint constraint : constraints) {
mask = mask.setAll(constraint.getListenedPropertyMask(modifiedClass, settableProperties));
mask = mask.setAll(constraint.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties));
}
return mask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.drools.core.common;

import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -156,9 +158,9 @@ public BetaConstraints getOriginalConstraint() {
throw new UnsupportedOperationException();
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraints[0].getListenedPropertyMask(modifiedClass, settableProperties)
.setAll(constraints[1].getListenedPropertyMask(modifiedClass, settableProperties));
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraints[0].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties)
.setAll(constraints[1].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties));
}

public void registerEvaluationContext(BuildContext buildContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -149,9 +151,9 @@ public boolean isAllowedCachedRight(ContextEntry[] context,
return this.constraints.isAllowedCachedRight( context, tuple );
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraint0.getListenedPropertyMask(modifiedClass, settableProperties)
.setAll(constraint1.getListenedPropertyMask(modifiedClass, settableProperties));
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraint0.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties)
.setAll(constraint1.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties));
}

public boolean isLeftUpdateOptimizationAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -151,7 +152,7 @@ public BetaConstraints getOriginalConstraint() {
throw new UnsupportedOperationException();
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return getEmptyPropertyReactiveMask(settableProperties.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.drools.core.common;

import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -180,11 +182,11 @@ public BetaConstraints getOriginalConstraint() {
throw new UnsupportedOperationException();
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraints[0].getListenedPropertyMask(modifiedClass, settableProperties)
.setAll(constraints[1].getListenedPropertyMask(modifiedClass, settableProperties))
.setAll(constraints[2].getListenedPropertyMask(modifiedClass, settableProperties))
.setAll(constraints[3].getListenedPropertyMask(modifiedClass, settableProperties));
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraints[0].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties)
.setAll(constraints[1].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties))
.setAll(constraints[2].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties))
.setAll(constraints[3].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties));
}

public void registerEvaluationContext(BuildContext buildContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -156,11 +158,11 @@ public boolean isAllowedCachedRight(ContextEntry[] context,
return this.constraints.isAllowedCachedRight(context, tuple);
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraint0.getListenedPropertyMask(modifiedClass, settableProperties)
.setAll(constraint1.getListenedPropertyMask(modifiedClass, settableProperties))
.setAll(constraint2.getListenedPropertyMask(modifiedClass, settableProperties))
.setAll(constraint3.getListenedPropertyMask(modifiedClass, settableProperties));
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraint0.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties)
.setAll(constraint1.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties))
.setAll(constraint2.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties))
.setAll(constraint3.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties));
}

public boolean isLeftUpdateOptimizationAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -208,8 +210,8 @@ public BetaConstraints getOriginalConstraint() {
throw new UnsupportedOperationException();
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraint.getListenedPropertyMask(modifiedClass, settableProperties);
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraint.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties);
}

public boolean isLeftUpdateOptimizationAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -147,8 +149,8 @@ public boolean isAllowedCachedRight(ContextEntry[] context,
return this.constraints.isAllowedCachedRight( context, tuple );
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraint.getListenedPropertyMask(modifiedClass, settableProperties);
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraint.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties);
}

public boolean isLeftUpdateOptimizationAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.drools.core.common;

import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -168,10 +170,10 @@ public BetaConstraints getOriginalConstraint() {
throw new UnsupportedOperationException();
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraints[0].getListenedPropertyMask(modifiedClass, settableProperties)
.setAll(constraints[1].getListenedPropertyMask(modifiedClass, settableProperties))
.setAll(constraints[2].getListenedPropertyMask(modifiedClass, settableProperties));
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraints[0].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties)
.setAll(constraints[1].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties))
.setAll(constraints[2].getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties));
}

public void registerEvaluationContext(BuildContext buildContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.List;
import java.util.Optional;

import org.drools.core.RuleBaseConfiguration;
import org.drools.core.reteoo.BetaMemory;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.ContextEntry;
import org.drools.core.rule.MutableTypeConstraint;
import org.drools.core.rule.Pattern;
import org.drools.core.spi.BetaNodeFieldConstraint;
import org.drools.core.spi.Tuple;
import org.drools.core.util.bitmask.BitMask;
Expand Down Expand Up @@ -152,10 +154,10 @@ public boolean isAllowedCachedRight(ContextEntry[] context,
return this.constraints.isAllowedCachedRight( context, tuple );
}

public BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties) {
return constraint0.getListenedPropertyMask(modifiedClass, settableProperties)
.setAll(constraint1.getListenedPropertyMask(modifiedClass, settableProperties))
.setAll(constraint2.getListenedPropertyMask(modifiedClass, settableProperties));
public BitMask getListenedPropertyMask(Pattern pattern, Class modifiedClass, List<String> settableProperties) {
return constraint0.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties)
.setAll(constraint1.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties))
.setAll(constraint2.getListenedPropertyMask(Optional.of(pattern), modifiedClass, settableProperties));
}

public boolean isLeftUpdateOptimizationAllowed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ protected void initDeclaredMask(BuildContext context,
rightListenedProperties = pattern.getListenedProperties();
List<String> accessibleProperties = pattern.getAccessibleProperties( context.getKnowledgeBase() );
rightDeclaredMask = pattern.getPositiveWatchMask(accessibleProperties);
rightDeclaredMask = rightDeclaredMask.setAll(constraints.getListenedPropertyMask(objectClass, accessibleProperties));
rightDeclaredMask = rightDeclaredMask.setAll(constraints.getListenedPropertyMask(pattern, objectClass, accessibleProperties));
rightNegativeMask = pattern.getNegativeWatchMask(accessibleProperties);
} else {
// if property reactive is not on, then accept all modification propagations
Expand Down
16 changes: 15 additions & 1 deletion drools-core/src/main/java/org/drools/core/spi/Constraint.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

import org.drools.core.impl.InternalKnowledgeBase;
import org.drools.core.reteoo.builder.BuildContext;
import org.drools.core.rule.Declaration;
import org.drools.core.rule.Pattern;
import org.drools.core.util.bitmask.BitMask;

import static org.drools.core.reteoo.PropertySpecificUtil.allSetButTraitBitMask;
Expand Down Expand Up @@ -76,7 +78,19 @@ void replaceDeclaration(Declaration oldDecl,
*/
boolean isTemporal();

default BitMask getListenedPropertyMask( Class modifiedClass, List<String> settableProperties ) {
default BitMask getListenedPropertyMask(Class modifiedClass, List<String> settableProperties ) {
return getListenedPropertyMask(Optional.empty(), modifiedClass, settableProperties);
}

/**
* Returns property reactivity BitMask of this constraint.
*
* @param pattern which this constraint belongs to. if pattern is empty, bind variables are considered to be declared in the same pattern. It should be fine for alpha constraints
* @param modifiedClass
* @param settableProperties
* @return property reactivity BitMask
*/
default BitMask getListenedPropertyMask(Optional<Pattern> pattern, Class modifiedClass, List<String> settableProperties ) {
return allSetButTraitBitMask();
}

Expand Down
Loading

0 comments on commit a6982e5

Please sign in to comment.