Search in sources :

Example 1 with MultipleFieldEqualitor

use of org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor in project lucene-solr by apache.

the class BiJoinStream method createIterationComparator.

private StreamComparator createIterationComparator(StreamEqualitor eq, StreamComparator comp) throws IOException {
    if (eq instanceof MultipleFieldEqualitor && comp instanceof MultipleFieldComparator) {
        // we know the comp is at least as long as the eq because we've already validated the tuple order
        StreamComparator[] compoundComps = new StreamComparator[((MultipleFieldEqualitor) eq).getEqs().length];
        for (int idx = 0; idx < compoundComps.length; ++idx) {
            StreamEqualitor sourceEqualitor = ((MultipleFieldEqualitor) eq).getEqs()[idx];
            StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[idx];
            if (sourceEqualitor instanceof FieldEqualitor && sourceComparator instanceof FieldComparator) {
                FieldEqualitor fieldEqualitor = (FieldEqualitor) sourceEqualitor;
                FieldComparator fieldComparator = (FieldComparator) sourceComparator;
                compoundComps[idx] = new FieldComparator(fieldEqualitor.getLeftFieldName(), fieldEqualitor.getRightFieldName(), fieldComparator.getOrder());
            } else {
                throw new IOException("Failed to create an iteration comparator");
            }
        }
        return new MultipleFieldComparator(compoundComps);
    } else if (comp instanceof MultipleFieldComparator) {
        StreamEqualitor sourceEqualitor = eq;
        StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[0];
        if (sourceEqualitor instanceof FieldEqualitor && sourceComparator instanceof FieldComparator) {
            FieldEqualitor fieldEqualitor = (FieldEqualitor) sourceEqualitor;
            FieldComparator fieldComparator = (FieldComparator) sourceComparator;
            return new FieldComparator(fieldEqualitor.getLeftFieldName(), fieldEqualitor.getRightFieldName(), fieldComparator.getOrder());
        } else {
            throw new IOException("Failed to create an iteration comparator");
        }
    } else {
        StreamEqualitor sourceEqualitor = eq;
        StreamComparator sourceComparator = comp;
        if (sourceEqualitor instanceof FieldEqualitor && sourceComparator instanceof FieldComparator) {
            FieldEqualitor fieldEqualitor = (FieldEqualitor) sourceEqualitor;
            FieldComparator fieldComparator = (FieldComparator) sourceComparator;
            return new FieldComparator(fieldEqualitor.getLeftFieldName(), fieldEqualitor.getRightFieldName(), fieldComparator.getOrder());
        } else {
            throw new IOException("Failed to create an iteration comparator");
        }
    }
}
Also used : MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) StreamComparator(org.apache.solr.client.solrj.io.comp.StreamComparator) FieldEqualitor(org.apache.solr.client.solrj.io.eq.FieldEqualitor) MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) StreamEqualitor(org.apache.solr.client.solrj.io.eq.StreamEqualitor) IOException(java.io.IOException)

Example 2 with MultipleFieldEqualitor

use of org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor in project lucene-solr by apache.

the class SolrTable method handleSelectDistinctMapReduce.

private TupleStream handleSelectDistinctMapReduce(final String zkHost, final String collection, final Properties properties, final List<Map.Entry<String, Class>> fields, final String query, final List<Pair<String, String>> orders, final Bucket[] buckets, final String limit) throws IOException {
    int numWorkers = Integer.parseInt(properties.getProperty("numWorkers", "1"));
    String fl = getFields(fields);
    String sort = null;
    StreamEqualitor ecomp = null;
    StreamComparator comp = null;
    if (orders != null && orders.size() > 0) {
        StreamComparator[] adjustedSorts = adjustSorts(orders, buckets);
        // Because of the way adjustSorts works we know that each FieldComparator has a single
        // field name. For this reason we can just look at the leftFieldName
        FieldEqualitor[] fieldEqualitors = new FieldEqualitor[adjustedSorts.length];
        StringBuilder buf = new StringBuilder();
        for (int i = 0; i < adjustedSorts.length; i++) {
            FieldComparator fieldComparator = (FieldComparator) adjustedSorts[i];
            fieldEqualitors[i] = new FieldEqualitor(fieldComparator.getLeftFieldName());
            if (i > 0) {
                buf.append(",");
            }
            buf.append(fieldComparator.getLeftFieldName()).append(" ").append(fieldComparator.getOrder().toString());
        }
        sort = buf.toString();
        if (adjustedSorts.length == 1) {
            ecomp = fieldEqualitors[0];
            comp = adjustedSorts[0];
        } else {
            ecomp = new MultipleFieldEqualitor(fieldEqualitors);
            comp = new MultipleFieldComparator(adjustedSorts);
        }
    } else {
        StringBuilder sortBuf = new StringBuilder();
        FieldEqualitor[] equalitors = new FieldEqualitor[buckets.length];
        StreamComparator[] streamComparators = new StreamComparator[buckets.length];
        for (int i = 0; i < buckets.length; i++) {
            equalitors[i] = new FieldEqualitor(buckets[i].toString());
            streamComparators[i] = new FieldComparator(buckets[i].toString(), ComparatorOrder.ASCENDING);
            if (i > 0) {
                sortBuf.append(',');
            }
            sortBuf.append(buckets[i].toString()).append(" asc");
        }
        sort = sortBuf.toString();
        if (equalitors.length == 1) {
            ecomp = equalitors[0];
            comp = streamComparators[0];
        } else {
            ecomp = new MultipleFieldEqualitor(equalitors);
            comp = new MultipleFieldComparator(streamComparators);
        }
    }
    ModifiableSolrParams params = new ModifiableSolrParams();
    params.set(CommonParams.FL, fl);
    params.set(CommonParams.Q, query);
    params.set(CommonParams.WT, CommonParams.JAVABIN);
    //Always use the /export handler for Distinct Queries because it requires exporting full result sets.
    params.set(CommonParams.QT, "/export");
    if (numWorkers > 1) {
        params.set("partitionKeys", getPartitionKeys(buckets));
    }
    params.set(SORT, sort);
    TupleStream tupleStream = null;
    CloudSolrStream cstream = new CloudSolrStream(zkHost, collection, params);
    tupleStream = new UniqueStream(cstream, ecomp);
    if (numWorkers > 1) {
        // Do the unique in parallel
        // Maintain the sort of the Tuples coming from the workers.
        ParallelStream parallelStream = new ParallelStream(zkHost, collection, tupleStream, numWorkers, comp);
        StreamFactory factory = new StreamFactory().withFunctionName("search", CloudSolrStream.class).withFunctionName("parallel", ParallelStream.class).withFunctionName("unique", UniqueStream.class);
        parallelStream.setStreamFactory(factory);
        tupleStream = parallelStream;
    }
    if (limit != null) {
        tupleStream = new LimitStream(tupleStream, Integer.parseInt(limit));
    }
    return tupleStream;
}
Also used : StreamComparator(org.apache.solr.client.solrj.io.comp.StreamComparator) MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) FieldEqualitor(org.apache.solr.client.solrj.io.eq.FieldEqualitor) MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) StreamFactory(org.apache.solr.client.solrj.io.stream.expr.StreamFactory) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) StreamEqualitor(org.apache.solr.client.solrj.io.eq.StreamEqualitor) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)

