[ASTERIXDB-2000][RT] Fix roundtrip-ability for INF in JSON format.

- user model changes: no
- storage format changes: no
- interface changes: no

Details:
- Use INF to represent infinity.

Change-Id: I13687822433744afe1ad3439029b2c0887563f9b
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1901
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
BAD: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/asterixdb/asterix-app/data/infinity.adm b/asterixdb/asterix-app/data/infinity.adm
new file mode 100644
index 0000000..fd44c8f
--- /dev/null
+++ b/asterixdb/asterix-app/data/infinity.adm
@@ -0,0 +1 @@
+{ "id": 1, "a": INF, "b": -INF, "c":NaN }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.1.ddl.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.1.ddl.sqlpp
new file mode 100644
index 0000000..7059c72
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.1.ddl.sqlpp
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+drop  dataverse test if exists;
+create  dataverse test;
+use test;
+
+create type test as {
+   id: int
+}
+
+create dataset test(test) primary key id;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.2.update.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.2.update.sqlpp
new file mode 100644
index 0000000..fd0f6ad
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.2.update.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+load dataset test using localfs ((`path`=`asterix_nc1://data/infinity.adm`),(`format`=`adm`));
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.3.query.sqlpp b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.3.query.sqlpp
new file mode 100644
index 0000000..aeb2c0d
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/numeric/infinity/infinity.3.query.sqlpp
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+use test;
+
+
+select value test from test;
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/double_01/double_01.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/double_01/double_01.1.adm
index ae7413d..0f1f5df 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/double_01/double_01.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/double_01/double_01.1.adm
@@ -1 +1 @@
-{ "double1": NaN, "double2": Infinity, "double3": -Infinity, "double4": -80.2, "double5": -2.056E-29, "double6": -2.056E-299, "double7": -2.056E-299 }
+{ "double1": NaN, "double2": INF, "double3": -INF, "double4": -80.2, "double5": -2.056E-29, "double6": -2.056E-299, "double7": -2.056E-299 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/float_01/float_01.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/float_01/float_01.1.adm
index 9acd764..722697d 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/float_01/float_01.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/constructor/float_01/float_01.1.adm
@@ -1 +1 @@
-{ "float1": NaN, "float2": Infinity, "float3": -Infinity, "float4": -80.2, "float5": -2.056E-29, "float6": -2.056E-29 }
+{ "float1": NaN, "float2": INF, "float3": -INF, "float4": -80.2, "float5": -2.056E-29, "float6": -2.056E-29 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs2/abs2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs2/abs2.1.adm
index 22e50da..7429760 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs2/abs2.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs2/abs2.1.adm
@@ -1 +1 @@
-{ "f0": 20.1, "f1": 2.056E-29, "f2": NaN, "f3": Infinity, "f4": Infinity, "f5": 0.0, "f6": 0.0 }
+{ "f0": 20.1, "f1": 2.056E-29, "f2": NaN, "f3": INF, "f4": INF, "f5": -0.0, "f6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs3/abs3.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs3/abs3.1.adm
index f938327..c868b79 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs3/abs3.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/abs3/abs3.1.adm
@@ -1 +1 @@
-{ "d0": 20.1, "d1": 2.056E-29, "d2": NaN, "d3": Infinity, "d4": Infinity, "d5": 0.0, "d6": 0.0 }
+{ "d0": 20.1, "d1": 2.056E-29, "d2": NaN, "d3": INF, "d4": INF, "d5": -0.0, "d6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret0/caret0.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret0/caret0.1.adm
index 3d2b01c..bec02d6 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret0/caret0.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/caret0/caret0.1.adm
@@ -1 +1 @@
-{ "c1": Infinity, "c2": 1.6777216E7, "c3": 9 }
+{ "c1": INF, "c2": 1.6777216E7, "c3": 9 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling2/ceiling2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling2/ceiling2.1.adm
index 0d2c59f..3311d2a 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling2/ceiling2.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling2/ceiling2.1.adm
@@ -1 +1 @@
-{ "f0": 21.0, "f1": -0.0, "f2": NaN, "f3": Infinity, "f4": -Infinity, "f5": -0.0, "f6": 0.0 }
+{ "f0": 21.0, "f1": -0.0, "f2": NaN, "f3": INF, "f4": -INF, "f5": -0.0, "f6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling3/ceiling3.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling3/ceiling3.1.adm
index 6d944b9..c81e935 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling3/ceiling3.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ceiling3/ceiling3.1.adm
@@ -1 +1 @@
-{ "d0": 21.0, "d1": -0.0, "d2": NaN, "d3": Infinity, "d4": -Infinity, "d5": -0.0, "d6": 0.0 }
+{ "d0": 21.0, "d1": -0.0, "d2": NaN, "d3": INF, "d4": -INF, "d5": -0.0, "d6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor2/floor2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor2/floor2.1.adm
index 9366300..9e493c2 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor2/floor2.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor2/floor2.1.adm
@@ -1 +1 @@
-{ "f0": 20.0, "f1": -1.0, "f2": NaN, "f3": Infinity, "f4": -Infinity, "f5": -0.0, "f6": 0.0 }
+{ "f0": 20.0, "f1": -1.0, "f2": NaN, "f3": INF, "f4": -INF, "f5": -0.0, "f6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor3/floor3.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor3/floor3.1.adm
index cb452ad..4322a51 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor3/floor3.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/floor3/floor3.1.adm
@@ -1 +1 @@
-{ "d0": 20.0, "d1": -1.0, "d2": NaN, "d3": Infinity, "d4": -Infinity, "d5": -0.0, "d6": 0.0 }
+{ "d0": 20.0, "d1": -1.0, "d2": NaN, "d3": INF, "d4": -INF, "d5": -0.0, "d6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/infinity/infinity.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/infinity/infinity.1.adm
new file mode 100644
index 0000000..8f7401a
--- /dev/null
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/infinity/infinity.1.adm
@@ -0,0 +1 @@
+{ "id": 1, "a": INF, "b": -INF, "c": NaN }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm
index 598faa4..aa6439f 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/ln/ln.1.adm
@@ -1 +1 @@
-{ "a": 4.787491742782046, "b": 4.505349850705881, "c": 4.499809670330265, "d": -Infinity, "e": NaN, "f": 0.0, "g": null }
+{ "a": 4.787491742782046, "b": 4.505349850705881, "c": 4.499809670330265, "d": -INF, "e": NaN, "f": 0.0, "g": null }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm
index 5280bf9..333cf3e 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/log/log.1.adm
@@ -1 +1 @@
-{ "a": 2.0791812460476247, "b": 1.9566485792052033, "c": 1.954242509439325, "d": -Infinity, "e": NaN, "f": 0.0, "g": null }
+{ "a": 2.0791812460476247, "b": 1.9566485792052033, "c": 1.954242509439325, "d": -INF, "e": NaN, "f": 0.0, "g": null }
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
index db5a90c..78d4801 100644
--- 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
@@ -1,2 +1,2 @@
-[ { "NaN": "NaN", "Infinity": "Infinity", "-Infinity": "-Infinity" }
- ]
+[ { "NaN": "NaN", "Infinity": "INF", "-Infinity": "-INF" }
+ ]
\ No newline at end of file
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even2/round-half-to-even2.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even2/round-half-to-even2.1.adm
index 2371813..0c4af96 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even2/round-half-to-even2.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even2/round-half-to-even2.1.adm
@@ -1 +1 @@
-{ "f0": 0.0, "f1": -20.0, "f2": NaN, "f3": Infinity, "f4": -Infinity, "f5": -0.0, "f6": 0.0 }
+{ "f0": 0.0, "f1": -20.0, "f2": NaN, "f3": INF, "f4": -INF, "f5": -0.0, "f6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even22/round-half-to-even22.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even22/round-half-to-even22.1.adm
index ddc981b..0050d53 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even22/round-half-to-even22.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even22/round-half-to-even22.1.adm
@@ -1 +1 @@
-{ "d0": 0.56, "d1": 0.32, "d2": NaN, "d3": Infinity, "d4": -Infinity, "d5": -0.0, "d6": 0.0 }
+{ "d0": 0.56, "d1": 0.32, "d2": NaN, "d3": INF, "d4": -INF, "d5": -0.0, "d6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even23/round-half-to-even23.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even23/round-half-to-even23.1.adm
index ddc981b..0050d53 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even23/round-half-to-even23.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even23/round-half-to-even23.1.adm
@@ -1 +1 @@
-{ "d0": 0.56, "d1": 0.32, "d2": NaN, "d3": Infinity, "d4": -Infinity, "d5": -0.0, "d6": 0.0 }
+{ "d0": 0.56, "d1": 0.32, "d2": NaN, "d3": INF, "d4": -INF, "d5": -0.0, "d6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even3/round-half-to-even3.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even3/round-half-to-even3.1.adm
index 8b67144..a58f7bc 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even3/round-half-to-even3.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/round-half-to-even3/round-half-to-even3.1.adm
@@ -1 +1 @@
-{ "d0": 0.0, "d1": -20.0, "d2": NaN, "d3": Infinity, "d4": -Infinity, "d5": -0.0, "d6": 0.0 }
+{ "d0": 0.0, "d1": -20.0, "d2": NaN, "d3": INF, "d4": -INF, "d5": -0.0, "d6": 0.0 }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_double_02/unary-minus_double_02.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_double_02/unary-minus_double_02.1.adm
index 399b39c..f848687 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_double_02/unary-minus_double_02.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_double_02/unary-minus_double_02.1.adm
@@ -1 +1 @@
-{ "double1": 2.056E-29, "double2": NaN, "double3": -Infinity, "double4": Infinity }
+{ "double1": 2.056E-29, "double2": NaN, "double3": -INF, "double4": INF }
diff --git a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_float_02/unary-minus_float_02.1.adm b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_float_02/unary-minus_float_02.1.adm
index d47edae..c7fb8f2 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_float_02/unary-minus_float_02.1.adm
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/results/numeric/unary-minus_float_02/unary-minus_float_02.1.adm
@@ -1 +1 @@
-{ "float1": 80.2, "float2": NaN, "float3": -Infinity, "float4": Infinity }
+{ "float1": 80.2, "float2": NaN, "float3": -INF, "float4": INF }
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 cd0355a..47c0529 100644
--- a/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
+++ b/asterixdb/asterix-app/src/test/resources/runtimets/testsuite_sqlpp.xml
@@ -4508,6 +4508,11 @@
       </compilation-unit>
     </test-case>
     <test-case FilePath="numeric">
+      <compilation-unit name="infinity">
+        <output-dir compare="Text">infinity</output-dir>
+      </compilation-unit>
+    </test-case>
+    <test-case FilePath="numeric">
       <compilation-unit name="multiply_double">
         <output-dir compare="Text">multiply_double</output-dir>
       </compilation-unit>
diff --git a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
index 44766ff..d964788 100644
--- a/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
+++ b/asterixdb/asterix-external-data/src/main/java/org/apache/asterix/external/parser/ADMDataParser.java
@@ -921,11 +921,23 @@
                 parseInt64(unquoted, out);
                 return true;
             case FLOAT:
-                aFloat.setValue(Float.parseFloat(unquoted));
+                if ("INF".equals(unquoted)) {
+                    aFloat.setValue(Float.POSITIVE_INFINITY);
+                } else if ("-INF".equals(unquoted)) {
+                    aFloat.setValue(Float.NEGATIVE_INFINITY);
+                } else {
+                    aFloat.setValue(Float.parseFloat(unquoted));
+                }
                 floatSerde.serialize(aFloat, out);
                 return true;
             case DOUBLE:
-                aDouble.setValue(Double.parseDouble(unquoted));
+                if ("INF".equals(unquoted)) {
+                    aDouble.setValue(Double.POSITIVE_INFINITY);
+                } else if ("-INF".equals(unquoted)) {
+                    aDouble.setValue(Double.NEGATIVE_INFINITY);
+                } else {
+                    aDouble.setValue(Double.parseDouble(unquoted));
+                }
                 doubleSerde.serialize(aDouble, out);
                 return true;
             case STRING:
diff --git a/asterixdb/asterix-external-data/src/main/resources/adm.grammar b/asterixdb/asterix-external-data/src/main/resources/adm.grammar
index b4f5432..4de729f 100644
--- a/asterixdb/asterix-external-data/src/main/resources/adm.grammar
+++ b/asterixdb/asterix-external-data/src/main/resources/adm.grammar
@@ -83,8 +83,8 @@
 DOUBLE_LITERAL       = signOrNothing(), digitSequence(), char(.), digitSequence(), token(@EXPONENT)
 DOUBLE_LITERAL       = signOrNothing(), digitSequence(), token(@EXPONENT)
 DOUBLE_LITERAL       = string(NaN)
-DOUBLE_LITERAL       = string(Infinity)
-DOUBLE_LITERAL       = string(-Infinity)
+DOUBLE_LITERAL       = string(INF)
+DOUBLE_LITERAL       = string(-INF)
 
 DOUBLE_LITERAL       = token(DOUBLE_LITERAL), caseInsensitiveChar(d)
 FLOAT_LITERAL        = token(DOUBLE_LITERAL), caseInsensitiveChar(f)
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java
index 5b5f53f..b1039a5 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java
@@ -22,6 +22,8 @@
 import java.io.OutputStream;
 import java.io.PrintStream;
 
+import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
@@ -215,6 +217,46 @@
         }
     }
 
+    public static void printDoubleForJson(byte[] b, int s, PrintStream ps) throws HyracksDataException {
+        final double d = ADoubleSerializerDeserializer.getDouble(b, s + 1);
+        if (Double.isFinite(d)) {
+            ps.print(d);
+        } else {
+            ps.append('"');
+            ps.print(Double.isNaN(d) ? "NaN" : (d == Double.POSITIVE_INFINITY) ? "INF" : "-INF");
+            ps.append('"');
+        }
+    }
+
+    public static void printDouble(byte[] b, int s, PrintStream ps) throws HyracksDataException {
+        final double d = ADoubleSerializerDeserializer.getDouble(b, s + 1);
+        if (Double.isFinite(d)) {
+            ps.print(d);
+        } else {
+            ps.print(Double.isNaN(d) ? "NaN" : (d == Double.POSITIVE_INFINITY) ? "INF" : "-INF");
+        }
+    }
+
+    public static void printFloatForJson(byte[] b, int s, PrintStream ps) throws HyracksDataException {
+        final float f = AFloatSerializerDeserializer.getFloat(b, s + 1);
+        if (Float.isFinite(f)) {
+            ps.print(f);
+        } else {
+            ps.print('"');
+            ps.print(Float.isNaN(f) ? "NaN" : (f == Float.POSITIVE_INFINITY) ? "INF" : "-INF");
+            ps.print('"');
+        }
+    }
+
+    public static void printFloat(byte[] b, int s, PrintStream ps) throws HyracksDataException {
+        final float f = AFloatSerializerDeserializer.getFloat(b, s + 1);
+        if (Float.isFinite(f)) {
+            ps.print(f);
+        } else {
+            ps.print(Float.isNaN(f) ? "NaN" : (f == Float.POSITIVE_INFINITY) ? "INF" : "-INF");
+        }
+    }
+
     public enum CASE {
         LOWER_CASE,
         UPPER_CASE,
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADoublePrinterFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADoublePrinterFactory.java
index 15dbbbc..49455d5 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADoublePrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADoublePrinterFactory.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,8 +29,8 @@
     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) -> PrintTools.printDouble(b, s,
+            ps);
 
     @Override
     public IPrinter createPrinter() {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AFloatPrinterFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AFloatPrinterFactory.java
index edf1e1d..3f5d4c2 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AFloatPrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AFloatPrinterFactory.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,8 +29,7 @@
     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) -> PrintTools.printFloat(b, s, ps);
 
     @Override
     public IPrinter createPrinter() {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/ADoublePrinterFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/ADoublePrinterFactory.java
index d08bae5..29f11c4 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/ADoublePrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/ADoublePrinterFactory.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,8 +29,8 @@
     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) -> PrintTools.printDouble(b, s,
+            ps);
 
     @Override
     public IPrinter createPrinter() {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/AFloatPrinterFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/AFloatPrinterFactory.java
index ed2c2f4..987ed8a 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/AFloatPrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/csv/AFloatPrinterFactory.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,8 +29,7 @@
     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) -> PrintTools.printFloat(b, s, ps);
 
     @Override
     public IPrinter createPrinter() {
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 abf9ced..2081162 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
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,16 +29,8 @@
     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) -> {
-        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('"');
-        }
-    };
+    public static final IPrinter PRINTER = (byte[] b, int s, int l, PrintStream ps) -> PrintTools.printDoubleForJson(b,
+            s, ps);
 
     @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 a6cdc0d..46ff2f7 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
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,16 +29,8 @@
     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) -> {
-        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('"');
-        }
-    };
+    public static final IPrinter PRINTER = (byte[] b, int s, int l, PrintStream ps) -> PrintTools.printFloatForJson(b,
+            s, ps);
 
     @Override
     public IPrinter createPrinter() {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADoublePrinterFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADoublePrinterFactory.java
index a14a16f..5d74980 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADoublePrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADoublePrinterFactory.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.ADoubleSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,8 +29,8 @@
     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) -> PrintTools.printDoubleForJson(b,
+            s, ps);
 
     @Override
     public IPrinter createPrinter() {
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AFloatPrinterFactory.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AFloatPrinterFactory.java
index 987dbd8..6ed3f98 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AFloatPrinterFactory.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AFloatPrinterFactory.java
@@ -20,7 +20,7 @@
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AFloatSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
 import org.apache.hyracks.algebricks.data.IPrinter;
 import org.apache.hyracks.algebricks.data.IPrinterFactory;
 
@@ -29,8 +29,8 @@
     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) -> PrintTools.printFloatForJson(b,
+            s, ps);
 
     @Override
     public IPrinter createPrinter() {