use of org.drools.core.util.index.TupleIndexHashTable in project drools by kiegroup.
the class BaseBetaConstraintsTest method checkBetaConstraints.
protected void checkBetaConstraints(BetaNodeFieldConstraint[] constraints, Class cls, short betaNodeType) {
RuleBaseConfiguration config = new RuleBaseConfiguration();
int depth = config.getCompositeKeyDepth();
BetaConstraints betaConstraints;
try {
betaConstraints = (BetaConstraints) cls.getConstructor(new Class[] { BetaNodeFieldConstraint[].class, RuleBaseConfiguration.class }).newInstance(constraints, config);
} catch (Exception e) {
throw new RuntimeException("could not invoke constructor for " + cls.getName());
}
betaConstraints.initIndexes(depth, betaNodeType);
// BetaConstraints betaConstraints = new DefaultBetaConstraints(constraints, config );
constraints = betaConstraints.getConstraints();
List<Integer> list = new ArrayList<Integer>();
// get indexed positions
for (int i = 0; i < constraints.length && list.size() < depth; i++) {
if (((IndexableConstraint) constraints[i]).isIndexable(betaNodeType)) {
list.add(i);
}
}
// convert to array
int[] indexedPositions = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
indexedPositions[i] = i;
}
assertEquals((indexedPositions.length > 0), betaConstraints.isIndexed());
assertEquals(indexedPositions.length, betaConstraints.getIndexCount());
BetaMemory betaMemory = betaConstraints.createBetaMemory(config, NodeTypeEnums.JoinNode);
if (indexedPositions.length > 0) {
if (((IndexableConstraint) constraints[indexedPositions[0]]).getConstraintType() == ConstraintType.EQUAL) {
TupleIndexHashTable tupleHashTable = (TupleIndexHashTable) betaMemory.getLeftTupleMemory();
assertTrue(tupleHashTable.isIndexed());
Index index = tupleHashTable.getIndex();
for (int i = 0; i < indexedPositions.length; i++) {
checkSameConstraintForIndex((IndexableConstraint) constraints[indexedPositions[i]], index.getFieldIndex(i));
}
TupleIndexHashTable factHashTable = (TupleIndexHashTable) betaMemory.getRightTupleMemory();
assertTrue(factHashTable.isIndexed());
index = factHashTable.getIndex();
for (int i = 0; i < indexedPositions.length; i++) {
checkSameConstraintForIndex((IndexableConstraint) constraints[indexedPositions[i]], index.getFieldIndex(i));
}
} else {
}
} else {
TupleList tupleHashTable = (TupleList) betaMemory.getLeftTupleMemory();
assertFalse(tupleHashTable.isIndexed());
TupleList factHashTable = (TupleList) betaMemory.getRightTupleMemory();
assertFalse(factHashTable.isIndexed());
}
}
Aggregations