mirror of https://github.com/apache/druid.git
increase druid-histogram postagg test coverage (#9732)
This commit is contained in:
parent
accd710115
commit
2c0746cfab
|
@ -142,6 +142,11 @@
|
|||
<artifactId>hamcrest-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>nl.jqno.equalsverifier</groupId>
|
||||
<artifactId>equalsverifier</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.apache.druid.query.aggregation.PostAggregator;
|
|||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class ApproximateHistogramPostAggregator implements PostAggregator
|
||||
{
|
||||
|
@ -65,4 +66,24 @@ public abstract class ApproximateHistogramPostAggregator implements PostAggregat
|
|||
|
||||
@Override
|
||||
public abstract String toString();
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ApproximateHistogramPostAggregator that = (ApproximateHistogramPostAggregator) o;
|
||||
return name.equals(that.name) &&
|
||||
fieldName.equals(that.fieldName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(name, fieldName);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.druid.query.aggregation.post.PostAggregatorIds;
|
|||
import org.apache.druid.query.cache.CacheKeyBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@JsonTypeName("buckets")
|
||||
|
@ -105,4 +106,27 @@ public class BucketsPostAggregator extends ApproximateHistogramPostAggregator
|
|||
.appendFloat(offset)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
BucketsPostAggregator that = (BucketsPostAggregator) o;
|
||||
return Float.compare(that.bucketSize, bucketSize) == 0 &&
|
||||
Float.compare(that.offset, offset) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(super.hashCode(), bucketSize, offset);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ import java.util.Set;
|
|||
public class CustomBucketsPostAggregator extends ApproximateHistogramPostAggregator
|
||||
{
|
||||
private final float[] breaks;
|
||||
private String fieldName;
|
||||
|
||||
@JsonCreator
|
||||
public CustomBucketsPostAggregator(
|
||||
|
@ -47,7 +46,6 @@ public class CustomBucketsPostAggregator extends ApproximateHistogramPostAggrega
|
|||
{
|
||||
super(name, fieldName);
|
||||
this.breaks = breaks;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -93,4 +91,28 @@ public class CustomBucketsPostAggregator extends ApproximateHistogramPostAggrega
|
|||
.appendFloatArray(breaks)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
CustomBucketsPostAggregator that = (CustomBucketsPostAggregator) o;
|
||||
return Arrays.equals(breaks, that.breaks);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + Arrays.hashCode(breaks);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.apache.druid.query.aggregation.post.PostAggregatorIds;
|
|||
import org.apache.druid.query.cache.CacheKeyBuilder;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@JsonTypeName("equalBuckets")
|
||||
|
@ -94,4 +95,26 @@ public class EqualBucketsPostAggregator extends ApproximateHistogramPostAggregat
|
|||
.appendInt(numBuckets)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
EqualBucketsPostAggregator that = (EqualBucketsPostAggregator) o;
|
||||
return numBuckets == that.numBuckets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(super.hashCode(), numBuckets);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ public class MaxPostAggregator extends ApproximateHistogramPostAggregator
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "QuantilePostAggregator{" +
|
||||
return "MaxPostAggregator{" +
|
||||
"fieldName='" + fieldName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ public class MinPostAggregator extends ApproximateHistogramPostAggregator
|
|||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "QuantilePostAggregator{" +
|
||||
return "MinPostAggregator{" +
|
||||
"fieldName='" + fieldName + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.druid.query.cache.CacheKeyBuilder;
|
|||
|
||||
import java.util.Comparator;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
@JsonTypeName("quantile")
|
||||
|
@ -40,7 +41,6 @@ public class QuantilePostAggregator extends ApproximateHistogramPostAggregator
|
|||
static final Comparator COMPARATOR = Comparator.comparingDouble(o -> ((Number) o).doubleValue());
|
||||
|
||||
private final float probability;
|
||||
private final String fieldName;
|
||||
|
||||
@JsonCreator
|
||||
public QuantilePostAggregator(
|
||||
|
@ -51,7 +51,6 @@ public class QuantilePostAggregator extends ApproximateHistogramPostAggregator
|
|||
{
|
||||
super(name, fieldName);
|
||||
this.probability = probability;
|
||||
this.fieldName = fieldName;
|
||||
|
||||
if (probability < 0 || probability > 1) {
|
||||
throw new IAE("Illegal probability[%s], must be strictly between 0 and 1", probability);
|
||||
|
@ -96,38 +95,13 @@ public class QuantilePostAggregator extends ApproximateHistogramPostAggregator
|
|||
return probability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final QuantilePostAggregator that = (QuantilePostAggregator) o;
|
||||
|
||||
if (Float.compare(that.probability, probability) != 0) {
|
||||
return false;
|
||||
}
|
||||
return fieldName != null ? fieldName.equals(that.fieldName) : that.fieldName == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = (probability != +0.0f ? Float.floatToIntBits(probability) : 0);
|
||||
result = 31 * result + (fieldName != null ? fieldName.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "QuantilePostAggregator{" +
|
||||
"probability=" + probability +
|
||||
"name='" + name + '\'' +
|
||||
", fieldName='" + fieldName + '\'' +
|
||||
", probability=" + probability +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
@ -139,4 +113,26 @@ public class QuantilePostAggregator extends ApproximateHistogramPostAggregator
|
|||
.appendFloat(probability)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
QuantilePostAggregator that = (QuantilePostAggregator) o;
|
||||
return Float.compare(that.probability, probability) == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return Objects.hash(super.hashCode(), probability);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,10 +28,10 @@ import java.util.Arrays;
|
|||
@JsonTypeName("quantiles")
|
||||
public class Quantiles
|
||||
{
|
||||
float[] probabilities;
|
||||
float[] quantiles;
|
||||
float min;
|
||||
float max;
|
||||
final float[] probabilities;
|
||||
final float[] quantiles;
|
||||
final float min;
|
||||
final float max;
|
||||
|
||||
@JsonCreator
|
||||
public Quantiles(
|
||||
|
@ -80,23 +80,11 @@ public class Quantiles
|
|||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Quantiles quantiles1 = (Quantiles) o;
|
||||
|
||||
if (Float.compare(quantiles1.max, max) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (Float.compare(quantiles1.min, min) != 0) {
|
||||
return false;
|
||||
}
|
||||
if (!Arrays.equals(probabilities, quantiles1.probabilities)) {
|
||||
return false;
|
||||
}
|
||||
if (!Arrays.equals(quantiles, quantiles1.quantiles)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return Float.compare(quantiles1.min, min) == 0 &&
|
||||
Float.compare(quantiles1.max, max) == 0 &&
|
||||
Arrays.equals(probabilities, quantiles1.probabilities) &&
|
||||
Arrays.equals(quantiles, quantiles1.quantiles);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -122,4 +122,28 @@ public class QuantilesPostAggregator extends ApproximateHistogramPostAggregator
|
|||
.appendFloatArray(probabilities)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
if (!super.equals(o)) {
|
||||
return false;
|
||||
}
|
||||
QuantilesPostAggregator that = (QuantilesPostAggregator) o;
|
||||
return Arrays.equals(probabilities, that.probabilities);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = super.hashCode();
|
||||
result = 31 * result + Arrays.hashCode(probabilities);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -87,6 +87,22 @@ public class ApproximateHistogramAggregationTest extends InitializedNullHandling
|
|||
Assert.assertEquals(92.782760, row.getMetric("index_min").floatValue(), 0.0001);
|
||||
Assert.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001);
|
||||
Assert.assertEquals(133.69340, row.getMetric("index_quantile").floatValue(), 0.0001);
|
||||
Assert.assertEquals(
|
||||
new Quantiles(new float[]{0.2f, 0.7f}, new float[]{92.78276f, 103.195305f}, 92.78276f, 135.109191f),
|
||||
row.getRaw("index_quantiles")
|
||||
);
|
||||
Assert.assertEquals(
|
||||
"Histogram{breaks=[92.0, 94.0, 96.0, 98.0, 100.0, 106.0, 108.0, 134.0, 136.0], counts=[1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]}",
|
||||
row.getRaw("index_buckets").toString()
|
||||
);
|
||||
Assert.assertEquals(
|
||||
"Histogram{breaks=[50.0, 100.0], counts=[3.0]}",
|
||||
row.getRaw("index_custom").toString()
|
||||
);
|
||||
Assert.assertEquals(
|
||||
"Histogram{breaks=[71.61954498291016, 92.78276062011719, 113.94597625732422, 135.10919189453125], counts=[1.0, 3.0, 1.0]}",
|
||||
row.getRaw("index_equal").toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -99,6 +115,22 @@ public class ApproximateHistogramAggregationTest extends InitializedNullHandling
|
|||
Assert.assertEquals(0.0F, row.getMetric("index_min"));
|
||||
Assert.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001);
|
||||
Assert.assertEquals(131.428176, row.getMetric("index_quantile").floatValue(), 0.0001);
|
||||
Assert.assertEquals(
|
||||
new Quantiles(new float[]{0.2f, 0.7f}, new float[]{0.0f, 92.95146f}, 0.0f, 135.109191f),
|
||||
row.getRaw("index_quantiles")
|
||||
);
|
||||
Assert.assertEquals(
|
||||
"Histogram{breaks=[-2.0, 92.0, 94.0, 96.0, 98.0, 100.0, 106.0, 108.0, 134.0, 136.0], counts=[8.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0]}",
|
||||
row.getRaw("index_buckets").toString()
|
||||
);
|
||||
Assert.assertEquals(
|
||||
"Histogram{breaks=[50.0, 100.0], counts=[3.0]}",
|
||||
row.getRaw("index_custom").toString()
|
||||
);
|
||||
Assert.assertEquals(
|
||||
"Histogram{breaks=[-67.55459594726562, 0.0, 67.55459594726562, 135.10919189453125], counts=[8.0, 0.0, 5.0]}",
|
||||
row.getRaw("index_equal").toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,7 +172,11 @@ public class ApproximateHistogramAggregationTest extends InitializedNullHandling
|
|||
+ "\"postAggregations\": ["
|
||||
+ " { \"type\": \"min\", \"name\": \"index_min\", \"fieldName\": \"index_ah\"},"
|
||||
+ " { \"type\": \"max\", \"name\": \"index_max\", \"fieldName\": \"index_ah\"},"
|
||||
+ " { \"type\": \"quantile\", \"name\": \"index_quantile\", \"fieldName\": \"index_ah\", \"probability\" : 0.99 }"
|
||||
+ " { \"type\": \"quantile\", \"name\": \"index_quantile\", \"fieldName\": \"index_ah\", \"probability\" : 0.99 },"
|
||||
+ " { \"type\": \"quantiles\", \"name\": \"index_quantiles\", \"fieldName\": \"index_ah\", \"probabilities\" : [0.2, 0.7] },"
|
||||
+ " { \"type\": \"buckets\", \"name\": \"index_buckets\", \"fieldName\": \"index_ah\", \"bucketSize\" : 2.0, \"offset\": 4.0 },"
|
||||
+ " { \"type\": \"customBuckets\", \"name\": \"index_custom\", \"fieldName\": \"index_ah\", \"breaks\" : [50.0, 100.0] },"
|
||||
+ " { \"type\": \"equalBuckets\", \"name\": \"index_equal\", \"fieldName\": \"index_ah\", \"numBuckets\" : 3 }"
|
||||
+ "],"
|
||||
+ "\"intervals\": [ \"1970/2050\" ]"
|
||||
+ "}";
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ArrayUtilsTest
|
||||
{
|
||||
@Test
|
||||
public void testHashCodeLong()
|
||||
{
|
||||
int hash1 = ArrayUtils.hashCode(new long[]{1L, 2L, 3L}, 0, 2);
|
||||
int hash2 = ArrayUtils.hashCode(new long[]{1L, 2L, 3L}, 0, 2);
|
||||
int hash3 = ArrayUtils.hashCode(new long[]{1L, 2L, 3L}, 0, 1);
|
||||
int hash4 = ArrayUtils.hashCode(new long[]{1L, 2L, 3L}, 0, 1);
|
||||
|
||||
Assert.assertEquals(hash1, hash2);
|
||||
Assert.assertNotEquals(hash1, hash3);
|
||||
Assert.assertEquals(hash3, hash4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCodeFloat()
|
||||
{
|
||||
int hash1 = ArrayUtils.hashCode(new float[]{1.0f, 2.0f, 3.0f}, 0, 2);
|
||||
int hash2 = ArrayUtils.hashCode(new float[]{1.0f, 2.0f, 3.0f}, 0, 2);
|
||||
int hash3 = ArrayUtils.hashCode(new float[]{1.0f, 2.0f, 3.0f}, 0, 1);
|
||||
int hash4 = ArrayUtils.hashCode(new float[]{1.0f, 2.0f, 3.0f}, 0, 1);
|
||||
|
||||
Assert.assertEquals(hash1, hash2);
|
||||
Assert.assertNotEquals(hash1, hash3);
|
||||
Assert.assertEquals(hash3, hash4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashCodeDouble()
|
||||
{
|
||||
int hash1 = ArrayUtils.hashCode(new double[]{1.0, 2.0, 3.0}, 0, 2);
|
||||
int hash2 = ArrayUtils.hashCode(new double[]{1.0, 2.0, 3.0}, 0, 2);
|
||||
int hash3 = ArrayUtils.hashCode(new double[]{1.0, 2.0, 3.0}, 0, 1);
|
||||
int hash4 = ArrayUtils.hashCode(new double[]{1.0, 2.0, 3.0}, 0, 1);
|
||||
|
||||
Assert.assertEquals(hash1, hash2);
|
||||
Assert.assertNotEquals(hash1, hash3);
|
||||
Assert.assertEquals(hash3, hash4);
|
||||
}
|
||||
}
|
|
@ -19,7 +19,9 @@
|
|||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.apache.druid.query.aggregation.PostAggregator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -28,18 +30,40 @@ public class BucketsPostAggregatorTest
|
|||
@Test
|
||||
public void testSerde() throws Exception
|
||||
{
|
||||
BucketsPostAggregator aggregator1 =
|
||||
BucketsPostAggregator there =
|
||||
new BucketsPostAggregator("buckets_post_aggregator", "test_field", 2f, 4f);
|
||||
|
||||
DefaultObjectMapper mapper = new DefaultObjectMapper();
|
||||
BucketsPostAggregator aggregator2 = mapper.readValue(
|
||||
mapper.writeValueAsString(aggregator1),
|
||||
BucketsPostAggregator andBackAgain = mapper.readValue(
|
||||
mapper.writeValueAsString(there),
|
||||
BucketsPostAggregator.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(aggregator1.getBucketSize(), aggregator2.getBucketSize(), 0.0001);
|
||||
Assert.assertEquals(aggregator1.getOffset(), aggregator2.getOffset(), 0.0001);
|
||||
Assert.assertArrayEquals(aggregator1.getCacheKey(), aggregator2.getCacheKey());
|
||||
Assert.assertEquals(aggregator1.getDependentFields(), aggregator2.getDependentFields());
|
||||
Assert.assertEquals(there, andBackAgain);
|
||||
Assert.assertEquals(there.getBucketSize(), andBackAgain.getBucketSize(), 0.0001);
|
||||
Assert.assertEquals(there.getOffset(), andBackAgain.getOffset(), 0.0001);
|
||||
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
|
||||
Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
PostAggregator postAgg =
|
||||
new BucketsPostAggregator("buckets_post_aggregator", "test_field", 2f, 4f);
|
||||
|
||||
Assert.assertEquals(
|
||||
"BucketsPostAggregator{name='buckets_post_aggregator', fieldName='test_field', bucketSize=2.0, offset=4.0}",
|
||||
postAgg.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(BucketsPostAggregator.class)
|
||||
.withNonnullFields("name", "fieldName")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.apache.druid.query.aggregation.PostAggregator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CustomBucketsPostAggregatorTest
|
||||
{
|
||||
@Test
|
||||
public void testSerde() throws Exception
|
||||
{
|
||||
CustomBucketsPostAggregator there =
|
||||
new CustomBucketsPostAggregator("buckets_post_aggregator", "test_field", new float[]{2f, 4f});
|
||||
|
||||
DefaultObjectMapper mapper = new DefaultObjectMapper();
|
||||
CustomBucketsPostAggregator andBackAgain = mapper.readValue(
|
||||
mapper.writeValueAsString(there),
|
||||
CustomBucketsPostAggregator.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(there, andBackAgain);
|
||||
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
|
||||
Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
PostAggregator postAgg =
|
||||
new CustomBucketsPostAggregator("buckets_post_aggregator", "test_field", new float[]{2f, 4f});
|
||||
|
||||
Assert.assertEquals(
|
||||
"CustomBucketsPostAggregator{name='buckets_post_aggregator', fieldName='test_field', breaks=[2.0, 4.0]}",
|
||||
postAgg.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(CustomBucketsPostAggregator.class)
|
||||
.withNonnullFields("name", "fieldName")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.apache.druid.query.aggregation.PostAggregator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EqualBucketsPostAggregatorTest
|
||||
{
|
||||
@Test
|
||||
public void testSerde() throws Exception
|
||||
{
|
||||
EqualBucketsPostAggregator there =
|
||||
new EqualBucketsPostAggregator("buckets_post_aggregator", "test_field", 3);
|
||||
|
||||
DefaultObjectMapper mapper = new DefaultObjectMapper();
|
||||
EqualBucketsPostAggregator andBackAgain = mapper.readValue(
|
||||
mapper.writeValueAsString(there),
|
||||
EqualBucketsPostAggregator.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(there, andBackAgain);
|
||||
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
|
||||
Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
PostAggregator postAgg =
|
||||
new EqualBucketsPostAggregator("buckets_post_aggregator", "test_field", 3);
|
||||
|
||||
Assert.assertEquals(
|
||||
"EqualBucketsPostAggregator{name='buckets_post_aggregator', fieldName='test_field', numBuckets=3}",
|
||||
postAgg.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(EqualBucketsPostAggregator.class)
|
||||
.withNonnullFields("name", "fieldName")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.apache.druid.query.aggregation.PostAggregator;
|
||||
import org.apache.druid.testing.InitializedNullHandlingTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -29,6 +32,23 @@ import java.util.Map;
|
|||
|
||||
public class MaxPostAggregatorTest extends InitializedNullHandlingTest
|
||||
{
|
||||
@Test
|
||||
public void testSerde() throws Exception
|
||||
{
|
||||
MaxPostAggregator there =
|
||||
new MaxPostAggregator("max", "test_field");
|
||||
|
||||
DefaultObjectMapper mapper = new DefaultObjectMapper();
|
||||
MaxPostAggregator andBackAgain = mapper.readValue(
|
||||
mapper.writeValueAsString(there),
|
||||
MaxPostAggregator.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(there, andBackAgain);
|
||||
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
|
||||
Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparator()
|
||||
{
|
||||
|
@ -52,4 +72,25 @@ public class MaxPostAggregatorTest extends InitializedNullHandlingTest
|
|||
Assert.assertEquals(0, comp.compare(after, after));
|
||||
Assert.assertEquals(1, comp.compare(after, before));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
PostAggregator postAgg =
|
||||
new MaxPostAggregator("max", "test_field");
|
||||
|
||||
Assert.assertEquals(
|
||||
"MaxPostAggregator{fieldName='test_field'}",
|
||||
postAgg.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(MaxPostAggregator.class)
|
||||
.withNonnullFields("name", "fieldName")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.apache.druid.query.aggregation.PostAggregator;
|
||||
import org.apache.druid.testing.InitializedNullHandlingTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -29,6 +32,23 @@ import java.util.Map;
|
|||
|
||||
public class MinPostAggregatorTest extends InitializedNullHandlingTest
|
||||
{
|
||||
@Test
|
||||
public void testSerde() throws Exception
|
||||
{
|
||||
MinPostAggregator there =
|
||||
new MinPostAggregator("min", "test_field");
|
||||
|
||||
DefaultObjectMapper mapper = new DefaultObjectMapper();
|
||||
MinPostAggregator andBackAgain = mapper.readValue(
|
||||
mapper.writeValueAsString(there),
|
||||
MinPostAggregator.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(there, andBackAgain);
|
||||
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
|
||||
Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparator()
|
||||
{
|
||||
|
@ -52,4 +72,25 @@ public class MinPostAggregatorTest extends InitializedNullHandlingTest
|
|||
Assert.assertEquals(0, comp.compare(after, after));
|
||||
Assert.assertEquals(-1, comp.compare(after, before));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
PostAggregator postAgg =
|
||||
new MinPostAggregator("min", "test_field");
|
||||
|
||||
Assert.assertEquals(
|
||||
"MinPostAggregator{fieldName='test_field'}",
|
||||
postAgg.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(MinPostAggregator.class)
|
||||
.withNonnullFields("name", "fieldName")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.apache.druid.testing.InitializedNullHandlingTest;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
@ -29,6 +31,23 @@ import java.util.Map;
|
|||
|
||||
public class QuantilePostAggregatorTest extends InitializedNullHandlingTest
|
||||
{
|
||||
@Test
|
||||
public void testSerde() throws Exception
|
||||
{
|
||||
QuantilePostAggregator there =
|
||||
new QuantilePostAggregator("max", "test_field", 0.5f);
|
||||
|
||||
DefaultObjectMapper mapper = new DefaultObjectMapper();
|
||||
QuantilePostAggregator andBackAgain = mapper.readValue(
|
||||
mapper.writeValueAsString(there),
|
||||
QuantilePostAggregator.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(there, andBackAgain);
|
||||
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
|
||||
Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparator()
|
||||
{
|
||||
|
@ -54,4 +73,25 @@ public class QuantilePostAggregatorTest extends InitializedNullHandlingTest
|
|||
Assert.assertEquals(0, comp.compare(after, after));
|
||||
Assert.assertEquals(1, comp.compare(after, before));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
QuantilePostAggregator postAgg =
|
||||
new QuantilePostAggregator("quantile", "testField", 0.9f);
|
||||
|
||||
Assert.assertEquals(
|
||||
"QuantilePostAggregator{name='quantile', fieldName='testField', probability=0.9}",
|
||||
postAgg.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(QuantilePostAggregator.class)
|
||||
.withNonnullFields("name", "fieldName")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
public class QuantilesPostAggregatorTest
|
||||
{
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Test
|
||||
public void testSerde() throws Exception
|
||||
{
|
||||
QuantilesPostAggregator there =
|
||||
new QuantilesPostAggregator("max", "test_field", new float[]{0.2f, 0.7f});
|
||||
|
||||
DefaultObjectMapper mapper = new DefaultObjectMapper();
|
||||
QuantilesPostAggregator andBackAgain = mapper.readValue(
|
||||
mapper.writeValueAsString(there),
|
||||
QuantilesPostAggregator.class
|
||||
);
|
||||
|
||||
Assert.assertEquals(there, andBackAgain);
|
||||
Assert.assertArrayEquals(there.getCacheKey(), andBackAgain.getCacheKey());
|
||||
Assert.assertEquals(there.getDependentFields(), andBackAgain.getDependentFields());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testComparator()
|
||||
{
|
||||
expectedException.expect(UnsupportedOperationException.class);
|
||||
QuantilesPostAggregator quantiles = new QuantilesPostAggregator("quantiles", "someAgg", new float[]{0.3f, 0.9f});
|
||||
quantiles.getComparator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString()
|
||||
{
|
||||
QuantilesPostAggregator postAgg =
|
||||
new QuantilesPostAggregator("post", "test_field", new float[]{0.2f, 0.7f});
|
||||
|
||||
Assert.assertEquals(
|
||||
"QuantilesPostAggregator{name='post', fieldName='test_field', probabilities=[0.2, 0.7]}",
|
||||
postAgg.toString()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(QuantilesPostAggregator.class)
|
||||
.withNonnullFields("name", "fieldName")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
|
@ -20,6 +20,7 @@
|
|||
package org.apache.druid.query.aggregation.histogram;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import nl.jqno.equalsverifier.EqualsVerifier;
|
||||
import org.apache.druid.jackson.DefaultObjectMapper;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Assert;
|
||||
|
@ -78,4 +79,13 @@ public class QuantilesTest
|
|||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEquals()
|
||||
{
|
||||
EqualsVerifier.forClass(Quantiles.class)
|
||||
.withNonnullFields("probabilities", "quantiles", "min", "max")
|
||||
.usingGetClass()
|
||||
.verify();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue