You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ji...@apache.org on 2019/05/03 17:52:31 UTC
[incubator-pinot] branch master updated: [TE] Use strict strategy
in model mapper for spec class (#4185)
This is an automated email from the ASF dual-hosted git repository.
jihao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 04042c7 [TE] Use strict strategy in model mapper for spec class (#4185)
04042c7 is described below
commit 04042c73697aed1969cb9284dca8c7267de9aa60
Author: Jihao Zhang <ji...@linkedin.com>
AuthorDate: Fri May 3 10:52:25 2019 -0700
[TE] Use strict strategy in model mapper for spec class (#4185)
---
.../thirdeye/detection/spec/AbstractSpec.java | 3 +++
.../thirdeye/detection/spec/AbstractSpecTest.java | 9 ++++++++
.../pinot/thirdeye/detection/spec/TestSpec.java | 27 ++++++++++++++++++++++
3 files changed, 39 insertions(+)
diff --git a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpec.java b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpec.java
index 47c8ba8..eb1fa69 100644
--- a/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpec.java
+++ b/thirdeye/thirdeye-pinot/src/main/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpec.java
@@ -21,6 +21,7 @@ package org.apache.pinot.thirdeye.detection.spec;
import java.util.Map;
import org.modelmapper.ModelMapper;
+import org.modelmapper.convention.MatchingStrategies;
/**
@@ -31,6 +32,8 @@ public abstract class AbstractSpec {
public static <T extends AbstractSpec> T fromProperties(Map<String, Object> properties, Class<T> specClass) {
// don't reuse model mapper instance. It caches typeMaps and will result in unexpected mappings
ModelMapper modelMapper = new ModelMapper();
+ // use strict mapping to ensure no mismatches or ambiguity occurs
+ modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
return modelMapper.map(properties, specClass);
}
}
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpecTest.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpecTest.java
index ba0fc7f..58779f8 100644
--- a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpecTest.java
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/AbstractSpecTest.java
@@ -65,5 +65,14 @@ public class AbstractSpecTest {
Assert.assertEquals(spec.getC(), "default");
Assert.assertEquals(spec.getConfiguration(), ImmutableMap.of("k1", "v1", "k2", "v2"));
}
+
+ @Test
+ public void testAbstractSpecMappingAmbiguityFalse() {
+ TestSpec spec = AbstractSpec.fromProperties(ImmutableMap.of("upThreshold", 0.2, "downThreshold", 0.3), TestSpec.class);
+ Assert.assertEquals(spec.getUpThreshold(), 0.2);
+ Assert.assertEquals(spec.getThreshold(), 0.1);
+ Assert.assertEquals(spec.getDownThreshold(), 0.3);
+ }
+
}
diff --git a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/TestSpec.java b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/TestSpec.java
index 0f2dc8d..bf76b35 100644
--- a/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/TestSpec.java
+++ b/thirdeye/thirdeye-pinot/src/test/java/org/apache/pinot/thirdeye/detection/spec/TestSpec.java
@@ -26,6 +26,9 @@ public class TestSpec extends AbstractSpec{
private String c = "default";
private RuleBaselineProvider baselineProvider;
private Map<String, String> configuration;
+ private double threshold = 0.1;
+ private double upThreshold;
+ private double downThreshold;
public Map<String, String> getConfiguration() {
return configuration;
@@ -66,5 +69,29 @@ public class TestSpec extends AbstractSpec{
public void setC(String c) {
this.c = c;
}
+
+ public double getThreshold() {
+ return threshold;
+ }
+
+ public void setThreshold(double threshold) {
+ this.threshold = threshold;
+ }
+
+ public double getUpThreshold() {
+ return upThreshold;
+ }
+
+ public void setUpThreshold(double upThreshold) {
+ this.upThreshold = upThreshold;
+ }
+
+ public double getDownThreshold() {
+ return downThreshold;
+ }
+
+ public void setDownThreshold(double downThreshold) {
+ this.downThreshold = downThreshold;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org