Search in sources :

Example 26 with AtomicValue

use of org.exist.xquery.value.AtomicValue in project exist by eXist-db.

the class GeneralComparison method nodeSetCompare.

/**
 * Optimized implementation, which can be applied if the left operand returns a node set. In this case, the left expression is executed first. All
 * matching context nodes are then passed to the right expression.
 *
 * @param   nodes            DOCUMENT ME!
 * @param   contextSequence  DOCUMENT ME!
 *
 * @return  DOCUMENT ME!
 *
 * @throws  XPathException  DOCUMENT ME!
 */
protected Sequence nodeSetCompare(NodeSet nodes, Sequence contextSequence) throws XPathException {
    if (context.getProfiler().isEnabled()) {
        context.getProfiler().message(this, Profiler.OPTIMIZATION_FLAGS, "OPTIMIZATION CHOICE", "nodeSetCompare");
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("No index: fall back to nodeSetCompare");
    }
    final long start = System.currentTimeMillis();
    final NodeSet result = new NewArrayNodeSet();
    final Collator collator = getCollator(contextSequence);
    if ((contextSequence != null) && !contextSequence.isEmpty() && !contextSequence.getDocumentSet().contains(nodes.getDocumentSet())) {
        for (final NodeProxy item : nodes) {
            ContextItem context = item.getContext();
            if (context == null) {
                throw (new XPathException(this, "Internal error: context node missing"));
            }
            final AtomicValue lv = item.atomize();
            do {
                final Sequence rs = getRight().eval(context.getNode().toSequence());
                for (final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
                    final AtomicValue rv = i2.nextItem().atomize();
                    if (compareAtomic(collator, lv, rv)) {
                        result.add(item);
                    }
                }
            } while ((context = context.getNextDirect()) != null);
        }
    } else {
        for (final NodeProxy item : nodes) {
            final AtomicValue lv = item.atomize();
            final Sequence rs = getRight().eval(contextSequence);
            for (final SequenceIterator i2 = Atomize.atomize(rs).iterate(); i2.hasNext(); ) {
                final AtomicValue rv = i2.nextItem().atomize();
                if (compareAtomic(collator, lv, rv)) {
                    result.add(item);
                }
            }
        }
    }
    if (context.getProfiler().traceFunctions()) {
        context.getProfiler().traceIndexUsage(context, PerformanceStats.RANGE_IDX_TYPE, this, PerformanceStats.NO_INDEX, System.currentTimeMillis() - start);
    }
    return (result);
}
Also used : NodeSet(org.exist.dom.persistent.NodeSet) VirtualNodeSet(org.exist.dom.persistent.VirtualNodeSet) NewArrayNodeSet(org.exist.dom.persistent.NewArrayNodeSet) NewArrayNodeSet(org.exist.dom.persistent.NewArrayNodeSet) ContextItem(org.exist.dom.persistent.ContextItem) SequenceIterator(org.exist.xquery.value.SequenceIterator) AtomicValue(org.exist.xquery.value.AtomicValue) Sequence(org.exist.xquery.value.Sequence) NodeProxy(org.exist.dom.persistent.NodeProxy) Collator(com.ibm.icu.text.Collator)

Aggregations

AtomicValue (org.exist.xquery.value.AtomicValue)26 Sequence (org.exist.xquery.value.Sequence)16 Collator (com.ibm.icu.text.Collator)9 Item (org.exist.xquery.value.Item)9 SequenceIterator (org.exist.xquery.value.SequenceIterator)9 XPathException (org.exist.xquery.XPathException)6 NumericValue (org.exist.xquery.value.NumericValue)6 StringValue (org.exist.xquery.value.StringValue)5 NodeProxy (org.exist.dom.persistent.NodeProxy)4 ComputableValue (org.exist.xquery.value.ComputableValue)4 IOException (java.io.IOException)3 QName (org.exist.dom.QName)3 QNameValue (org.exist.xquery.value.QNameValue)3 ValueSequence (org.exist.xquery.value.ValueSequence)3 Test (org.junit.Test)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 EXistException (org.exist.EXistException)2 Collection (org.exist.collections.Collection)2 ContextItem (org.exist.dom.persistent.ContextItem)2 NodeSet (org.exist.dom.persistent.NodeSet)2