carbondata-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ravipes...@apache.org
Subject [1/2] incubator-carbondata git commit: [CARBONDATA-270] [Description] Double data type value comparison optimization, EqualsToExpression evaluation for double values first check for the equality of nan values and then the double value comparison happens,
Date Tue, 13 Dec 2016 06:48:20 GMT
Repository: incubator-carbondata
Updated Branches:
  refs/heads/master b7c7060ab -> 05f56afdc


[CARBONDATA-270]
[Description] Double data type value comparison optimization,EqualsToExpression evaluation
for double values first check for the equality of nan values and then the double value comparison
happens, since nan comparison scenarios are rare we can push the comparison of nan after the
double value comparison. while comparing dictionary value which is type double should also
will preserve the -0.0 and 0.0 equality


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

Branch: refs/heads/master
Commit: b9db4ac8d5aa814b8ea4d02d7a426f688501df33
Parents: b7c7060
Author: sujith71955 <sujithchacko.2010@gmail.com>
Authored: Fri Sep 23 12:37:12 2016 +0530
Committer: ravipesala <ravi.pesala@gmail.com>
Committed: Tue Dec 13 12:17:27 2016 +0530

----------------------------------------------------------------------
 .../cache/dictionary/ColumnDictionaryInfo.java     |  7 ++++---
 .../apache/carbondata/core/util/DataTypeUtil.java  | 17 +++++++++++++++++
 .../apache/carbondata/scan/filter/FilterUtil.java  |  5 +----
 3 files changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/b9db4ac8/core/src/main/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryInfo.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryInfo.java
b/core/src/main/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryInfo.java
index b2d81da..c19f244 100644
--- a/core/src/main/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryInfo.java
+++ b/core/src/main/java/org/apache/carbondata/core/cache/dictionary/ColumnDictionaryInfo.java
@@ -31,7 +31,7 @@ import org.apache.carbondata.core.constants.CarbonCommonConstants;
 import org.apache.carbondata.core.util.ByteUtil;
 import org.apache.carbondata.core.util.CarbonProperties;
 import org.apache.carbondata.core.util.CarbonUtil;
-
+import org.apache.carbondata.core.util.DataTypeUtil;
 /**
  * class that implements methods specific for dictionary data look up
  */
@@ -277,8 +277,9 @@ public class ColumnDictionaryInfo extends AbstractColumnDictionaryInfo
{
         case INT:
           return Integer.compare((Integer.parseInt(dictionaryVal)), (Integer.parseInt(memberVal)));
         case DOUBLE:
-          return Double
-              .compare((Double.parseDouble(dictionaryVal)), (Double.parseDouble(memberVal)));
+          return DataTypeUtil
+              .compareDoubleWithNan((Double.parseDouble(dictionaryVal)),
+                  (Double.parseDouble(memberVal)));
         case LONG:
           return Long.compare((Long.parseLong(dictionaryVal)), (Long.parseLong(memberVal)));
         case BOOLEAN:

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/b9db4ac8/core/src/main/java/org/apache/carbondata/core/util/DataTypeUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/core/util/DataTypeUtil.java b/core/src/main/java/org/apache/carbondata/core/util/DataTypeUtil.java
index d179fca..5808d61 100644
--- a/core/src/main/java/org/apache/carbondata/core/util/DataTypeUtil.java
+++ b/core/src/main/java/org/apache/carbondata/core/util/DataTypeUtil.java
@@ -400,4 +400,21 @@ public final class DataTypeUtil {
     }
     return null;
   }
+  /**
+   * This method will compare double values it will preserve
+   * the -0.0 and 0.0 equality as per == ,also preserve NaN equality check as per
+   * java.lang.Double.equals()
+   *
+   * @param d1 double value for equality check
+   * @param d2 double value for equality check
+   * @return boolean after comparing two double values.
+   */
+  public static int compareDoubleWithNan(Double d1, Double d2) {
+    if ((d1.doubleValue() == d2.doubleValue()) || (Double.isNaN(d1) && Double.isNaN(d2)))
{
+      return 0;
+    } else if (d1 < d2) {
+      return -1;
+    }
+    return 1;
+  }
 }

http://git-wip-us.apache.org/repos/asf/incubator-carbondata/blob/b9db4ac8/core/src/main/java/org/apache/carbondata/scan/filter/FilterUtil.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/carbondata/scan/filter/FilterUtil.java b/core/src/main/java/org/apache/carbondata/scan/filter/FilterUtil.java
index 1d4650e..3f71ced 100644
--- a/core/src/main/java/org/apache/carbondata/scan/filter/FilterUtil.java
+++ b/core/src/main/java/org/apache/carbondata/scan/filter/FilterUtil.java
@@ -1403,10 +1403,7 @@ public final class FilterUtil {
    * @return boolean after comparing two double values.
    */
   public static boolean nanSafeEqualsDoubles(Double d1, Double d2) {
-    Boolean xIsNan = Double.isNaN(d1);
-    Boolean yIsNan = Double.isNaN(d2);
-    if ((xIsNan && yIsNan) || (d1.doubleValue() == d2.doubleValue())) {
-
+    if ((d1.doubleValue() == d2.doubleValue()) || (Double.isNaN(d1) && Double.isNaN(d2)))
{
       return true;
     }
     return false;


Mime
View raw message