Corrected JSON output of date/time/duration types.
Change-Id: I5c37d3b5aad7f286eba1cb8cb5f05ad456a6521e
Reviewed-on: https://asterix-gerrit.ics.uci.edu/363
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Chris Hillery <ceej@lambda.nu>
diff --git a/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-cleanjson/alltypes_01.1.json b/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-cleanjson/alltypes_01.1.json
index 5081d69..dd319a4 100644
--- a/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-cleanjson/alltypes_01.1.json
+++ b/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-cleanjson/alltypes_01.1.json
@@ -1,2 +1,2 @@
-[ { "id": 10, "string": "Nancy", "float": 32.5, "double": -2013.5938237483274, "boolean": true, "int8": 125, "int16": 32765, "int32": 294967295, "int64": 1700000000000000000, "unorderedList": [ "reading", "writing" ], "orderedList": [ "Brad", "Scott" ], "record": { "number": 8389, "street": "Hill St.", "city": "Mountain View" }, "date": { "date": -125625945600000}, "time": { "time": 44430000}, "datetime": { "datetime": -123703587570000}, "duration": { "duration": { "months": 131, "millis": 1075830000} }, "point": [41.0, 44.0], "point3d": [44.0, 13.0, 41.0], "line": [ [10.1, 11.1], [10.2, 11.2] ], "rectangle": [ [5.1, 11.8], [87.6, 15.6548] ], "polygon": [ [1.2, 1.3], [2.1, 2.5], [3.5, 3.6], [4.6, 4.8] ], "circle": [ [10.1, 11.1], 10.2 ], "binary": "ABCDEF0123456789", "uuid": "5c848e5c-6b6a-498f-8452-8847a2957421" }
+[ { "id": 10, "string": "Nancy", "float": 32.5, "double": -2013.5938237483274, "boolean": true, "int8": 125, "int16": 32765, "int32": 294967295, "int64": 1700000000000000000, "unorderedList": [ "reading", "writing" ], "orderedList": [ "Brad", "Scott" ], "record": { "number": 8389, "street": "Hill St.", "city": "Mountain View" }, "date": "-2011-01-27", "time": "12:20:30.000Z", "datetime": "-1951-12-27T12:20:30.000Z", "duration": "P10Y11M12DT10H50M30S", "point": [41.0, 44.0], "point3d": [44.0, 13.0, 41.0], "line": [ [10.1, 11.1], [10.2, 11.2] ], "rectangle": [ [5.1, 11.8], [87.6, 15.6548] ], "polygon": [ [1.2, 1.3], [2.1, 2.5], [3.5, 3.6], [4.6, 4.8] ], "circle": [ [10.1, 11.1], 10.2 ], "binary": "ABCDEF0123456789", "uuid": "5c848e5c-6b6a-498f-8452-8847a2957421" }
]
diff --git a/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-losslessjson/alltypes_01.1.json b/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-losslessjson/alltypes_01.1.json
index 5ee58be..2e99438 100644
--- a/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-losslessjson/alltypes_01.1.json
+++ b/asterix-app/src/test/resources/runtimets/results/scan/alltypes_01-losslessjson/alltypes_01.1.json
@@ -1,2 +1,2 @@
-[ { "id": { "int64": 10 }, "string": "Nancy", "float": 32.5, "double": -2013.5938237483274, "boolean": true, "int8": { "int8": 125 }, "int16": { "int16": 32765 }, "int32": { "int32": 294967295 }, "int64": { "int64": 1700000000000000000 }, "unorderedList": { "unorderedlist": [ "reading", "writing" ] }, "orderedList": { "orderedlist": [ "Brad", "Scott" ] }, "record": { "number": { "int64": 8389 }, "street": "Hill St.", "city": "Mountain View" }, "date": { "date": -125625945600000}, "time": { "time": 44430000}, "datetime": { "datetime": -123703587570000}, "duration": { "duration": { "months": 131, "millis": 1075830000} }, "point": { "point": [41.0, 44.0] }, "point3d": { "point3d": [44.0, 13.0, 41.0] }, "line": { "line": [ { "point": [10.1, 11.1] }, { "point": [10.2, 11.2] } ] }, "rectangle": { "rectangle": [{ "point": [5.1, 11.8] }, { "point": [87.6, 15.6548] } ] }, "polygon": { "polygon": [{ "point": [1.2, 1.3] },{ "point": [2.1, 2.5] },{ "point": [3.5, 3.6] },{ "point": [4.6, 4.8] }] }, "circle": { "circle": [ { "point": [10.1, 11.1] }, 10.2 ] }, "binary": "ABCDEF0123456789", "uuid": "5c848e5c-6b6a-498f-8452-8847a2957421" }
+[ { "id": { "int64": 10 }, "string": "Nancy", "float": 32.5, "double": -2013.5938237483274, "boolean": true, "int8": { "int8": 125 }, "int16": { "int16": 32765 }, "int32": { "int32": 294967295 }, "int64": { "int64": 1700000000000000000 }, "unorderedList": { "unorderedlist": [ "reading", "writing" ] }, "orderedList": { "orderedlist": [ "Brad", "Scott" ] }, "record": { "number": { "int64": 8389 }, "street": "Hill St.", "city": "Mountain View" }, "date": { "date": "-2011-01-27" }, "time": { "time": "12:20:30.000Z" }, "datetime": { "datetime": "-1951-12-27T12:20:30.000Z" }, "duration": { "duration": "P10Y11M12DT10H50M30S" }, "point": { "point": [41.0, 44.0] }, "point3d": { "point3d": [44.0, 13.0, 41.0] }, "line": { "line": [ { "point": [10.1, 11.1] }, { "point": [10.2, 11.2] } ] }, "rectangle": { "rectangle": [{ "point": [5.1, 11.8] }, { "point": [87.6, 15.6548] } ] }, "polygon": { "polygon": [{ "point": [1.2, 1.3] },{ "point": [2.1, 2.5] },{ "point": [3.5, 3.6] },{ "point": [4.6, 4.8] }] }, "circle": { "circle": [ { "point": [10.1, 11.1] }, 10.2 ] }, "binary": "ABCDEF0123456789", "uuid": "5c848e5c-6b6a-498f-8452-8847a2957421" }
]
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java
index 6f94c92..596e168 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/PrintTools.java
@@ -18,19 +18,172 @@
*/
package org.apache.asterix.dataflow.data.nontagged.printers;
-import java.io.IOException;
-import java.io.OutputStream;
-
+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;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.data.utils.WriteValueTools;
import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.PrintStream;
+
public class PrintTools {
+ private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
+ private static long CHRONON_OF_DAY = 24 * 60 * 60 * 1000;
+
+ public static void printDateString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
+ long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
+
+ try {
+ gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.DAY, false);
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+
+ public static void printDateTimeString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
+ long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
+
+ try {
+ gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+
+ }
+
+ public static void printDayTimeDurationString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
+ boolean positive = true;
+ long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 1);
+
+ // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
+ if (milliseconds < 0) {
+ milliseconds *= -1;
+ positive = false;
+ }
+
+ int millisecond = gCalInstance.getDurationMillisecond(milliseconds);
+ int second = gCalInstance.getDurationSecond(milliseconds);
+ int minute = gCalInstance.getDurationMinute(milliseconds);
+ int hour = gCalInstance.getDurationHour(milliseconds);
+ int day = gCalInstance.getDurationDay(milliseconds);
+
+ if (!positive) {
+ ps.print("-");
+ }
+ try {
+ ps.print("P");
+ if (day != 0) {
+ WriteValueTools.writeInt(day, ps);
+ ps.print("D");
+ }
+ if (hour != 0 || minute != 0 || second != 0 || millisecond != 0) {
+ ps.print("T");
+ }
+ if (hour != 0) {
+ WriteValueTools.writeInt(hour, ps);
+ ps.print("H");
+ }
+ if (minute != 0) {
+ WriteValueTools.writeInt(minute, ps);
+ ps.print("M");
+ }
+ if (second != 0 || millisecond != 0) {
+ WriteValueTools.writeInt(second, ps);
+ }
+ if (millisecond > 0) {
+ ps.print(".");
+ WriteValueTools.writeInt(millisecond, ps);
+ }
+ if (second != 0 || millisecond != 0) {
+ ps.print("S");
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+
+ public static void printDurationString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
+ boolean positive = true;
+ int months = AInt32SerializerDeserializer.getInt(b, s + 1);
+ long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 5);
+
+ // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
+ if (months < 0 || milliseconds < 0) {
+ months *= -1;
+ milliseconds *= -1;
+ positive = false;
+ }
+
+ int month = gCalInstance.getDurationMonth(months);
+ int year = gCalInstance.getDurationYear(months);
+ int millisecond = gCalInstance.getDurationMillisecond(milliseconds);
+ int second = gCalInstance.getDurationSecond(milliseconds);
+ int minute = gCalInstance.getDurationMinute(milliseconds);
+ int hour = gCalInstance.getDurationHour(milliseconds);
+ int day = gCalInstance.getDurationDay(milliseconds);
+
+ if (!positive) {
+ ps.print("-");
+ }
+ try {
+ ps.print("P");
+ if (year != 0) {
+ WriteValueTools.writeInt(year, ps);
+ ps.print("Y");
+ }
+ if (month != 0) {
+ WriteValueTools.writeInt(month, ps);
+ ps.print("M");
+ }
+ if (day != 0) {
+ WriteValueTools.writeInt(day, ps);
+ ps.print("D");
+ }
+ if (hour != 0 || minute != 0 || second != 0 || millisecond != 0) {
+ ps.print("T");
+ }
+ if (hour != 0) {
+ WriteValueTools.writeInt(hour, ps);
+ ps.print("H");
+ }
+ if (minute != 0) {
+ WriteValueTools.writeInt(minute, ps);
+ ps.print("M");
+ }
+ if (second != 0 || millisecond != 0) {
+ WriteValueTools.writeInt(second, ps);
+ }
+ if (millisecond > 0) {
+ ps.print(".");
+ WriteValueTools.writeInt(millisecond, ps);
+ }
+ if (second != 0 || millisecond != 0) {
+ ps.print("S");
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+
+ public static void printTimeString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
+ int time = AInt32SerializerDeserializer.getInt(b, s + 1);
+
+ try {
+ gCalInstance.getExtendStringRepUntilField(time, 0, ps, GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+
public enum CASE {
LOWER_CASE,
UPPER_CASE,
}
-
public static void writeUTF8StringAsCSV(byte[] b, int s, int l, OutputStream os) throws IOException {
int stringLength = UTF8StringPointable.getUTFLength(b, s);
int position = s + 2; // skip 2 bytes containing string size
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADatePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADatePrinter.java
index c1f952e..cedecff 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADatePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADatePrinter.java
@@ -18,20 +18,15 @@
*/
package org.apache.asterix.dataflow.data.nontagged.printers.adm;
-import java.io.IOException;
import java.io.PrintStream;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
public class ADatePrinter implements IPrinter {
- private static long CHRONON_OF_DAY = 24 * 60 * 60 * 1000;
public static final ADatePrinter INSTANCE = new ADatePrinter();
- private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
@Override
public void init() {
@@ -41,17 +36,7 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
ps.print("date(\"");
- printString(b, s, l, ps);
+ PrintTools.printDateString(b, s, l, ps);
ps.print("\")");
}
-
- public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
-
- try {
- gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.DAY, false);
- } catch (IOException e) {
- throw new AlgebricksException(e);
- }
- }
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADateTimePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADateTimePrinter.java
index b3f60e2..54381f5 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADateTimePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADateTimePrinter.java
@@ -18,19 +18,15 @@
*/
package org.apache.asterix.dataflow.data.nontagged.printers.adm;
-import java.io.IOException;
import java.io.PrintStream;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
public class ADateTimePrinter implements IPrinter {
public static final ADateTimePrinter INSTANCE = new ADateTimePrinter();
- private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
@Override
public void init() {
@@ -40,18 +36,7 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
ps.print("datetime(\"");
- printString(b, s, l, ps);
+ PrintTools.printDateTimeString(b, s, l, ps);
ps.print("\")");
}
-
- public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
-
- try {
- gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.MILLISECOND, true);
- } catch (IOException e) {
- throw new AlgebricksException(e);
- }
-
- }
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADayTimeDurationPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADayTimeDurationPrinter.java
index 59da5d5..e23b3ab 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADayTimeDurationPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADayTimeDurationPrinter.java
@@ -18,19 +18,16 @@
*/
package org.apache.asterix.dataflow.data.nontagged.printers.adm;
-import java.io.IOException;
import java.io.PrintStream;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
-import org.apache.hyracks.algebricks.data.utils.WriteValueTools;
public class ADayTimeDurationPrinter implements IPrinter {
public static final ADayTimeDurationPrinter INSTANCE = new ADayTimeDurationPrinter();
- private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
@Override
public void init() throws AlgebricksException {
@@ -39,56 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- boolean positive = true;
- long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 1);
-
- // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
- if (milliseconds < 0) {
- milliseconds *= -1;
- positive = false;
- }
-
- int millisecond = gCalInstance.getDurationMillisecond(milliseconds);
- int second = gCalInstance.getDurationSecond(milliseconds);
- int minute = gCalInstance.getDurationMinute(milliseconds);
- int hour = gCalInstance.getDurationHour(milliseconds);
- int day = gCalInstance.getDurationDay(milliseconds);
-
ps.print("day-time-duration(\"");
- if (!positive) {
- ps.print("-");
- }
- try {
- ps.print("P");
- if (day != 0) {
- WriteValueTools.writeInt(day, ps);
- ps.print("D");
- }
- if (hour != 0 || minute != 0 || second != 0 || millisecond != 0) {
- ps.print("T");
- }
- if (hour != 0) {
- WriteValueTools.writeInt(hour, ps);
- ps.print("H");
- }
- if (minute != 0) {
- WriteValueTools.writeInt(minute, ps);
- ps.print("M");
- }
- if (second != 0 || millisecond != 0) {
- WriteValueTools.writeInt(second, ps);
- }
- if (millisecond > 0) {
- ps.print(".");
- WriteValueTools.writeInt(millisecond, ps);
- }
- if (second != 0 || millisecond != 0) {
- ps.print("S");
- }
- ps.print("\")");
- } catch (IOException e) {
- throw new AlgebricksException(e);
- }
+ PrintTools.printDayTimeDurationString(b, s, l, ps);
+ ps.print("\")");
}
-
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADurationPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADurationPrinter.java
index 589626c..26c6fc0 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADurationPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ADurationPrinter.java
@@ -18,15 +18,12 @@
*/
package org.apache.asterix.dataflow.data.nontagged.printers.adm;
-import java.io.IOException;
import java.io.PrintStream;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
-import org.apache.hyracks.algebricks.data.utils.WriteValueTools;
public class ADurationPrinter implements IPrinter {
@@ -40,67 +37,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- boolean positive = true;
- int months = AInt32SerializerDeserializer.getInt(b, s + 1);
- long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 5);
-
- // set the negative flag. "||" is necessary in case that months field is not there (so it is 0)
- if (months < 0 || milliseconds < 0) {
- months *= -1;
- milliseconds *= -1;
- positive = false;
- }
-
- int month = gCalInstance.getDurationMonth(months);
- int year = gCalInstance.getDurationYear(months);
- int millisecond = gCalInstance.getDurationMillisecond(milliseconds);
- int second = gCalInstance.getDurationSecond(milliseconds);
- int minute = gCalInstance.getDurationMinute(milliseconds);
- int hour = gCalInstance.getDurationHour(milliseconds);
- int day = gCalInstance.getDurationDay(milliseconds);
-
ps.print("duration(\"");
- if (!positive) {
- ps.print("-");
- }
- try {
- ps.print("P");
- if (year != 0) {
- WriteValueTools.writeInt(year, ps);
- ps.print("Y");
- }
- if (month != 0) {
- WriteValueTools.writeInt(month, ps);
- ps.print("M");
- }
- if (day != 0) {
- WriteValueTools.writeInt(day, ps);
- ps.print("D");
- }
- if (hour != 0 || minute != 0 || second != 0 || millisecond != 0) {
- ps.print("T");
- }
- if (hour != 0) {
- WriteValueTools.writeInt(hour, ps);
- ps.print("H");
- }
- if (minute != 0) {
- WriteValueTools.writeInt(minute, ps);
- ps.print("M");
- }
- if (second != 0 || millisecond != 0) {
- WriteValueTools.writeInt(second, ps);
- }
- if (millisecond > 0) {
- ps.print(".");
- WriteValueTools.writeInt(millisecond, ps);
- }
- if (second != 0 || millisecond != 0) {
- ps.print("S");
- }
- ps.print("\")");
- } catch (IOException e) {
- throw new AlgebricksException(e);
- }
+ PrintTools.printDurationString(b, s, l, ps);
+ ps.print("\")");
}
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AIntervalPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AIntervalPrinter.java
index 1c0adc6..99c02e8 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AIntervalPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AIntervalPrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
import org.apache.asterix.om.types.ATypeTag;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -45,26 +46,21 @@
short typetag = AInt8SerializerDeserializer.getByte(b, s + 1 + 8 * 2);
- IPrinter timeInstancePrinter;
-
if (typetag == ATypeTag.DATE.serialize()) {
ps.print("-date(\"");
- timeInstancePrinter = ADatePrinter.INSTANCE;
- ((ADatePrinter) timeInstancePrinter).printString(b, s + 4, 4, ps);
+ PrintTools.printDateString(b, s + 4, 4, ps);
ps.print(", ");
- ((ADatePrinter) timeInstancePrinter).printString(b, s + 12, 4, ps);
+ PrintTools.printDateString(b, s + 12, 4, ps);
} else if (typetag == ATypeTag.TIME.serialize()) {
ps.print("-time(\"");
- timeInstancePrinter = ATimePrinter.INSTANCE;
- ((ATimePrinter) timeInstancePrinter).printString(b, s + 4, 4, ps);
+ PrintTools.printTimeString(b, s + 4, 4, ps);
ps.print(", ");
- ((ATimePrinter) timeInstancePrinter).printString(b, s + 12, 4, ps);
+ PrintTools.printTimeString(b, s + 12, 4, ps);
} else if (typetag == ATypeTag.DATETIME.serialize()) {
ps.print("-datetime(\"");
- timeInstancePrinter = ADateTimePrinter.INSTANCE;
- ((ADateTimePrinter) timeInstancePrinter).printString(b, s, 8, ps);
+ PrintTools.printDateTimeString(b, s, 8, ps);
ps.print(", ");
- ((ADateTimePrinter) timeInstancePrinter).printString(b, s + 8, 8, ps);
+ PrintTools.printDateTimeString(b, s + 8, 8, ps);
} else {
throw new AlgebricksException("Unsupport internal time types in interval: " + typetag);
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ATimePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ATimePrinter.java
index 06861a6..10c4575 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ATimePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/ATimePrinter.java
@@ -18,19 +18,16 @@
*/
package org.apache.asterix.dataflow.data.nontagged.printers.adm;
-import java.io.IOException;
import java.io.PrintStream;
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
public class ATimePrinter implements IPrinter {
public static final ATimePrinter INSTANCE = new ATimePrinter();
- private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
@Override
public void init() {
@@ -40,18 +37,7 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
ps.print("time(\"");
- printString(b,s,l, ps);
+ PrintTools.printTimeString(b, s, l, ps);
ps.print("\")");
}
-
- public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- int time = AInt32SerializerDeserializer.getInt(b, s + 1);
-
- try {
- gCalInstance.getExtendStringRepUntilField(time, 0, ps, Fields.HOUR, Fields.MILLISECOND, true);
- } catch (IOException e) {
- throw new AlgebricksException(e);
- }
- }
-
}
\ No newline at end of file
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADatePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADatePrinter.java
index 4988483..5994adc 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADatePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADatePrinter.java
@@ -20,13 +20,13 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
public class ADatePrinter implements IPrinter {
- private static long CHRONON_OF_DAY = 24 * 60 * 60 * 1000;
public static final ADatePrinter INSTANCE = new ADatePrinter();
@Override
@@ -36,10 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
-
- ps.print("{ \"date\": ");
- ps.print(chrononTime);
- ps.print("}");
+ ps.print("\"");
+ PrintTools.printDateString(b, s, l, ps);
+ ps.print("\"");
}
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADateTimePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADateTimePrinter.java
index 19d1270..6d98b8d 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADateTimePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADateTimePrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
@@ -35,10 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
-
- ps.print("{ \"datetime\": ");
- ps.print(chrononTime);
- ps.print("}");
+ ps.print("\"");
+ PrintTools.printDateTimeString(b, s, l, ps);
+ ps.print("\"");
}
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADayTimeDurationPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADayTimeDurationPrinter.java
index 3d7ea84..409586c 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADayTimeDurationPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADayTimeDurationPrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
@@ -35,11 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 1);
-
- ps.print("{ \"day-time-duration\": ");
- ps.print(milliseconds);
- ps.print("}");
+ ps.print("\"");
+ PrintTools.printDayTimeDurationString(b, s, l, ps);
+ ps.print("\")");
}
-
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADurationPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADurationPrinter.java
index 14ee58e..59874af 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADurationPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ADurationPrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -36,14 +37,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- int months = AInt32SerializerDeserializer.getInt(b, s + 1);
- long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 5);
-
- ps.print("{ \"duration\": { ");
- ps.print("\"months\": ");
- ps.print(months);
- ps.print(", \"millis\": ");
- ps.print(milliseconds);
- ps.print("} }");
+ ps.print("\"");
+ PrintTools.printDurationString(b, s, l, ps);
+ ps.print("\"");
}
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ATimePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ATimePrinter.java
index 625494a..1ffceea 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ATimePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/ATimePrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
@@ -35,11 +36,9 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- int time = AInt32SerializerDeserializer.getInt(b, s + 1);
-
- ps.print("{ \"time\": ");
- ps.print(time);
- ps.print("}");
+ ps.print("\"");
+ PrintTools.printTimeString(b, s, l, ps);
+ ps.print("\"");
}
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADatePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADatePrinter.java
index d7eb138..0cc8eb5 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADatePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADatePrinter.java
@@ -20,13 +20,13 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
public class ADatePrinter implements IPrinter {
- private static long CHRONON_OF_DAY = 24 * 60 * 60 * 1000;
public static final ADatePrinter INSTANCE = new ADatePrinter();
@Override
@@ -36,10 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
-
- ps.print("{ \"date\": ");
- ps.print(chrononTime);
- ps.print("}");
+ ps.print("{ \"date\": \"");
+ PrintTools.printDateString(b, s, l, ps);
+ ps.print("\" }");
}
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADateTimePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADateTimePrinter.java
index 0705283..de9445e 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADateTimePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADateTimePrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
@@ -35,10 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
-
- ps.print("{ \"datetime\": ");
- ps.print(chrononTime);
- ps.print("}");
+ ps.print("{ \"datetime\": \"");
+ PrintTools.printDateTimeString(b, s, l, ps);
+ ps.print("\" }");
}
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADayTimeDurationPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADayTimeDurationPrinter.java
index a00519a..3b29ba8 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADayTimeDurationPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADayTimeDurationPrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
@@ -35,10 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 1);
-
ps.print("{ \"day-time-duration\": ");
- ps.print(milliseconds);
+ PrintTools.printDayTimeDurationString(b, s, l, ps);
ps.print("}");
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADurationPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADurationPrinter.java
index 315fd30..1642afa 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADurationPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ADurationPrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -36,14 +37,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- int months = AInt32SerializerDeserializer.getInt(b, s + 1);
- long milliseconds = AInt64SerializerDeserializer.getLong(b, s + 5);
-
- ps.print("{ \"duration\": { ");
- ps.print("\"months\": ");
- ps.print(months);
- ps.print(", \"millis\": ");
- ps.print(milliseconds);
- ps.print("} }");
+ ps.print("{ \"duration\": \"");
+ PrintTools.printDurationString(b, s, l, ps);
+ ps.print("\" }");
}
}
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ATimePrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ATimePrinter.java
index cd5fcc0..59328c0 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ATimePrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/ATimePrinter.java
@@ -20,6 +20,7 @@
import java.io.PrintStream;
+import org.apache.asterix.dataflow.data.nontagged.printers.PrintTools;
import org.apache.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
import org.apache.hyracks.algebricks.data.IPrinter;
@@ -35,11 +36,8 @@
@Override
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
- int time = AInt32SerializerDeserializer.getInt(b, s + 1);
-
- ps.print("{ \"time\": ");
- ps.print(time);
- ps.print("}");
+ ps.print("{ \"time\": \"");
+ PrintTools.printTimeString(b, s, l, ps);
+ ps.print("\" }");
}
-
}