-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from zapr-oss/develop
Support for distinctCount extension
- Loading branch information
Showing
4 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -204,6 +204,7 @@ Aggregation Queries | |
* LongFirst | ||
* LongLast | ||
* ThetaSketch | ||
* DistinctCount | ||
|
||
#### Filters | ||
|
||
|
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
37 changes: 37 additions & 0 deletions
37
...va/in/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregator.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,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; | ||
} | ||
|
||
} |
86 changes: 86 additions & 0 deletions
86
...n/zapr/druid/druidry/extensions/distinctcount/aggregator/DistinctCountAggregatorTest.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,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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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); | ||
} | ||
|
||
} |