Skip to content

Commit

Permalink
elasticsearch 0.90.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ejain committed Nov 8, 2013
1 parent 6c7e59e commit 0d119a6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>0.90.5</version>
<version>0.90.6</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
import java.io.IOException;

import org.apache.lucene.index.AtomicReaderContext;
import org.elasticsearch.common.hppc.LongLongOpenHashMap;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.trove.iterator.TLongLongIterator;
import org.elasticsearch.common.trove.map.hash.TLongLongHashMap;
import org.elasticsearch.index.fielddata.AtomicNumericFieldData;
import org.elasticsearch.index.fielddata.DoubleValues;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
Expand All @@ -22,7 +21,7 @@ public class DecimalHistogramFacetExecutor extends FacetExecutor {
private final double interval;
private final double offset;

final Recycler.V<TLongLongHashMap> counts;
final Recycler.V<LongLongOpenHashMap> counts;

public DecimalHistogramFacetExecutor(IndexNumericFieldData<AtomicNumericFieldData> indexFieldData, double interval, double offset, ComparatorType comparatorType, SearchContext context) {
this.indexFieldData = indexFieldData;
Expand All @@ -40,10 +39,14 @@ public FacetExecutor.Collector collector() {
@Override
public InternalFacet buildFacet(String facetName) {
InternalDecimalHistogramFacet.DecimalEntry[] entries = new InternalDecimalHistogramFacet.DecimalEntry[counts.v().size()];
int i = 0;
for (TLongLongIterator it = counts.v().iterator(); it.hasNext();) {
it.advance();
entries[i++] = new InternalDecimalHistogramFacet.DecimalEntry(it.key(), it.value());
final boolean[] states = counts.v().allocated;
final long[] keys = counts.v().keys;
final long[] values = counts.v().values;
int entryIndex = 0;
for (int i = 0; i < states.length; ++i) {
if (states[i]) {
entries[entryIndex++] = new InternalDecimalHistogramFacet.DecimalEntry(keys[i], values[i]);
}
}
counts.release();
return new InternalDecimalHistogramFacet(facetName, interval, offset, comparatorType, entries);
Expand Down Expand Up @@ -78,9 +81,9 @@ private static class HistogramProc extends DoubleFacetAggregatorBase {

private final double interval;
private final double offset;
private final TLongLongHashMap counts;
private final LongLongOpenHashMap counts;

public HistogramProc(double interval, double offset, TLongLongHashMap counts) {
public HistogramProc(double interval, double offset, LongLongOpenHashMap counts) {
this.interval = interval;
this.offset = offset;
this.counts = counts;
Expand All @@ -89,7 +92,7 @@ public HistogramProc(double interval, double offset, TLongLongHashMap counts) {
@Override
public void onValue(int docId, double value) {
long bucket = (long) Math.floor(((value + offset) / interval));
counts.adjustOrPutValue(bucket, 1, 1);
counts.addTo(bucket, 1);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.hppc.LongLongOpenHashMap;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.trove.iterator.TLongLongIterator;
import org.elasticsearch.common.trove.map.hash.TLongLongHashMap;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.search.facet.Facet;
Expand Down Expand Up @@ -132,18 +131,22 @@ public Facet reduce(ReduceContext context) {
return facet;
}

Recycler.V<TLongLongHashMap> counts = context.cacheRecycler().longLongMap(-1);
Recycler.V<LongLongOpenHashMap> counts = context.cacheRecycler().longLongMap(-1);
for (Facet facet : facets) {
InternalDecimalHistogramFacet histoFacet = (InternalDecimalHistogramFacet) facet;
for (DecimalEntry entry : histoFacet.entries) {
counts.v().adjustOrPutValue(entry.getKey(), entry.getCount(), entry.getCount());
counts.v().addTo(entry.getKey(), entry.getCount());
}
}
final boolean[] states = counts.v().allocated;
final long[] keys = counts.v().keys;
final long[] values = counts.v().values;
DecimalEntry[] entries = new DecimalEntry[counts.v().size()];
int i = 0;
for (TLongLongIterator it = counts.v().iterator(); it.hasNext();) {
it.advance();
entries[i++] = new DecimalEntry(it.key(), it.value());
int entryIndex = 0;
for (int i = 0; i < states.length; ++i) {
if (states[i]) {
entries[entryIndex++] = new DecimalEntry(keys[i], values[i]);
}
}
counts.release();

Expand Down

0 comments on commit 0d119a6

Please sign in to comment.