asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Till Westmann (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Print non-numeric floating point values as strings
Date Sat, 24 Sep 2016 18:14:04 GMT
Till Westmann has submitted this change and it was merged.

Change subject: Print non-numeric floating point values as strings
......................................................................


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>
---
A asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/non-finite/non-finite.1.query.sqlpp
A asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/non-finite/non-finite.1.json
M asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
M asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADoublePrinterFactory.java
M asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AFloatPrinterFactory.java
5 files changed, 32 insertions(+), 4 deletions(-)

Approvals:
  Yingyi Bu: Looks good to me, approved
  Jenkins: Verified; No violations found; Verified



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)
+};
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" }
+ ]
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">
     <!--
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 @@
     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() {
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 @@
     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() {

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/1208
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I423fa30005a0987b1b98dc111a489a64e347df15
Gerrit-PatchSet: 3
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Till Westmann <tillw@apache.org>
Gerrit-Reviewer: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Gerrit-Reviewer: Till Westmann <tillw@apache.org>
Gerrit-Reviewer: Yingyi Bu <buyingyi@gmail.com>

Mime
View raw message