From ed77fcbd3ba11d5ad1e2981dfe096adaaeb8a5e0 Mon Sep 17 00:00:00 2001 From: Furkan KAMACI Date: Thu, 7 Feb 2019 22:51:07 +0300 Subject: [PATCH] Improper getter value is fixed. (#6930) * Improper getter value is fixed. * Test class is added. --- .../histogram/BucketsPostAggregator.java | 2 +- .../histogram/BucketsPostAggregatorTest.java | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregatorTest.java 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 94400f781bbb..c47044cd3307 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 @@ -82,7 +82,7 @@ public float getBucketSize() @JsonProperty public float getOffset() { - return bucketSize; + return offset; } @Override 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 new file mode 100644 index 000000000000..ebcd2823dc81 --- /dev/null +++ b/extensions-core/histogram/src/test/java/org/apache/druid/query/aggregation/histogram/BucketsPostAggregatorTest.java @@ -0,0 +1,45 @@ +/* + * 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.apache.druid.jackson.DefaultObjectMapper; +import org.junit.Assert; +import org.junit.Test; + +public class BucketsPostAggregatorTest +{ + @Test + public void testSerde() throws Exception + { + BucketsPostAggregator aggregator1 = + new BucketsPostAggregator("buckets_post_aggregator", "test_field", 2f, 4f); + + DefaultObjectMapper mapper = new DefaultObjectMapper(); + BucketsPostAggregator aggregator2 = mapper.readValue( + mapper.writeValueAsString(aggregator1), + 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()); + } +}