Skip to content
This repository was archived by the owner on May 5, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</parent>

<properties>
<elasticsearch.version>0.90.5</elasticsearch.version>
<elasticsearch.version>0.90.7</elasticsearch.version>
</properties>

<distributionManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
import org.elasticsearch.common.collect.ImmutableMap;
import org.elasticsearch.common.collect.MapBuilder;
import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.hppc.ObjectIntOpenHashMap;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.joda.time.Chronology;
import org.elasticsearch.common.joda.time.DateTimeField;
import org.elasticsearch.common.joda.time.DateTimeZone;
import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.trove.impl.Constants;
import org.elasticsearch.common.trove.map.hash.TObjectIntHashMap;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
Expand All @@ -34,7 +33,7 @@
public class DistinctDateHistogramFacetParser extends AbstractComponent implements FacetParser {

private final ImmutableMap<String, DateFieldParser> dateFieldParsers;
private final TObjectIntHashMap<String> rounding = new TObjectIntHashMap<String>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, -1);
private final ObjectIntOpenHashMap<String> rounding = new ObjectIntOpenHashMap<String>();

@Inject
public DistinctDateHistogramFacetParser(Settings settings) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package crate.elasticsearch.facet.distinct;

import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.common.hppc.LongObjectOpenHashMap;
import org.elasticsearch.common.logging.ESLogger;
import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.search.facet.Facet;
Expand Down Expand Up @@ -110,6 +111,7 @@ static final class Fields {
@Override
public Facet reduce(ReduceContext context) {
List<Facet> facets = context.facets();

if (facets.size() == 1) {
// we need to sort it
InternalDistinctDateHistogramFacet internalFacet = (InternalDistinctDateHistogramFacet) facets.get(0);
Expand All @@ -118,22 +120,26 @@ public Facet reduce(ReduceContext context) {
return internalFacet;
}

Recycler.V<ExtTLongObjectHashMap<DistinctEntry>> map = context.cacheRecycler().longObjectMap(-1);
Recycler.V<LongObjectOpenHashMap<DistinctEntry>> map = context.cacheRecycler().longObjectMap(-1);
for (Facet facet : facets) {

InternalDistinctDateHistogramFacet histoFacet = (InternalDistinctDateHistogramFacet) facet;
for (DistinctEntry fullEntry : histoFacet.entries) {
DistinctEntry current = map.v().get(fullEntry.getTime());
if (current != null) {
current.getValues().addAll(fullEntry.getValues());

} else {
map.v().put(fullEntry.getTime(), fullEntry);
if(fullEntry != null){
DistinctEntry current = map.v().get(fullEntry.getTime());
if (current != null) {
current.getValues().addAll(fullEntry.getValues());
} else {
map.v().put(fullEntry.getTime(), fullEntry);
}
}

}
}

// sort
Object[] values = map.v().internalValues();
Object[] values = map.v().values;
Arrays.sort(values, (Comparator) comparatorType.comparator());
List<DistinctEntry> ordered = new ArrayList<DistinctEntry>(map.v().size());
for (int i = 0; i < map.v().size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import org.apache.lucene.index.AtomicReaderContext;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.common.hppc.LongObjectOpenHashMap;
import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.search.facet.FacetExecutor;
Expand All @@ -14,6 +14,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

/**
* Collect the distinct values per time interval.
Expand All @@ -27,7 +28,7 @@ public class LongDistinctDateHistogramFacetExecutor extends FacetExecutor {
private MutableDateTime dateTime;
private final long interval;
private final DateHistogramFacet.ComparatorType comparatorType;
final Recycler.V<ExtTLongObjectHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries;
final Recycler.V<LongObjectOpenHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries;
private final CacheRecycler cacheRecycler;

public LongDistinctDateHistogramFacetExecutor(IndexNumericFieldData keyIndexFieldData,
Expand All @@ -50,7 +51,7 @@ public Collector collector() {

@Override
public InternalFacet buildFacet(String facetName) {
ArrayList<LongInternalDistinctDateHistogramFacet.DistinctEntry> entries1 = new ArrayList<LongInternalDistinctDateHistogramFacet.DistinctEntry>(entries.v().valueCollection());
ArrayList<LongInternalDistinctDateHistogramFacet.DistinctEntry> entries1 = new ArrayList<LongInternalDistinctDateHistogramFacet.DistinctEntry>(Arrays.asList(entries.v().values));

entries.release();
return new LongInternalDistinctDateHistogramFacet(facetName, comparatorType, entries1);
Expand Down Expand Up @@ -100,11 +101,11 @@ public static class DateHistogramProc extends LongFacetAggregatorBase {
LongValues valueValues;
private final long interval;
private MutableDateTime dateTime;
final ExtTLongObjectHashMap<InternalDistinctDateHistogramFacet.DistinctEntry> entries;
final LongObjectOpenHashMap<InternalDistinctDateHistogramFacet.DistinctEntry> entries;

final ValueAggregator valueAggregator = new ValueAggregator();

public DateHistogramProc(ExtTLongObjectHashMap<InternalDistinctDateHistogramFacet.DistinctEntry> entries, MutableDateTime dateTime, long interval) {
public DateHistogramProc(LongObjectOpenHashMap<InternalDistinctDateHistogramFacet.DistinctEntry> entries, MutableDateTime dateTime, long interval) {
this.dateTime = dateTime;
this.entries = entries;
this.interval = interval;
Expand All @@ -116,11 +117,11 @@ public DateHistogramProc(ExtTLongObjectHashMap<InternalDistinctDateHistogramFace
*/
@Override
public void onDoc(int docId, LongValues values) {
if (values.hasValue(docId)) {
final LongValues.Iter iter = values.getIter(docId);
while (iter.hasNext()) {
dateTime.setMillis(iter.next());
//dateTime = new MutableDateTime(iter.next());

int totalDocumentEntries= values.setDocument(docId);
if (totalDocumentEntries > 0) {
for(Integer i = 0 ; i < totalDocumentEntries ; i++) {
dateTime.setMillis(values.nextValue());
onValue(docId, dateTime);
total++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
import org.elasticsearch.search.facet.Facet;

import java.io.IOException;
import java.util.*;
import org.elasticsearch.cache.recycler.CacheRecycler;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class LongInternalDistinctDateHistogramFacet extends InternalDistinctDateHistogramFacet {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.common.hppc.LongObjectOpenHashMap;
import org.elasticsearch.common.joda.time.MutableDateTime;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
import org.elasticsearch.index.fielddata.BytesValues;
import org.elasticsearch.index.fielddata.LongValues;
import org.elasticsearch.index.fielddata.plain.PackedArrayIndexFieldData;
Expand All @@ -17,6 +17,7 @@

import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;

/**
* Collect the distinct values per time interval.
Expand All @@ -30,7 +31,7 @@ public class StringDistinctDateHistogramFacetExecutor extends FacetExecutor {
private MutableDateTime dateTime;
private final long interval;
private final DateHistogramFacet.ComparatorType comparatorType;
final Recycler.V<ExtTLongObjectHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries;
final Recycler.V<LongObjectOpenHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries;

public StringDistinctDateHistogramFacetExecutor(PackedArrayIndexFieldData keyIndexFieldData,
PagedBytesIndexFieldData distinctIndexFieldData,
Expand All @@ -51,7 +52,7 @@ public Collector collector() {

@Override
public InternalFacet buildFacet(String facetName) {
ArrayList<InternalDistinctDateHistogramFacet.DistinctEntry> entries1 = new ArrayList<InternalDistinctDateHistogramFacet.DistinctEntry>(entries.v().valueCollection());
ArrayList<InternalDistinctDateHistogramFacet.DistinctEntry> entries1 = new ArrayList<InternalDistinctDateHistogramFacet.DistinctEntry>(Arrays.asList(entries.v().values));
entries.release();
return new StringInternalDistinctDateHistogramFacet(facetName, comparatorType, entries1);
}
Expand All @@ -73,7 +74,7 @@ public Collector() {
@Override
public void setNextReader(AtomicReaderContext context) throws IOException {
keyValues = keyIndexFieldData.load(context).getLongValues();
histoProc.valueValues = distinctIndexFieldData.load(context).getBytesValues();
histoProc.valueValues = distinctIndexFieldData.load(context).getBytesValues(false);
}

@Override
Expand All @@ -98,11 +99,11 @@ public static class DateHistogramProc {
BytesValues.WithOrdinals valueValues;
private final long interval;
private MutableDateTime dateTime;
final Recycler.V<ExtTLongObjectHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries;
final Recycler.V<LongObjectOpenHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries;

final ValueAggregator valueAggregator = new ValueAggregator();

public DateHistogramProc(Recycler.V<ExtTLongObjectHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries, MutableDateTime dateTime, long interval) {
public DateHistogramProc(Recycler.V<LongObjectOpenHashMap<InternalDistinctDateHistogramFacet.DistinctEntry>> entries, MutableDateTime dateTime, long interval) {
this.dateTime = dateTime;
this.entries = entries;
this.interval = interval;
Expand All @@ -112,10 +113,10 @@ public DateHistogramProc(Recycler.V<ExtTLongObjectHashMap<InternalDistinctDateHi
* Pass a dateTime to onValue to account for the interval and rounding that is set in the Parser
*/
public void onDoc(int docId, LongValues values) {
if (values.hasValue(docId)) {
final LongValues.Iter iter = values.getIter(docId);
while (iter.hasNext()) {
dateTime.setMillis(iter.next());
int totalDocumentEntries= values.setDocument(docId);
if (totalDocumentEntries > 0) {
for(Integer i = 0 ; i < totalDocumentEntries ; i++) {
dateTime.setMillis(values.nextValue());
onValue(docId, dateTime);
total++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
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.ExtTLongObjectHashMap;
import org.elasticsearch.search.facet.Facet;
import org.elasticsearch.search.facet.InternalFacet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import org.apache.lucene.util.PriorityQueue;
import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.bytes.HashedBytesArray;
import org.elasticsearch.common.hppc.LongObjectOpenHashMap;
import org.elasticsearch.common.hppc.procedures.LongObjectProcedure;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.trove.map.TLongObjectMap;
import org.elasticsearch.common.trove.procedure.TLongObjectProcedure;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.search.facet.Facet;
Expand Down Expand Up @@ -89,16 +89,15 @@ protected boolean lessThan(Entry a, Entry b) {
}
}

public void insert(TLongObjectMap<InternalLatestFacet.Entry> entries) {
public void insert(LongObjectOpenHashMap<Entry> entries) {
if (queue == null) {
this.queue = new EntryPriorityQueue(start + size);
}
entries.forEachEntry(new TLongObjectProcedure<Entry>() {
entries.forEach(new LongObjectProcedure<Entry>() {
@Override
public boolean execute(long key, Entry entry) {
public void apply(long key, Entry entry) {
entry.key = key;
queue.insertWithOverflow(entry);
return true;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import org.apache.lucene.index.AtomicReaderContext;
import org.elasticsearch.cache.recycler.CacheRecycler;
import org.elasticsearch.common.hppc.LongObjectOpenHashMap;
import org.elasticsearch.common.recycler.Recycler;
import org.elasticsearch.common.trove.ExtTLongObjectHashMap;
import org.elasticsearch.index.fielddata.FieldDataType;
import org.elasticsearch.index.fielddata.IndexNumericFieldData;
import org.elasticsearch.index.fielddata.LongValues;
Expand All @@ -27,7 +27,7 @@ public class LatestFacetExecutor extends FacetExecutor {
protected int size = 10;
protected int start = 0;

final Recycler.V<ExtTLongObjectHashMap<InternalLatestFacet.Entry>> entries;
final Recycler.V<LongObjectOpenHashMap<InternalLatestFacet.Entry>> entries;

public LatestFacetExecutor(IndexNumericFieldData keyField, IndexNumericFieldData valueField,
IndexNumericFieldData tsField, int size, int start, CacheRecycler cacheRecycler) {
Expand Down Expand Up @@ -80,20 +80,22 @@ public void setNextReader(AtomicReaderContext context) throws IOException {

public static class Aggregator extends LongFacetAggregatorBase {

final ExtTLongObjectHashMap<InternalLatestFacet.Entry> entries;
final LongObjectOpenHashMap<InternalLatestFacet.Entry> entries;

LongValues valueValues;
LongValues tsValues;
public Aggregator(ExtTLongObjectHashMap<InternalLatestFacet.Entry> entries){
public Aggregator(LongObjectOpenHashMap<InternalLatestFacet.Entry> entries){
this.entries = entries;
}

@Override
public void onValue(int docId, long key) {
InternalLatestFacet.Entry entry = entries.get(key);
long ts = tsValues.getValue(docId);
tsValues.setDocument(docId);
long ts = tsValues.nextValue();
if (entry == null || entry.ts < ts) {
int value = (int)valueValues.getValue(docId);
valueValues.setDocument(docId);
int value = (int)valueValues.nextValue();
if (entry == null) {
entry = new InternalLatestFacet.Entry(ts, value);
entries.put(key, entry);
Expand Down