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;
}
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;
}
}
}
}