This is an automated email from the ASF dual-hosted git repository.
cwylie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/druid.git
The following commit(s) were added to refs/heads/master by this push:
new 2c0746c increase druid-histogram postagg test coverage (#9732)
2c0746c is described below
commit 2c0746cfab89db05dff90bc47a6a8041d98a6182
Author: Clint Wylie <[email protected]>
AuthorDate: Thu May 7 00:10:29 2020 -0700
increase druid-histogram postagg test coverage (#9732)
---
extensions-core/histogram/pom.xml | 5 ++
.../ApproximateHistogramPostAggregator.java | 21 ++++++
.../histogram/BucketsPostAggregator.java | 24 +++++++
.../histogram/CustomBucketsPostAggregator.java | 26 ++++++-
.../histogram/EqualBucketsPostAggregator.java | 23 +++++++
.../aggregation/histogram/MaxPostAggregator.java | 2 +-
.../aggregation/histogram/MinPostAggregator.java | 2 +-
.../histogram/QuantilePostAggregator.java | 54 +++++++--------
.../query/aggregation/histogram/Quantiles.java | 28 +++-----
.../histogram/QuantilesPostAggregator.java | 24 +++++++
.../ApproximateHistogramAggregationTest.java | 38 ++++++++++-
.../aggregation/histogram/ArrayUtilsTest.java | 65 ++++++++++++++++++
.../histogram/BucketsPostAggregatorTest.java | 38 +++++++++--
.../histogram/CustomBucketsPostAggregatorTest.java | 67 ++++++++++++++++++
.../histogram/EqualBucketsPostAggregatorTest.java | 67 ++++++++++++++++++
.../histogram/MaxPostAggregatorTest.java | 41 +++++++++++
.../histogram/MinPostAggregatorTest.java | 41 +++++++++++
.../histogram/QuantilePostAggregatorTest.java | 40 +++++++++++
.../histogram/QuantilesPostAggregatorTest.java | 79 ++++++++++++++++++++++
.../query/aggregation/histogram/QuantilesTest.java | 10 +++
20 files changed, 634 insertions(+), 61 deletions(-)
diff --git a/extensions-core/histogram/pom.xml
b/extensions-core/histogram/pom.xml
index 207cb07..8a18501 100644
--- a/extensions-core/histogram/pom.xml
+++ b/extensions-core/histogram/pom.xml
@@ -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>
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramPostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramPostAggregator.java
index d046232..fbe82f1 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramPostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramPostAggregator.java
@@ -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);
+ }
}
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregator.java
index c47044c..818a014 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregator.java
@@ -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);
+ }
}
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/CustomBucketsPostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/CustomBucketsPostAggregator.java
index a9187beb..3cb8a17 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/CustomBucketsPostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/CustomBucketsPostAggregator.java
@@ -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;
+ }
}
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/EqualBucketsPostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/EqualBucketsPostAggregator.java
index 517a7cc..54ac745 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/EqualBucketsPostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/EqualBucketsPostAggregator.java
@@ -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);
+ }
}
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregator.java
index 4c507d5..e9e8e26 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregator.java
@@ -81,7 +81,7 @@ public class MaxPostAggregator extends
ApproximateHistogramPostAggregator
@Override
public String toString()
{
- return "QuantilePostAggregator{" +
+ return "MaxPostAggregator{" +
"fieldName='" + fieldName + '\'' +
'}';
}
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MinPostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MinPostAggregator.java
index 3c9dd9f..bd043cf 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MinPostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/MinPostAggregator.java
@@ -83,7 +83,7 @@ public class MinPostAggregator extends
ApproximateHistogramPostAggregator
@Override
public String toString()
{
- return "QuantilePostAggregator{" +
+ return "MinPostAggregator{" +
"fieldName='" + fieldName + '\'' +
'}';
}
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregator.java
index 13640eb..fb84ec8 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregator.java
@@ -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);
@@ -97,37 +96,12 @@ public class QuantilePostAggregator extends
ApproximateHistogramPostAggregator
}
@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);
+ }
}
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/Quantiles.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/Quantiles.java
index 0f89051..18c918a 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/Quantiles.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/Quantiles.java
@@ -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
diff --git
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilesPostAggregator.java
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilesPostAggregator.java
index 2ef4c50..6b68ddc 100644
---
a/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilesPostAggregator.java
+++
b/extensions-core/histogram/src/main/java/org/apache/druid/query/aggregation/histogram/QuantilesPostAggregator.java
@@ -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;
+ }
}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregationTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregationTest.java
index da752a2..c38b335 100644
---
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregationTest.java
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ApproximateHistogramAggregationTest.java
@@ -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\" ]"
+ "}";
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ArrayUtilsTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ArrayUtilsTest.java
new file mode 100644
index 0000000..faa1102
--- /dev/null
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/ArrayUtilsTest.java
@@ -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);
+ }
+}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregatorTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregatorTest.java
index ebcd282..10e49b4 100644
---
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregatorTest.java
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregatorTest.java
@@ -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();
}
}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/CustomBucketsPostAggregatorTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/CustomBucketsPostAggregatorTest.java
new file mode 100644
index 0000000..fa082c4
--- /dev/null
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/CustomBucketsPostAggregatorTest.java
@@ -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();
+ }
+}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/EqualBucketsPostAggregatorTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/EqualBucketsPostAggregatorTest.java
new file mode 100644
index 0000000..56dd732
--- /dev/null
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/EqualBucketsPostAggregatorTest.java
@@ -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();
+ }
+}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregatorTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregatorTest.java
index d9cdd43..711d2a6 100644
---
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregatorTest.java
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MaxPostAggregatorTest.java
@@ -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;
@@ -30,6 +33,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()
{
final String aggName = "doubleWithNulls";
@@ -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();
+ }
}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MinPostAggregatorTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MinPostAggregatorTest.java
index 770dce8..53f97af 100644
---
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MinPostAggregatorTest.java
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/MinPostAggregatorTest.java
@@ -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;
@@ -30,6 +33,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()
{
final String aggName = "doubleWithNulls";
@@ -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();
+ }
}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregatorTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregatorTest.java
index 98cc521..810068a 100644
---
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregatorTest.java
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilePostAggregatorTest.java
@@ -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;
@@ -30,6 +32,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()
{
final String aggName = "doubleWithNulls";
@@ -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();
+ }
}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesPostAggregatorTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesPostAggregatorTest.java
new file mode 100644
index 0000000..2178cb6
--- /dev/null
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesPostAggregatorTest.java
@@ -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();
+ }
+}
diff --git
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesTest.java
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesTest.java
index dd93f5f..c299d55 100644
---
a/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesTest.java
+++
b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/QuantilesTest.java
@@ -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();
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]