-
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 #51 from zapr-oss/develop
Release of 2.5
- Loading branch information
Showing
9 changed files
with
447 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
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
39 changes: 39 additions & 0 deletions
39
.../java/in/zapr/druid/druidry/extensions/datasketches/aggregator/ThetaSketchAggregator.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,39 @@ | ||
package in.zapr.druid.druidry.extensions.datasketches.aggregator; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.common.math.LongMath; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
|
||
import in.zapr.druid.druidry.aggregator.DruidAggregator; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
@Getter | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class ThetaSketchAggregator extends DruidAggregator { | ||
|
||
private static final String THETA_SKETCH_TYPE_AGGREGATOR = "thetaSketch"; | ||
private String fieldName; | ||
private Boolean isInputThetaSketch; | ||
private Long size; | ||
|
||
@Builder | ||
public ThetaSketchAggregator( | ||
@NonNull String name, | ||
@NonNull String fieldName, | ||
Boolean isInputThetaSketch, | ||
Long size) { | ||
this.type = THETA_SKETCH_TYPE_AGGREGATOR; | ||
this.name = name; | ||
this.fieldName = fieldName; | ||
this.isInputThetaSketch = isInputThetaSketch; | ||
this.size = size; | ||
|
||
if (size != null) { | ||
Preconditions.checkArgument(LongMath.isPowerOfTwo(size), "size must be a power of 2"); | ||
} | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...uid/druidry/extensions/datasketches/postAggregator/ThetaSketchEstimatePostAggregator.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,21 @@ | ||
package in.zapr.druid.druidry.extensions.datasketches.postAggregator; | ||
|
||
import in.zapr.druid.druidry.postAggregator.DruidPostAggregator; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
@Getter | ||
public class ThetaSketchEstimatePostAggregator extends DruidPostAggregator { | ||
|
||
private static final String THETA_SKETCH_ESTIMATE_POST_AGGREGATOR_TYPE = "thetaSketchEstimate"; | ||
|
||
private DruidPostAggregator field; | ||
|
||
public ThetaSketchEstimatePostAggregator(@NonNull String name, | ||
@NonNull DruidPostAggregator field) { | ||
this.type = THETA_SKETCH_ESTIMATE_POST_AGGREGATOR_TYPE; | ||
this.name = name; | ||
this.field = field; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...ava/in/zapr/druid/druidry/extensions/datasketches/postAggregator/ThetaSketchFunction.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,22 @@ | ||
package in.zapr.druid.druidry.extensions.datasketches.postAggregator; | ||
|
||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
public enum ThetaSketchFunction { | ||
|
||
INTERSECT("INTERSECT"), | ||
UNION("UNION"), | ||
NOT("NOT"); | ||
|
||
private String value; | ||
|
||
ThetaSketchFunction(String value) { | ||
this.value = value; | ||
} | ||
|
||
@JsonValue | ||
public String getValue() { | ||
return value; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
.../druid/druidry/extensions/datasketches/postAggregator/ThetaSketchSetOpPostAggregator.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,36 @@ | ||
package in.zapr.druid.druidry.extensions.datasketches.postAggregator; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
import java.util.List; | ||
|
||
import in.zapr.druid.druidry.postAggregator.DruidPostAggregator; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
@Getter | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class ThetaSketchSetOpPostAggregator extends DruidPostAggregator { | ||
|
||
private static final String THETA_SKETCH_SET_OP_POST_AGGREGATOR_TYPE = "thetaSketchSetOp"; | ||
|
||
@JsonProperty("func") | ||
private ThetaSketchFunction function; | ||
private List<DruidPostAggregator> fields; | ||
private Long size; | ||
|
||
@Builder | ||
private ThetaSketchSetOpPostAggregator(@NonNull String name, | ||
@NonNull ThetaSketchFunction function, | ||
@NonNull List<DruidPostAggregator> fields, | ||
Long size) { | ||
this.type = THETA_SKETCH_SET_OP_POST_AGGREGATOR_TYPE; | ||
this.name = name; | ||
this.function = function; | ||
this.fields = fields; | ||
this.size = size; | ||
} | ||
|
||
} |
91 changes: 91 additions & 0 deletions
91
...a/in/zapr/druid/druidry/extensions/datasketches/aggregator/ThetaSketchAggregatorTest.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,91 @@ | ||
package in.zapr.druid.druidry.extensions.datasketches.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.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
public class ThetaSketchAggregatorTest { | ||
|
||
private static ObjectMapper objectMapper; | ||
|
||
@BeforeClass | ||
public void init() { | ||
objectMapper = new ObjectMapper(); | ||
} | ||
|
||
private JSONObject getThetaSketchAggregatorJSON() throws JSONException { | ||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("type", "thetaSketch"); | ||
jsonObject.put("name", "estimated_stars"); | ||
jsonObject.put("fieldName", "stars"); | ||
|
||
return jsonObject; | ||
} | ||
|
||
@Test | ||
public void testAllFields() throws JsonProcessingException, JSONException { | ||
|
||
ThetaSketchAggregator thetaSketchAggregator = ThetaSketchAggregator.builder() | ||
.name("estimated_stars") | ||
.fieldName("stars") | ||
.isInputThetaSketch(true) | ||
.size(1024L) | ||
.build(); | ||
|
||
JSONObject jsonObject = getThetaSketchAggregatorJSON(); | ||
jsonObject.put("isInputThetaSketch", true); | ||
jsonObject.put("size", 1024L); | ||
|
||
String actualJSON = objectMapper.writeValueAsString(thetaSketchAggregator); | ||
String expectedJSON = jsonObject.toString(); | ||
JSONAssert.assertEquals(expectedJSON, actualJSON, JSONCompareMode.NON_EXTENSIBLE); | ||
} | ||
|
||
@Test | ||
public void testRequiredFields() throws JsonProcessingException, JSONException { | ||
|
||
ThetaSketchAggregator thetaSketchAggregator = ThetaSketchAggregator.builder() | ||
.name("estimated_stars") | ||
.fieldName("stars") | ||
.build(); | ||
|
||
JSONObject jsonObject = getThetaSketchAggregatorJSON(); | ||
|
||
String actualJSON = objectMapper.writeValueAsString(thetaSketchAggregator); | ||
String expectedJSON = jsonObject.toString(); | ||
JSONAssert.assertEquals(expectedJSON, actualJSON, JSONCompareMode.NON_EXTENSIBLE); | ||
} | ||
|
||
@Test(expectedExceptions = IllegalArgumentException.class) | ||
public void preconditionCheck() { | ||
|
||
ThetaSketchAggregator thetaSketchAggregator = ThetaSketchAggregator.builder() | ||
.name("estimated_stars") | ||
.fieldName("stars") | ||
.size(420L) | ||
.build(); | ||
} | ||
|
||
@Test(expectedExceptions = NullPointerException.class) | ||
public void testNullName() { | ||
|
||
ThetaSketchAggregator thetaSketchAggregator = ThetaSketchAggregator.builder() | ||
.fieldName("stars") | ||
.build(); | ||
} | ||
|
||
@Test(expectedExceptions = NullPointerException.class) | ||
public void testNullFieldName() { | ||
|
||
ThetaSketchAggregator thetaSketchAggregator = ThetaSketchAggregator.builder() | ||
.name("estimated_stars") | ||
.build(); | ||
} | ||
|
||
} |
108 changes: 108 additions & 0 deletions
108
...druidry/extensions/datasketches/postAggregator/ThetaSketchEstimatePostAggregatorTest.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,108 @@ | ||
package in.zapr.druid.druidry.extensions.datasketches.postAggregator; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import org.json.JSONArray; | ||
import org.json.JSONException; | ||
import org.json.JSONObject; | ||
import org.skyscreamer.jsonassert.JSONAssert; | ||
import org.skyscreamer.jsonassert.JSONCompareMode; | ||
import org.testng.annotations.BeforeClass; | ||
import org.testng.annotations.Test; | ||
|
||
import java.util.Collections; | ||
|
||
import in.zapr.druid.druidry.postAggregator.FieldAccessPostAggregator; | ||
|
||
public class ThetaSketchEstimatePostAggregatorTest { | ||
|
||
private static ObjectMapper objectMapper; | ||
|
||
@BeforeClass | ||
public void init() { | ||
objectMapper = new ObjectMapper(); | ||
} | ||
|
||
private JSONObject getFieldAccessJSON() throws JSONException { | ||
JSONObject fieldAccess = new JSONObject(); | ||
fieldAccess.put("type", "fieldAccess"); | ||
fieldAccess.put("fieldName", "stars"); | ||
|
||
return fieldAccess; | ||
} | ||
|
||
@Test | ||
public void testAllFieldsWithFieldAccess() throws JsonProcessingException, JSONException { | ||
|
||
FieldAccessPostAggregator fieldAccessPostAggregator = | ||
new FieldAccessPostAggregator("stars"); | ||
|
||
ThetaSketchEstimatePostAggregator thetaSketchEstimatePostAggregator = | ||
new ThetaSketchEstimatePostAggregator("estimate_stars", fieldAccessPostAggregator); | ||
|
||
|
||
JSONObject fieldAccess = getFieldAccessJSON(); | ||
|
||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("type", "thetaSketchEstimate"); | ||
jsonObject.put("name", "estimate_stars"); | ||
jsonObject.put("field", fieldAccess); | ||
|
||
String actualJSON = objectMapper.writeValueAsString(thetaSketchEstimatePostAggregator); | ||
String expectedJSON = jsonObject.toString(); | ||
JSONAssert.assertEquals(expectedJSON, actualJSON, JSONCompareMode.NON_EXTENSIBLE); | ||
|
||
} | ||
|
||
@Test | ||
public void testAllFieldsWithThetaSketchSetOp() throws JsonProcessingException, JSONException { | ||
|
||
FieldAccessPostAggregator fieldAccessPostAggregator = | ||
new FieldAccessPostAggregator("stars"); | ||
|
||
ThetaSketchSetOpPostAggregator thetaSketchSetOpPostAggregator = ThetaSketchSetOpPostAggregator.builder() | ||
.name("name") | ||
.function(ThetaSketchFunction.INTERSECT) | ||
.fields(Collections.singletonList(fieldAccessPostAggregator)) | ||
.build(); | ||
|
||
ThetaSketchEstimatePostAggregator thetaSketchEstimatePostAggregator = | ||
new ThetaSketchEstimatePostAggregator("estimate_stars", thetaSketchSetOpPostAggregator); | ||
|
||
|
||
JSONObject fieldAccess = getFieldAccessJSON(); | ||
|
||
JSONArray fields = new JSONArray(Collections.singletonList(getFieldAccessJSON())); | ||
|
||
JSONObject thetaSketchSetOp = new JSONObject(); | ||
thetaSketchSetOp.put("type", "thetaSketchSetOp"); | ||
thetaSketchSetOp.put("name", "name"); | ||
thetaSketchSetOp.put("func", "INTERSECT"); | ||
thetaSketchSetOp.put("fields", fields); | ||
|
||
JSONObject jsonObject = new JSONObject(); | ||
jsonObject.put("type", "thetaSketchEstimate"); | ||
jsonObject.put("name", "estimate_stars"); | ||
jsonObject.put("field", thetaSketchSetOp); | ||
|
||
String actualJSON = objectMapper.writeValueAsString(thetaSketchEstimatePostAggregator); | ||
String expectedJSON = jsonObject.toString(); | ||
JSONAssert.assertEquals(expectedJSON, actualJSON, JSONCompareMode.NON_EXTENSIBLE); | ||
} | ||
|
||
@Test(expectedExceptions = NullPointerException.class) | ||
public void testNullName() { | ||
|
||
ThetaSketchEstimatePostAggregator thetaSketchEstimatePostAggregator = | ||
new ThetaSketchEstimatePostAggregator(null, new FieldAccessPostAggregator("stars")); | ||
} | ||
|
||
@Test(expectedExceptions = NullPointerException.class) | ||
public void testNullField() { | ||
|
||
ThetaSketchEstimatePostAggregator thetaSketchEstimatePostAggregator = | ||
new ThetaSketchEstimatePostAggregator("estimate_stars", null); | ||
} | ||
|
||
} |
Oops, something went wrong.