Skip to content

Commit

Permalink
[DROOLS-7444] join constraints are ignored when BigDecimal equality i… (
Browse files Browse the repository at this point in the history
#5233) (#5327)

* [DROOLS-7444] join constraints are ignored when BigDecimal equality is involved in a Pattern

* - Add more tests

* - added more tests

* - improve assertion
  • Loading branch information
tkobayas authored Jun 19, 2023
1 parent 4f6a0cb commit b4eb5b4
Show file tree
Hide file tree
Showing 5 changed files with 538 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ private static void sortRangeIndexable(BetaNodeFieldConstraint[] constraints, bo
indexable[0] = true;
}

private static boolean isEqualIndexable(BetaNodeFieldConstraint constraint) {
return constraint instanceof IndexableConstraint && ((IndexableConstraint)constraint).getConstraintType() == ConstraintType.EQUAL;
static boolean isEqualIndexable(BetaNodeFieldConstraint constraint) {
return constraint instanceof IndexableConstraint && ((IndexableConstraint)constraint).getConstraintType() == ConstraintType.EQUAL && !isBigDecimalEqualityConstraint((IndexableConstraint)constraint);
}

private static void swap(BetaNodeFieldConstraint[] constraints, int p1, int p2) {
Expand Down Expand Up @@ -334,7 +334,7 @@ public static ConstraintType getType(Constraint constraint) {

public static class Factory {
public static BetaMemory createBetaMemory(RuleBaseConfiguration config, short nodeType, BetaNodeFieldConstraint... constraints) {
if (config.getCompositeKeyDepth() < 1 || containsBigDecimalEqualityConstraint(constraints)) {
if (config.getCompositeKeyDepth() < 1) {
return new BetaMemory( config.isSequential() ? null : new TupleList(),
new TupleList(),
createContext(constraints),
Expand All @@ -348,17 +348,8 @@ public static BetaMemory createBetaMemory(RuleBaseConfiguration config, short no
nodeType );
}

private static boolean containsBigDecimalEqualityConstraint(BetaNodeFieldConstraint[] constraints) {
for (BetaNodeFieldConstraint constraint : constraints) {
if (constraint instanceof IndexableConstraint && isBigDecimalEqualityConstraint((IndexableConstraint) constraint)) {
return true;
}
}
return false;
}

private static TupleMemory createRightMemory(RuleBaseConfiguration config, IndexSpec indexSpec) {
if ( !config.isIndexRightBetaMemory() || !indexSpec.constraintType.isIndexable() ) {
if ( !config.isIndexRightBetaMemory() || !indexSpec.constraintType.isIndexable() || indexSpec.indexes.length == 0 ) {
return new TupleList();
}

Expand All @@ -377,7 +368,7 @@ private static TupleMemory createLeftMemory(RuleBaseConfiguration config, IndexS
if (config.isSequential()) {
return null;
}
if ( !config.isIndexLeftBetaMemory() || !indexSpec.constraintType.isIndexable() ) {
if ( !config.isIndexLeftBetaMemory() || !indexSpec.constraintType.isIndexable() || indexSpec.indexes.length == 0 ) {
return new TupleList();
}

Expand Down Expand Up @@ -417,11 +408,13 @@ private void init(short nodeType, BetaNodeFieldConstraint[] constraints, RuleBas

if (constraintType == ConstraintType.EQUAL) {
List<FieldIndex> indexList = new ArrayList<>();
indexList.add(((IndexableConstraint)constraints[firstIndexableConstraint]).getFieldIndex());
if (isEqualIndexable(constraints[firstIndexableConstraint])) {
indexList.add(((IndexableConstraint)constraints[firstIndexableConstraint]).getFieldIndex());
}

// look for other EQUAL constraint to eventually add them to the index
for (int i = firstIndexableConstraint+1; i < constraints.length && indexList.size() < keyDepth; i++) {
if ( ConstraintType.getType(constraints[i]) == ConstraintType.EQUAL && ! ((IndexableConstraint) constraints[i]).isUnification() ) {
if ( isEqualIndexable(constraints[i]) && ! ((IndexableConstraint) constraints[i]).isUnification() ) {
indexList.add(((IndexableConstraint)constraints[i]).getFieldIndex());
}
}
Expand Down
Loading

0 comments on commit b4eb5b4

Please sign in to comment.