asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject asterixdb git commit: Print non-numeric floating point values as strings
Date Sat, 24 Sep 2016 18:14:36 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 35487c014 -> d79d96ebc


Print non-numeric floating point values as strings

Change-Id: I423fa30005a0987b1b98dc111a489a64e347df15
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1208
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>


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

Branch: refs/heads/master
Commit: d79d96ebcfcc5b019c16cfdd250b7bd7e4dcac04
Parents: 35487c0
Author: Till Westmann <tillw@apache.org>
Authored: Fri Sep 23 22:58:06 2016 -0700
Committer: Till Westmann <tillw@apache.org>
Committed: Sat Sep 24 11:14:02 2016 -0700

----------------------------------------------------------------------
 .../numeric/non-finite/non-finite.1.query.sqlpp         |  5 +++++
 .../results/numeric/non-finite/non-finite.1.json        |  2 ++
 .../src/test/resources/runtimets/testsuite_sqlpp.xml    |  5 +++++
 .../printers/json/clean/ADoublePrinterFactory.java      | 12 ++++++++++--
 .../printers/json/clean/AFloatPrinterFactory.java       | 12 ++++++++++--
 5 files changed, 32 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d79d96eb/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/non-finite/non-finite.1.query.sqlpp
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/non-finite/non-finite.1.query.sqlpp
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/non-finite/non-finite.1.query.sqlpp
new file mode 100644
index 0000000..e03d5a4
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/non-finite/non-finite.1.query.sqlpp
@@ -0,0 +1,5 @@
+{
+  "NaN": sqrt(-1),
+  "Infinity": exp(1000),
+  "-Infinity": -exp(1000)
+};

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d79d96eb/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json
b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json
new file mode 100644
index 0000000..db5a90c
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json
@@ -0,0 +1,2 @@
+[ { "NaN": "NaN", "Infinity": "Infinity", "-Infinity": "-Infinity" }
+ ]

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d79d96eb/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
index 9490e7a..0aeca6c 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -4387,6 +4387,11 @@
         <output-dir compare="Text">sign</output-dir>
       </compilation-unit>
     </test-case>
+    <test-case FilePath="numeric">
+      <compilation-unit name="non-finite">
+        <output-dir compare="Clean-JSON">non-finite</output-dir>
+      </compilation-unit>
+    </test-case>
   </test-group>
   <test-group name="open-closed">
     <!--

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d79d96eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADoublePrinterFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADoublePrinterFactory.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADoublePrinterFactory.java
index 03088fb..abf9ced 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADoublePrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADoublePrinterFactory.java
@@ -29,8 +29,16 @@ public class ADoublePrinterFactory implements IPrinterFactory {
     private static final long serialVersionUID = 1L;
     public static final ADoublePrinterFactory INSTANCE = new ADoublePrinterFactory();
 
-    public static final IPrinter PRINTER = (byte[] b, int s, int l, PrintStream ps) ->
ps
-            .print(ADoubleSerializerDeserializer.getDouble(b, s + 1));
+    public static final IPrinter PRINTER = (byte[] b, int s, int l, PrintStream ps) ->
{
+        final double d = ADoubleSerializerDeserializer.getDouble(b, s + 1);
+        if (Double.isFinite(d)) {
+            ps.print(d);
+        } else {
+            ps.append('"');
+            ps.print(Double.toString(d));
+            ps.append('"');
+        }
+    };
 
     @Override
     public IPrinter createPrinter() {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/d79d96eb/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AFloatPrinterFactory.java
----------------------------------------------------------------------
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AFloatPrinterFactory.java
b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AFloatPrinterFactory.java
index 827ebec..a6cdc0d 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AFloatPrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AFloatPrinterFactory.java
@@ -29,8 +29,16 @@ public class AFloatPrinterFactory implements IPrinterFactory {
     private static final long serialVersionUID = 1L;
     public static final AFloatPrinterFactory INSTANCE = new AFloatPrinterFactory();
 
-    public static final IPrinter PRINTER = (byte[] b, int s, int l, PrintStream ps) ->
ps
-            .print(AFloatSerializerDeserializer.getFloat(b, s + 1));
+    public static final IPrinter PRINTER = (byte[] b, int s, int l, PrintStream ps) ->
{
+        final float aFloat = AFloatSerializerDeserializer.getFloat(b, s + 1);
+        if (Float.isFinite(aFloat)) {
+            ps.print(aFloat);
+        } else {
+            ps.append('"');
+            ps.print(Float.toString(aFloat));
+            ps.append('"');
+        }
+    };
 
     @Override
     public IPrinter createPrinter() {


Mime
View raw message