Search in sources :

Example 6 with IndexableConstraint

use of org.drools.core.rule.IndexableConstraint in project drools by kiegroup.

the class CompositeObjectSinkAdapter method addObjectSink.

public ObjectSinkPropagator addObjectSink(ObjectSink sink, int alphaNodeHashingThreshold) {
    // dirty it, so it'll rebuild on next get
    this.sinks = null;
    if (this.sinksMap != null) {
        this.sinksMap.put(sink, sink);
    }
    if (sink.getType() == NodeTypeEnums.AlphaNode) {
        final AlphaNode alphaNode = (AlphaNode) sink;
        final InternalReadAccessor readAccessor = getHashableAccessor(alphaNode);
        if (readAccessor != null) {
            final int index = readAccessor.getIndex();
            final FieldIndex fieldIndex = registerFieldIndex(index, readAccessor);
            // DROOLS-678 : prevent null values from being hashed as 0s
            final FieldValue value = ((IndexableConstraint) alphaNode.getConstraint()).getField();
            if (fieldIndex.getCount() >= this.alphaNodeHashingThreshold && this.alphaNodeHashingThreshold != 0 && !value.isNull()) {
                if (!fieldIndex.isHashed()) {
                    hashSinks(fieldIndex);
                }
                // no need to check, we know  the sink  does not exist
                this.hashedSinkMap.put(new HashKey(index, value, fieldIndex.getFieldExtractor()), alphaNode, false);
            } else {
                if (this.hashableSinks == null) {
                    this.hashableSinks = new ObjectSinkNodeList();
                }
                this.hashableSinks.add(alphaNode);
            }
            return this;
        }
    }
    if (this.otherSinks == null) {
        this.otherSinks = new ObjectSinkNodeList();
    }
    this.otherSinks.add((ObjectSinkNode) sink);
    return this;
}
Also used : IndexableConstraint(org.drools.core.rule.IndexableConstraint) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) FieldValue(org.drools.core.spi.FieldValue) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) IndexableConstraint(org.drools.core.rule.IndexableConstraint)

Example 7 with IndexableConstraint

use of org.drools.core.rule.IndexableConstraint in project drools by kiegroup.

the class CompositeObjectSinkAdapter method unHashSinks.

void unHashSinks(final FieldIndex fieldIndex) {
    final int index = fieldIndex.getIndex();
    // this is the list of sinks that need to be removed from the hashedSinkMap
    final List<HashKey> unhashedSinks = new ArrayList<HashKey>();
    final Iterator iter = this.hashedSinkMap.newIterator();
    ObjectHashMap.ObjectEntry entry = (ObjectHashMap.ObjectEntry) iter.next();
    while (entry != null) {
        final AlphaNode alphaNode = (AlphaNode) entry.getValue();
        final IndexableConstraint indexableConstraint = (IndexableConstraint) alphaNode.getConstraint();
        // the right field index
        if (index == indexableConstraint.getFieldExtractor().getIndex()) {
            final FieldValue value = indexableConstraint.getField();
            if (this.hashableSinks == null) {
                this.hashableSinks = new ObjectSinkNodeList();
            }
            this.hashableSinks.add(alphaNode);
            unhashedSinks.add(new HashKey(index, value, fieldIndex.getFieldExtractor()));
        }
        entry = (ObjectHashMap.ObjectEntry) iter.next();
    }
    for (HashKey hashKey : unhashedSinks) {
        this.hashedSinkMap.remove(hashKey);
    }
    if (this.hashedSinkMap.isEmpty()) {
        this.hashedSinkMap = null;
    }
    fieldIndex.setHashed(false);
}
Also used : IndexableConstraint(org.drools.core.rule.IndexableConstraint) ArrayList(java.util.ArrayList) Iterator(org.drools.core.util.Iterator) ObjectHashMap(org.drools.core.util.ObjectHashMap) ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry) FieldValue(org.drools.core.spi.FieldValue) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) IndexableConstraint(org.drools.core.rule.IndexableConstraint) ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry)

Example 8 with IndexableConstraint

use of org.drools.core.rule.IndexableConstraint in project drools by kiegroup.

the class CompositePartitionAwareObjectSinkAdapter method hashSink.

private boolean hashSink(ObjectSink sink) {
    InternalReadAccessor readAccessor = getHashableAccessor(sink);
    if (readAccessor != null) {
        int index = readAccessor.getIndex();
        if (fieldIndex == null) {
            this.fieldIndex = new CompositeObjectSinkAdapter.FieldIndex(index, readAccessor);
            this.hashedSinkMap = new ObjectHashMap();
        }
        if (fieldIndex.getIndex() == index) {
            AlphaNode alpha = (AlphaNode) sink;
            this.hashedSinkMap.put(new CompositeObjectSinkAdapter.HashKey(index, ((IndexableConstraint) alpha.getConstraint()).getField(), fieldIndex.getFieldExtractor()), alpha, false);
            return true;
        }
    }
    this.fieldIndex = null;
    this.hashedSinkMap = null;
    return false;
}
Also used : FieldIndex(org.drools.core.reteoo.CompositeObjectSinkAdapter.FieldIndex) IndexableConstraint(org.drools.core.rule.IndexableConstraint) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) ObjectHashMap(org.drools.core.util.ObjectHashMap) IndexableConstraint(org.drools.core.rule.IndexableConstraint)

Aggregations

IndexableConstraint (org.drools.core.rule.IndexableConstraint)8 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)4 FieldValue (org.drools.core.spi.FieldValue)4 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)4 ObjectHashMap (org.drools.core.util.ObjectHashMap)3 ArrayList (java.util.ArrayList)2 BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)2 Constraint (org.drools.core.spi.Constraint)2 HashMap (java.util.HashMap)1 RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)1 InternalKnowledgePackage (org.drools.core.definitions.InternalKnowledgePackage)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 KnowledgeBaseImpl (org.drools.core.impl.KnowledgeBaseImpl)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1 FieldIndex (org.drools.core.reteoo.CompositeObjectSinkAdapter.FieldIndex)1 GroupElement (org.drools.core.rule.GroupElement)1 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)1 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)1 Index (org.drools.core.util.AbstractHashTable.Index)1 Iterator (org.drools.core.util.Iterator)1