fixed an issue reported by Steven on temporal loading issue; rewrote the printers to share the print code
diff --git a/asterix-app/data/temporal/simpletemp_30.json b/asterix-app/data/temporal/simpletemp_30.json
new file mode 100644
index 0000000..f0a4582
--- /dev/null
+++ b/asterix-app/data/temporal/simpletemp_30.json
@@ -0,0 +1,3 @@
+{ "date": date("4619-11-23"), "time": time("14:29:36.786Z"), "datetime": datetime("2749-01-27T17:27:30.020Z"), "duration": duration("-P474133Y7M854630DT4H40M6.45S"), "year-month-duration": year-month-duration("P193989Y3M"), "day-time-duration": day-time-duration("P4477686DT4H49M31.87S"), "date-interval": interval-date("-9537-08-04, 9656-06-03"), "time-interval": interval-time("12:04:45.689Z, 12:41:59.002Z"), "datetime-interval": interval-datetime("-2640-10-11T17:32:15.675Z, 4104-02-01T05:59:11.902Z") }
+{ "date": date("-9971-09-24"), "time": time("11:38:17.154Z"), "datetime": datetime("1259-11-13T09:49:11.852Z"), "duration": duration("P473653Y9M4566143DT10H20M53.61S"), "year-month-duration": year-month-duration("P148233Y10M"), "day-time-duration": day-time-duration("-P7236357DT2H56M56.164S"), "date-interval": interval-date("-0255-09-06, 4925-05-03"), "time-interval": interval-time("23:10:45.169Z, 01:37:48.736Z"), "datetime-interval": interval-datetime("0534-12-08T08:20:31.487Z, 6778-02-16T22:40:21.653Z") }
+{ "date": date("7986-11-25"), "time": time("12:49:39.736Z"), "datetime": datetime("-8337-01-30T15:23:07.598Z"), "duration": duration("-P184484Y7M2241423DT10H42M49.500S"), "year-month-duration": year-month-duration("-P546031Y3M"), "day-time-duration": day-time-duration("P2623386DT10H32M31.983S"), "date-interval": interval-date("-4514-05-24, 3337-08-26"), "time-interval": interval-time("04:16:42.321Z, 02:22:56.816Z"), "datetime-interval": interval-datetime("2129-12-12T13:18:35.758Z, 8647-07-01T13:10:19.691Z") }
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.ddl.aql
new file mode 100644
index 0000000..66d955c
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.ddl.aql
@@ -0,0 +1,25 @@
+/*
+ * Test case name: insert_from_ext_ds_2
+ * Description: verify external data loading on temporal types
+ * Expected result: success
+ */
+
+drop dataverse timeTest if exists;
+create dataverse timeTest;
+use dataverse timeTest;
+
+create type timesType as open {
+ date: date,
+ time: time,
+ datetime: datetime,
+ duration: duration,
+ year-month-duration: year-month-duration,
+ day-time-duration: day-time-duration,
+ date-interval: interval,
+ time-interval: interval,
+ datetime-interval: interval
+}
+
+create dataset timeData(timesType)
+primary key date;
+
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.2.update.aql
new file mode 100644
index 0000000..daff7c6
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.2.update.aql
@@ -0,0 +1,4 @@
+use dataverse timeTest;
+
+load dataset timeData using localfs
+(("path"="nc1://data/temporal/simpletemp_30.json"),("format"="adm"));
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.3.query.aql
new file mode 100644
index 0000000..28549c8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.3.query.aql
@@ -0,0 +1,5 @@
+use dataverse timeTest;
+
+for $r in dataset timeData
+order by $r.date
+return $r
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.adm b/asterix-app/src/test/resources/runtimets/results/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.adm
new file mode 100644
index 0000000..4d1cf59
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/temporal/insert_from_ext_ds_2/insert_from_ext_ds_2.1.adm
@@ -0,0 +1,3 @@
+{ "date": date("-9971-09-24"), "time": time("11:38:17.154Z"), "datetime": datetime("1259-11-13T09:49:11.852Z"), "duration": duration("P473653Y9M4566143DT10H20M53.61S"), "year-month-duration": year-month-duration("P148233Y10M"), "day-time-duration": day-time-duration("-P7236357DT2H56M56.164S"), "date-interval": interval-date("-0255-09-06, 4925-05-03"), "time-interval": interval-time("23:10:45.169Z, 01:37:48.736Z"), "datetime-interval": interval-datetime("0534-12-08T08:20:31.487Z, 6778-02-16T22:40:21.653Z") }
+{ "date": date("4619-11-23"), "time": time("14:29:36.786Z"), "datetime": datetime("2749-01-27T17:27:30.020Z"), "duration": duration("-P474133Y7M854630DT4H40M6.45S"), "year-month-duration": year-month-duration("P193989Y3M"), "day-time-duration": day-time-duration("P4477686DT4H49M31.87S"), "date-interval": interval-date("-9537-08-04, 9656-06-03"), "time-interval": interval-time("12:04:45.689Z, 12:41:59.002Z"), "datetime-interval": interval-datetime("-2640-10-11T17:32:15.675Z, 4104-02-01T05:59:11.902Z") }
+{ "date": date("7986-11-25"), "time": time("12:49:39.736Z"), "datetime": datetime("-8337-01-30T15:23:07.598Z"), "duration": duration("-P184484Y7M2241423DT10H42M49.500S"), "year-month-duration": year-month-duration("-P546031Y3M"), "day-time-duration": day-time-duration("P2623386DT10H32M31.983S"), "date-interval": interval-date("-4514-05-24, 3337-08-26"), "time-interval": interval-time("04:16:42.321Z, 02:22:56.816Z"), "datetime-interval": interval-datetime("2129-12-12T13:18:35.758Z, 8647-07-01T13:10:19.691Z") }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index 417dac7..a845040 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -4314,6 +4314,11 @@
<output-dir compare="Text">insert_from_ext_ds</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="temporal">
+ <compilation-unit name="insert_from_ext_ds_2">
+ <output-dir compare="Text">insert_from_ext_ds_2</output-dir>
+ </compilation-unit>
+ </test-case>
<test-case FilePath="temporal">
<compilation-unit name="interval_functions">
<output-dir compare="Text">interval_functions</output-dir>
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
index 327faf1..b7df6ff 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADatePrinter.java
@@ -1,9 +1,11 @@
package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
+import java.io.IOException;
import java.io.PrintStream;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
@@ -22,22 +24,22 @@
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
long chrononTime = AInt32SerializerDeserializer.getInt(b, s + 1) * CHRONON_OF_DAY;
- int year = gCalInstance.getYear(chrononTime);
- int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
ps.print("date(\"");
- ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
- .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)));
+ try {
+ gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.DAY, false);
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
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;
- int year = gCalInstance.getYear(chrononTime);
- int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
- ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
- .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)));
+ 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/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
index 7cf1478..a412cb1 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADateTimePrinter.java
@@ -1,9 +1,11 @@
package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
+import java.io.IOException;
import java.io.PrintStream;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
@@ -21,30 +23,25 @@
public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
- int year = gCalInstance.getYear(chrononTime);
- int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
ps.print("datetime(\"");
- ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
- .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)))
- .append("T").append(String.format("%02d", gCalInstance.getHourOfDay(chrononTime))).append(":")
- .append(String.format("%02d", gCalInstance.getMinOfHour(chrononTime))).append(":")
- .append(String.format("%02d", gCalInstance.getSecOfMin(chrononTime))).append(".")
- .append(String.format("%03d", gCalInstance.getMillisOfSec(chrononTime))).append("Z");
+
+ try {
+ gCalInstance.getExtendStringRepUntilField(chrononTime, 0, ps, Fields.YEAR, Fields.MILLISECOND, true);
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+
ps.print("\")");
}
public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
long chrononTime = AInt64SerializerDeserializer.getLong(b, s + 1);
- int year = gCalInstance.getYear(chrononTime);
- int month = gCalInstance.getMonthOfYear(chrononTime, year);
-
- ps.append(String.format(year < 0 ? "%05d" : "%04d", year)).append("-").append(String.format("%02d", month))
- .append("-").append(String.format("%02d", gCalInstance.getDayOfMonthYear(chrononTime, year, month)))
- .append("T").append(String.format("%02d", gCalInstance.getHourOfDay(chrononTime))).append(":")
- .append(String.format("%02d", gCalInstance.getMinOfHour(chrononTime))).append(":")
- .append(String.format("%02d", gCalInstance.getSecOfMin(chrononTime))).append(".")
- .append(String.format("%03d", gCalInstance.getMillisOfSec(chrononTime))).append("Z");
+ 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/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
index aba6a4b..6550906 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ATimePrinter.java
@@ -1,9 +1,11 @@
package edu.uci.ics.asterix.dataflow.data.nontagged.printers;
+import java.io.IOException;
import java.io.PrintStream;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem.Fields;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
import edu.uci.ics.hyracks.algebricks.data.IPrinter;
@@ -22,21 +24,24 @@
int time = AInt32SerializerDeserializer.getInt(b, s + 1);
ps.print("time(\"");
- ps.append(String.format("%02d", gCalInstance.getHourOfDay(time))).append(":")
- .append(String.format("%02d", gCalInstance.getMinOfHour(time))).append(":")
- .append(String.format("%02d", gCalInstance.getSecOfMin(time))).append(".")
- .append(String.format("%03d", gCalInstance.getMillisOfSec(time))).append("Z");
+
+ try {
+ gCalInstance.getExtendStringRepUntilField(time, 0, ps, Fields.HOUR, Fields.MILLISECOND, true);
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
ps.print("\")");
}
-
+
public void printString(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
int time = AInt32SerializerDeserializer.getInt(b, s + 1);
- ps.append(String.format("%02d", gCalInstance.getHourOfDay(time))).append(":")
- .append(String.format("%02d", gCalInstance.getMinOfHour(time))).append(":")
- .append(String.format("%02d", gCalInstance.getSecOfMin(time))).append(".")
- .append(String.format("%03d", gCalInstance.getMillisOfSec(time))).append("Z");
+ 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/edu/uci/ics/asterix/om/base/ADate.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
index 0ef170e..28008b2 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADate.java
@@ -14,6 +14,8 @@
*/
package edu.uci.ics.asterix.om.base;
+import java.io.IOException;
+
import org.json.JSONException;
import org.json.JSONObject;
@@ -75,9 +77,12 @@
public String toString() {
StringBuilder sbder = new StringBuilder();
sbder.append("ADate: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(
- chrononTimeInDay * CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
- GregorianCalendarSystem.Fields.DAY);
+ try {
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(chrononTimeInDay * CHRONON_OF_DAY, 0,
+ sbder, GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.DAY, false);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
sbder.append(" }");
return sbder.toString();
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
index 081fa63..10d49aa 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ADateTime.java
@@ -14,6 +14,8 @@
*/
package edu.uci.ics.asterix.om.base;
+import java.io.IOException;
+
import org.json.JSONException;
import org.json.JSONObject;
@@ -106,8 +108,12 @@
public String toString() {
StringBuilder sbder = new StringBuilder();
sbder.append("ADateTime: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(chrononTime, 0, sbder,
- GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND);
+ try {
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(chrononTime, 0, sbder,
+ GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
sbder.append(" }");
return sbder.toString();
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java
index f1352f1..e3c5213 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/AInterval.java
@@ -14,6 +14,8 @@
*/
package edu.uci.ics.asterix.om.base;
+import java.io.IOException;
+
import org.json.JSONException;
import org.json.JSONObject;
@@ -100,33 +102,38 @@
public String toString() {
StringBuilder sbder = new StringBuilder();
sbder.append("AInterval: { ");
- if (typetag == ATypeTag.DATE.serialize()) {
- sbder.append("ADate: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(
- intervalStart * ADate.CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
- GregorianCalendarSystem.Fields.DAY);
- sbder.append(" }, ADate: {");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(
- intervalEnd * ADate.CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
- GregorianCalendarSystem.Fields.DAY);
- sbder.append(" }");
- } else if (typetag == ATypeTag.TIME.serialize()) {
- sbder.append("ATime: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalStart, 0, sbder,
- GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND);
- sbder.append(" }, ATime: { ");
+ try {
+ if (typetag == ATypeTag.DATE.serialize()) {
+ sbder.append("ADate: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalEnd, 0, sbder,
- GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND);
- sbder.append(" }");
- } else if (typetag == ATypeTag.DATETIME.serialize()) {
- sbder.append("ADateTime: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalStart, 0, sbder,
- GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND);
- sbder.append(" }, ADateTime: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(intervalEnd, 0, sbder,
- GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND);
- sbder.append(" }");
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(
+ intervalStart * ADate.CHRONON_OF_DAY, 0, sbder, GregorianCalendarSystem.Fields.YEAR,
+ GregorianCalendarSystem.Fields.DAY, false);
+
+ sbder.append(" }, ADate: {");
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalEnd * ADate.CHRONON_OF_DAY,
+ 0, sbder, GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.DAY, false);
+ sbder.append(" }");
+ } else if (typetag == ATypeTag.TIME.serialize()) {
+ sbder.append("ATime: { ");
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalStart, 0, sbder,
+ GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ sbder.append(" }, ATime: { ");
+
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalEnd, 0, sbder,
+ GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ sbder.append(" }");
+ } else if (typetag == ATypeTag.DATETIME.serialize()) {
+ sbder.append("ADateTime: { ");
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalStart, 0, sbder,
+ GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ sbder.append(" }, ADateTime: { ");
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(intervalEnd, 0, sbder,
+ GregorianCalendarSystem.Fields.YEAR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ sbder.append(" }");
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
sbder.append(" }");
return sbder.toString();
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
index b97ed51..edbf007 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/ATime.java
@@ -14,6 +14,8 @@
*/
package edu.uci.ics.asterix.om.base;
+import java.io.IOException;
+
import org.json.JSONException;
import org.json.JSONObject;
@@ -90,8 +92,12 @@
public String toString() {
StringBuilder sbder = new StringBuilder();
sbder.append("ATime: { ");
- GregorianCalendarSystem.getInstance().getExtendStringRepWithTimezoneUntilField(chrononTime, 0, sbder,
- GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND);
+ try {
+ GregorianCalendarSystem.getInstance().getExtendStringRepUntilField(chrononTime, 0, sbder,
+ GregorianCalendarSystem.Fields.HOUR, GregorianCalendarSystem.Fields.MILLISECOND, true);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
sbder.append(" }");
return sbder.toString();
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java
index 84e2386..90fc2bf 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ADurationParserFactory.java
@@ -248,18 +248,28 @@
throw new HyracksDataException(durationErrorMessage + ": no time fields after time separator.");
}
+ int totalMonths = sign * (year * 12 + month);
+ long totalMilliseconds = sign
+ * (day * 24L * 3600L * 1000L + 3600L * 1000L * hour + 60L * minute * 1000L + second * 1000L + millisecond);
+
+ if (sign > 0) {
+ if (totalMonths < 0) {
+ throw new HyracksDataException(durationErrorMessage
+ + ": total number of months is beyond its max value (-2147483647 to 2147483647).");
+ }
+ if (totalMilliseconds < 0) {
+ throw new HyracksDataException(
+ durationErrorMessage
+ + ": total number of milliseconds is beyond its max value (-9223372036854775808 to 9223372036854775807).");
+ }
+ }
+
if (mutableObject instanceof AMutableDuration) {
- ((AMutableDuration) mutableObject)
- .setValue(sign * (year * 12 + month),
- sign
- * (day * 24 * 3600 * 1000L + 3600 * 1000L * hour + 60 * minute * 1000L + second
- * 1000L + millisecond));
+ ((AMutableDuration) mutableObject).setValue(totalMonths, totalMilliseconds);
} else if (mutableObject instanceof AMutableYearMonthDuration) {
- ((AMutableYearMonthDuration) mutableObject).setMonths(sign * (year * 12 + month));
+ ((AMutableYearMonthDuration) mutableObject).setMonths(totalMonths);
} else if (mutableObject instanceof AMutableDayTimeDuration) {
- ((AMutableDayTimeDuration) mutableObject)
- .setMilliseconds(sign
- * (day * 24 * 3600 * 1000L + 3600 * 1000L * hour + 60 * minute * 1000L + second * 1000L + millisecond));
+ ((AMutableDayTimeDuration) mutableObject).setMilliseconds(totalMilliseconds);
}
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
index f74af9b..26293e9 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/GregorianCalendarSystem.java
@@ -30,6 +30,8 @@
*/
package edu.uci.ics.asterix.om.base.temporal;
+import java.io.IOException;
+
/**
* A simple implementation of the Gregorian calendar system.
* <p/>
@@ -268,8 +270,8 @@
* @param sbder
* @param untilField
*/
- public void getExtendStringRepWithTimezoneUntilField(long chrononTime, int timezone, StringBuilder sbder,
- Fields startField, Fields untilField) {
+ public void getExtendStringRepUntilField(long chrononTime, int timezone, Appendable sbder, Fields startField,
+ Fields untilField, boolean withTimezone) throws IOException {
int year = getYear(chrononTime);
int month = getMonthOfYear(chrononTime, year);
@@ -323,16 +325,18 @@
break;
}
- if (timezone == 0) {
- sbder.append("Z");
- } else {
- short tzMin = (short) ((timezone % 4) * 15);
- if (tzMin < 0) {
- tzMin = (short) (-1 * tzMin);
+ if (withTimezone) {
+ if (timezone == 0) {
+ sbder.append("Z");
+ } else {
+ short tzMin = (short) ((timezone % 4) * 15);
+ if (tzMin < 0) {
+ tzMin = (short) (-1 * tzMin);
+ }
+ short tzHr = (short) (timezone / 4);
+ sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr)))
+ .append(":").append(String.format("%02d", tzMin));
}
- short tzHr = (short) (timezone / 4);
- sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr))).append(":")
- .append(String.format("%02d", tzMin));
}
}
@@ -343,8 +347,8 @@
* @param timezone
* @param sbder
*/
- public void getBasicStringRepWithTimezoneUntilField(long chrononTime, int timezone, StringBuilder sbder,
- Fields startField, Fields untilField) {
+ public void getBasicStringRepUntilField(long chrononTime, int timezone, Appendable sbder, Fields startField,
+ Fields untilField, boolean withTimezone) throws IOException {
int year = getYear(chrononTime);
int month = getMonthOfYear(chrononTime, year);
@@ -382,16 +386,18 @@
break;
}
- if (timezone == 0) {
- sbder.append("Z");
- } else {
- short tzMin = (short) ((timezone % 4) * 15);
- if (tzMin < 0) {
- tzMin = (short) (-1 * tzMin);
+ if (withTimezone) {
+ if (timezone == 0) {
+ sbder.append("Z");
+ } else {
+ short tzMin = (short) ((timezone % 4) * 15);
+ if (tzMin < 0) {
+ tzMin = (short) (-1 * tzMin);
+ }
+ short tzHr = (short) (timezone / 4);
+ sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr)))
+ .append(String.format("%02d", tzMin));
}
- short tzHr = (short) (timezone / 4);
- sbder.append((tzHr >= 0 ? "+" : "-")).append(String.format("%02d", (tzHr < 0 ? -tzHr : tzHr)))
- .append(String.format("%02d", tzMin));
}
}
@@ -480,8 +486,7 @@
* Get the year for the given chronon time.
* <p/>
* This code is directly from the Joda library BadicChronology.java.<br/>
- * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May
- * 7th, 2012.
+ * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012.
*
* @param chrononTime
* @return
@@ -528,8 +533,7 @@
* Get the month of the year for the given chronon time and the year.
* <p/>
* This code is directly from the Joda library BasicGJChronology.java.<br/>
- * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May
- * 7th, 2012 and commented by Theodoros Ioannou on July 2012.
+ * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012 and commented by Theodoros Ioannou on July 2012.
* <p/>
*
* @param millis
@@ -593,8 +597,7 @@
* Get the day of the given month and year for the input chronon time.
* <p/>
* This function is directly from Joda Library BasicChronology.java.<br/>
- * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May
- * 7th, 2012.
+ * The original authers are Stephen Colebourne, Brain S O'Neill and Guy Allard, and modified by JArod Wen on May 7th, 2012.
* <p/>
*
* @param millis
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
index 441d20a..55b9663 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustDateTimeForTimeZoneDescriptor.java
@@ -120,8 +120,8 @@
StringBuilder sbder = new StringBuilder();
- calInstance.getExtendStringRepWithTimezoneUntilField(chronon, timezone, sbder, Fields.YEAR,
- Fields.MILLISECOND);
+ calInstance.getExtendStringRepUntilField(chronon, timezone, sbder, Fields.YEAR,
+ Fields.MILLISECOND, true);
out.writeByte(SER_STRING_TYPE_TAG);
out.writeUTF(sbder.toString());
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
index 1ca64c6..340545d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/AdjustTimeForTimeZoneDescriptor.java
@@ -120,8 +120,8 @@
StringBuilder sbder = new StringBuilder();
- calInstance.getExtendStringRepWithTimezoneUntilField(chronon, timezone, sbder, Fields.HOUR,
- Fields.MILLISECOND);
+ calInstance.getExtendStringRepUntilField(chronon, timezone, sbder, Fields.HOUR,
+ Fields.MILLISECOND, true);
out.writeByte(SER_STRING_TYPE_TAG);
out.writeUTF(sbder.toString());