Search in sources :

Example 1 with HashKey

use of org.apache.solr.client.solrj.io.comp.HashKey in project lucene-solr by apache.

the class RollupStream method close.

public void close() throws IOException {
    tupleStream.close();
    this.currentMetrics = null;
    this.currentKey = new HashKey("-");
    this.finished = false;
}
Also used : HashKey(org.apache.solr.client.solrj.io.comp.HashKey)

Example 2 with HashKey

use of org.apache.solr.client.solrj.io.comp.HashKey in project lucene-solr by apache.

the class RollupStream method read.

public Tuple read() throws IOException {
    while (true) {
        Tuple tuple = tupleStream.read();
        if (tuple.EOF) {
            if (!finished) {
                if (currentMetrics == null) {
                    return tuple;
                }
                Map<String, Object> map = new HashMap<String, Object>();
                for (Metric metric : currentMetrics) {
                    map.put(metric.getIdentifier(), metric.getValue());
                }
                for (int i = 0; i < buckets.length; i++) {
                    map.put(buckets[i].toString(), currentKey.getParts()[i]);
                }
                Tuple t = new Tuple(map);
                tupleStream.pushBack(tuple);
                finished = true;
                return t;
            } else {
                return tuple;
            }
        }
        Object[] bucketValues = new Object[buckets.length];
        for (int i = 0; i < buckets.length; i++) {
            bucketValues[i] = buckets[i].getBucketValue(tuple);
        }
        HashKey hashKey = new HashKey(bucketValues);
        if (hashKey.equals(currentKey)) {
            for (Metric bucketMetric : currentMetrics) {
                bucketMetric.update(tuple);
            }
        } else {
            Tuple t = null;
            if (currentMetrics != null) {
                Map<String, Object> map = new HashMap<String, Object>();
                for (Metric metric : currentMetrics) {
                    map.put(metric.getIdentifier(), metric.getValue());
                }
                for (int i = 0; i < buckets.length; i++) {
                    map.put(buckets[i].toString(), currentKey.getParts()[i]);
                }
                t = new Tuple(map);
            }
            currentKey = hashKey;
            if (metrics != null) {
                currentMetrics = new Metric[metrics.length];
                for (int i = 0; i < metrics.length; i++) {
                    Metric bucketMetric = metrics[i].newInstance();
                    bucketMetric.update(tuple);
                    currentMetrics[i] = bucketMetric;
                }
            }
            if (t != null) {
                return t;
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) Metric(org.apache.solr.client.solrj.io.stream.metrics.Metric) HashKey(org.apache.solr.client.solrj.io.comp.HashKey) Tuple(org.apache.solr.client.solrj.io.Tuple)

Aggregations

HashKey (org.apache.solr.client.solrj.io.comp.HashKey)2 HashMap (java.util.HashMap)1 Tuple (org.apache.solr.client.solrj.io.Tuple)1 Metric (org.apache.solr.client.solrj.io.stream.metrics.Metric)1