From 09458e45b372d306e5514a315065753eab94e063 Mon Sep 17 00:00:00 2001 From: Gagan Gupta Date: Mon, 5 Nov 2018 14:58:00 +0530 Subject: [PATCH 1/4] Version bumped to 2.10-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0ebc1f57..cf004feb 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ in.zapr.druid druidry - 2.9 + 2.10-SNAPSHOT Druidry - Druid Java Client Druidry is an open-source Java based utility library which supports creating From 091866c5ff5ef005bb0919b1de13a5e0058bf9c8 Mon Sep 17 00:00:00 2001 From: Abhi Sapariya Date: Sat, 1 Dec 2018 16:58:01 +0530 Subject: [PATCH 2/4] implemented distinct count aggregator extension --- .../aggregator/DistinctCountAggregator.java | 37 ++++++++ .../DistinctCountAggregatorTest.java | 86 +++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/main/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregator.java create mode 100644 src/test/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregatorTest.java diff --git a/src/main/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregator.java b/src/main/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregator.java new file mode 100644 index 00000000..25685902 --- /dev/null +++ b/src/main/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregator.java @@ -0,0 +1,37 @@ +/* + * Copyright 2018-present Red Brick Lane Marketing Solutions Pvt. Ltd. + * + * Licensed 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 in.zapr.druid.druidry.extensions.distinctcount.aggregator; + +import in.zapr.druid.druidry.aggregator.DruidAggregator; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.NonNull; + +@Getter +@EqualsAndHashCode(callSuper = true) +public class DistinctCountAggregator extends DruidAggregator { + + private static final String DISTINCT_COUNT_AGGREGATOR_TYPE = "distinctCount"; + private String fieldName; + + public DistinctCountAggregator(@NonNull String name, @NonNull String fieldName) { + this.type = DISTINCT_COUNT_AGGREGATOR_TYPE; + this.name = name; + this.fieldName = fieldName; + } + +} diff --git a/src/test/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregatorTest.java b/src/test/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregatorTest.java new file mode 100644 index 00000000..09993b17 --- /dev/null +++ b/src/test/java/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregatorTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2017-present, Red Brick Lane Marketing Solutions Pvt. Ltd. + * All rights reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package in.zapr.druid.druidry.extensions.distinctcount.aggregator; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +import org.json.JSONException; +import org.json.JSONObject; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class DistinctCountAggregatorTest { + + private static ObjectMapper objectMapper; + + @BeforeClass + public void init() { + objectMapper = new ObjectMapper(); + } + + @Test + public void testAllFields() throws JsonProcessingException, JSONException { + + DistinctCountAggregator distinctCountAggregator = + new DistinctCountAggregator("uniqueStars", "allStars"); + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("type", "distinctCount"); + jsonObject.put("name", "uniqueStars"); + jsonObject.put("fieldName", "allStars"); + + String actualJSON = objectMapper.writeValueAsString(distinctCountAggregator); + String expectedJSON = jsonObject.toString(); + JSONAssert.assertEquals(expectedJSON, actualJSON, JSONCompareMode.NON_EXTENSIBLE); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testNullFields() { + + DistinctCountAggregator distinctCountAggregator = + new DistinctCountAggregator(null, null); + } + + @Test + public void testEqualsPositive() { + + DistinctCountAggregator aggregator1 = + new DistinctCountAggregator("uniqueStars", "allStars"); + DistinctCountAggregator aggregator2 = + new DistinctCountAggregator("uniqueStars", "allStars"); + + Assert.assertEquals(aggregator1, aggregator2); + } + + @Test + public void testEqualsNegative() { + + DistinctCountAggregator aggregator1 = + new DistinctCountAggregator("uniqueStars1", "allStars1"); + DistinctCountAggregator aggregator2 = + new DistinctCountAggregator("uniqueStars2", "allStars2"); + + Assert.assertNotEquals(aggregator1, aggregator2); + } + +} From 9de2733fd9f34294f10d16cef56a1be65969ed85 Mon Sep 17 00:00:00 2001 From: Abhi Sapariya Date: Mon, 3 Dec 2018 23:13:28 +0530 Subject: [PATCH 3/4] readme update --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7fd88686..41528777 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,7 @@ Aggregation Queries * LongFirst * LongLast * ThetaSketch +* DistinctCount #### Filters From 6319df9ee55cb9e70310713475dfe8e342de7826 Mon Sep 17 00:00:00 2001 From: Abhi Sapariya <43852557+abhi-zapr@users.noreply.github.com> Date: Mon, 3 Dec 2018 23:19:41 +0530 Subject: [PATCH 4/4] Version bumped to v2.10 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cf004feb..b766bd9c 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ in.zapr.druid druidry - 2.10-SNAPSHOT + 2.10 Druidry - Druid Java Client Druidry is an open-source Java based utility library which supports creating