Example 3 with MultipleFieldEqualitor

use of org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor in project lucene-solr by apache.

the class BiJoinStream method createSideComparator.

private StreamComparator createSideComparator(StreamEqualitor eq, StreamComparator comp) throws IOException {
    if (eq instanceof MultipleFieldEqualitor && comp instanceof MultipleFieldComparator) {
        // we know the comp is at least as long as the eq because we've already validated the tuple order
        StreamComparator[] compoundComps = new StreamComparator[((MultipleFieldEqualitor) eq).getEqs().length];
        for (int idx = 0; idx < compoundComps.length; ++idx) {
            StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[idx];
            if (sourceComparator instanceof FieldComparator) {
                FieldComparator fieldComparator = (FieldComparator) sourceComparator;
                compoundComps[idx] = new FieldComparator(fieldComparator.getLeftFieldName(), fieldComparator.getRightFieldName(), fieldComparator.getOrder());
            } else {
                throw new IOException("Failed to create an side comparator");
            }
        }
        return new MultipleFieldComparator(compoundComps);
    } else if (comp instanceof MultipleFieldComparator) {
        StreamComparator sourceComparator = ((MultipleFieldComparator) comp).getComps()[0];
        if (sourceComparator instanceof FieldComparator) {
            FieldComparator fieldComparator = (FieldComparator) sourceComparator;
            return new FieldComparator(fieldComparator.getLeftFieldName(), fieldComparator.getRightFieldName(), fieldComparator.getOrder());
        } else {
            throw new IOException("Failed to create an side comparator");
        }
    } else {
        StreamComparator sourceComparator = comp;
        if (sourceComparator instanceof FieldComparator) {
            FieldComparator fieldComparator = (FieldComparator) sourceComparator;
            return new FieldComparator(fieldComparator.getLeftFieldName(), fieldComparator.getRightFieldName(), fieldComparator.getOrder());
        } else {
            throw new IOException("Failed to create an side comparator");
        }
    }
}
Also used : MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) StreamComparator(org.apache.solr.client.solrj.io.comp.StreamComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) IOException(java.io.IOException)

Example 4 with MultipleFieldEqualitor

use of org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor in project lucene-solr by apache.

the class ReducerStream method convertToEqualitor.

private StreamEqualitor convertToEqualitor(StreamComparator comp) {
    if (comp instanceof MultipleFieldComparator) {
        MultipleFieldComparator mComp = (MultipleFieldComparator) comp;
        StreamEqualitor[] eqs = new StreamEqualitor[mComp.getComps().length];
        for (int idx = 0; idx < mComp.getComps().length; ++idx) {
            eqs[idx] = convertToEqualitor(mComp.getComps()[idx]);
        }
        return new MultipleFieldEqualitor(eqs);
    } else {
        FieldComparator fComp = (FieldComparator) comp;
        return new FieldEqualitor(fComp.getLeftFieldName(), fComp.getRightFieldName());
    }
}
Also used : MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) FieldEqualitor(org.apache.solr.client.solrj.io.eq.FieldEqualitor) MultipleFieldEqualitor(org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) FieldComparator(org.apache.solr.client.solrj.io.comp.FieldComparator) MultipleFieldComparator(org.apache.solr.client.solrj.io.comp.MultipleFieldComparator) StreamEqualitor(org.apache.solr.client.solrj.io.eq.StreamEqualitor)

Aggregations

FieldComparator (org.apache.solr.client.solrj.io.comp.FieldComparator)4 MultipleFieldComparator (org.apache.solr.client.solrj.io.comp.MultipleFieldComparator)4 MultipleFieldEqualitor (org.apache.solr.client.solrj.io.eq.MultipleFieldEqualitor)4 StreamComparator (org.apache.solr.client.solrj.io.comp.StreamComparator)3 FieldEqualitor (org.apache.solr.client.solrj.io.eq.FieldEqualitor)3 StreamEqualitor (org.apache.solr.client.solrj.io.eq.StreamEqualitor)3 IOException (java.io.IOException)2 StreamFactory (org.apache.solr.client.solrj.io.stream.expr.StreamFactory)1 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)1