You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by sw...@apache.org on 2014/05/29 03:46:32 UTC

[1/2] git commit: AMBARI-5922. Predicates don't work on fields with float values. Unnecessary newline removed. (swagle)

Repository: ambari
Updated Branches:
  refs/heads/trunk ebe04d4b8 -> c4a659772


AMBARI-5922. Predicates don't work on fields with float values. Unnecessary newline removed. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c4a65977
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c4a65977
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c4a65977

Branch: refs/heads/trunk
Commit: c4a6597721ad48bcebe9a8905e1251132cb79e5c
Parents: 9099842
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Wed May 28 18:19:11 2014 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Wed May 28 18:46:25 2014 -0700

----------------------------------------------------------------------
 .../ambari/server/controller/predicate/ComparisonPredicate.java     | 1 -
 1 file changed, 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c4a65977/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
index de429e8..c1cd16c 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
@@ -79,7 +79,6 @@ public abstract class ComparisonPredicate<T> extends PropertyPredicate implement
   protected int compareValueTo(Object propertyValue) throws ClassCastException{
     if (doubleValue != null) {
       if (propertyValue instanceof Number) {
-
         return doubleValue.compareTo(((Number) propertyValue).doubleValue());
       }
       else if (propertyValue instanceof String) {


[2/2] git commit: AMBARI-5922. Predicates don't work on fields with float values. (swagle)

Posted by sw...@apache.org.
AMBARI-5922. Predicates don't work on fields with float values. (swagle)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9099842a
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9099842a
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9099842a

Branch: refs/heads/trunk
Commit: 9099842a0e010402d07f542cf5b964d364d7ae85
Parents: ebe04d4
Author: Siddharth Wagle <sw...@hortonworks.com>
Authored: Wed May 28 17:59:00 2014 -0700
Committer: Siddharth Wagle <sw...@hortonworks.com>
Committed: Wed May 28 18:46:25 2014 -0700

----------------------------------------------------------------------
 .../controller/predicate/ComparisonPredicate.java   |  6 +++---
 .../controller/predicate/GreaterPredicateTest.java  | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/9099842a/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
index e8102d6..de429e8 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/predicate/ComparisonPredicate.java
@@ -77,10 +77,10 @@ public abstract class ComparisonPredicate<T> extends PropertyPredicate implement
   }
 
   protected int compareValueTo(Object propertyValue) throws ClassCastException{
-
     if (doubleValue != null) {
-      if (propertyValue instanceof Number ) {
-        return (int) (doubleValue - ((Number) propertyValue).doubleValue());
+      if (propertyValue instanceof Number) {
+
+        return doubleValue.compareTo(((Number) propertyValue).doubleValue());
       }
       else if (propertyValue instanceof String) {
         Double doubleFromString = stringToDouble((String) propertyValue);

http://git-wip-us.apache.org/repos/asf/ambari/blob/9099842a/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/GreaterPredicateTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/GreaterPredicateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/GreaterPredicateTest.java
index af79eff..47fcaae 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/GreaterPredicateTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/predicate/GreaterPredicateTest.java
@@ -67,4 +67,20 @@ public class GreaterPredicateTest {
     Assert.assertEquals(1, ids.size());
     Assert.assertTrue(ids.contains(propertyId));
   }
+
+  @Test
+  public void testApplyWithSmallFloats() {
+    Resource resource = new ResourceImpl(Resource.Type.HostComponent);
+    String propertyId = PropertyHelper.getPropertyId("category1", "foo");
+    Predicate predicate = new GreaterPredicate<Double>(propertyId, 0.1);
+
+    resource.setProperty(propertyId, 1.3);
+    Assert.assertTrue(predicate.evaluate(resource));
+
+    resource.setProperty(propertyId, 0.06);
+    Assert.assertFalse(predicate.evaluate(resource));
+
+    resource.setProperty(propertyId, 100.3);
+    Assert.assertTrue(predicate.evaluate(resource));
+  }
 }