-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This function will be needed in the upcoming rate aggs tests.
- Loading branch information
Showing
9 changed files
with
171 additions
and
317 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
...plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/AnalyticsTestsUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
|
||
package org.elasticsearch.xpack.analytics; | ||
|
||
import java.io.IOException; | ||
|
||
import org.apache.lucene.document.BinaryDocValuesField; | ||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.search.aggregations.metrics.TDigestState; | ||
|
||
import com.tdunning.math.stats.Centroid; | ||
import com.tdunning.math.stats.TDigest; | ||
|
||
public final class AnalyticsTestsUtils { | ||
|
||
/** | ||
* Generates an index fields for histogram fields. Used in tests of aggregations that work on histogram fields. | ||
*/ | ||
public static BinaryDocValuesField histogramFieldDocValues(String fieldName, double[] values) throws IOException { | ||
TDigest histogram = new TDigestState(100.0); //default | ||
for (double value : values) { | ||
histogram.add(value); | ||
} | ||
BytesStreamOutput streamOutput = new BytesStreamOutput(); | ||
histogram.compress(); | ||
for (Centroid centroid : histogram.centroids()) { | ||
streamOutput.writeVInt(centroid.count()); | ||
streamOutput.writeDouble(centroid.mean()); | ||
} | ||
return new BinaryDocValuesField(fieldName, streamOutput.bytes().toBytesRef()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.