updated char and byte array accessors to prepare for interval importing code.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_temporal_functionality@864 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/data/temporal/temporalData.json b/asterix-app/data/temporal/temporalData.json
index ae100f7..b866a51 100644
--- a/asterix-app/data/temporal/temporalData.json
+++ b/asterix-app/data/temporal/temporalData.json
@@ -1,2 +1,3 @@
-{"id": "001", "dateField": -2012-12-12, "dateFieldPlus": 0990-01-01, "timeField": 23:49:12.39Z, "timeFieldPlus": 03:23:12.2, "datetimeField": 2012-12-12T00:00:00.001, "datetimeFieldPlus": -00130810T221015398, "durationField": P20Y19DT3H74M23.34S, "durationFieldPlus": -P2MT4M300.68S}
-{"id": "002", "datetimeField": 19201220T232918478 }
\ No newline at end of file
+{"id": "001", "dateField": -2012-12-12, "dateFieldPlus": 0990-01-01, "timeField": 23:49:12.39Z, "timeFieldPlus": 03:23:12.2, "datetimeField": 2012-12-12T00:00:00.001, "datetimeFieldPlus": -00130810T221015398, "durationField": P20Y19DT3H74M23.34S, "durationFieldPlus": -P2MT4M300.68S, "intervalField": I(2012-12-12T00:00:00.001,20130810T221015398) }
+{"id": "002", "datetimeField": 19201220T232918478 }
+{"id": "003", "intervalPlus": I(19:23:32.328Z,23:20:20) }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/temp/insert_from_ext_ds.aql b/asterix-app/src/test/resources/runtimets/queries/temp/insert_from_ext_ds.aql
index c816047..5813696 100644
--- a/asterix-app/src/test/resources/runtimets/queries/temp/insert_from_ext_ds.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/temp/insert_from_ext_ds.aql
@@ -13,7 +13,8 @@
dateField: date?,
timeField: time?,
datetimeField: datetime?,
- durationField: duration?
+ durationField: duration?,
+ intervalField: interval?
}
write output to nc1:"rttest/temp_insert_from_ext_ds.adm";
@@ -23,4 +24,4 @@
(("path"="nc1://data/temporal/temporalData.json"),("format"="adm"));
for $r in dataset("testds")
-return {"date": $r.dateField, "time": $r.timeField, "datetime": $r.datetimeField, "duration": $r.durationField}
\ No newline at end of file
+return {"date": $r.dateField, "time": $r.timeField, "datetime": $r.datetimeField, "duration": $r.durationField, "interval": $r.intervalField }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/temp/insert_from_ext_ds.adm b/asterix-app/src/test/resources/runtimets/results/temp/insert_from_ext_ds.adm
index 00bfc1b..afe2ccc 100644
--- a/asterix-app/src/test/resources/runtimets/results/temp/insert_from_ext_ds.adm
+++ b/asterix-app/src/test/resources/runtimets/results/temp/insert_from_ext_ds.adm
@@ -1,2 +1,3 @@
-{ "date": date("-2012-12-12"), "time": time("23:49:12.390Z"), "datetime": datetime("2012-12-12T00:00:00.001Z"), "duration": duration("P20Y19DT4H14M23.34S") }
-{ "date": null, "time": null, "datetime": datetime("1920-12-20T23:29:18.478Z"), "duration": null }
\ No newline at end of file
+{ "date": date("-2012-12-12"), "time": time("23:49:12.390Z"), "datetime": datetime("2012-12-12T00:00:00.001Z"), "duration": duration("P20Y19DT4H14M23.34S"), "interval": interval("datetime("2012-12-12T00:00:00.001Z"), datetime("2013-08-10T22:10:15.398Z")") }
+{ "date": null, "time": null, "datetime": datetime("1920-12-20T23:29:18.478Z"), "duration": null, "interval": null }
+{ "date": null, "time": null, "datetime": null, "duration": null, "interval": null }
\ No newline at end of file
diff --git a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/AsterixBuiltinTypeMap.java b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/AsterixBuiltinTypeMap.java
index 734237e..27cf542 100644
--- a/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/AsterixBuiltinTypeMap.java
+++ b/asterix-metadata/src/main/java/edu/uci/ics/asterix/metadata/entities/AsterixBuiltinTypeMap.java
@@ -40,6 +40,7 @@
_builtinTypeMap.put("time", BuiltinType.ATIME);
_builtinTypeMap.put("datetime", BuiltinType.ADATETIME);
_builtinTypeMap.put("duration", BuiltinType.ADURATION);
+ _builtinTypeMap.put("interval", BuiltinType.AINTERVAL);
_builtinTypeMap.put("point", BuiltinType.APOINT);
_builtinTypeMap.put("point3d", BuiltinType.APOINT3D);
_builtinTypeMap.put("line", BuiltinType.ALINE);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java
index 70ba225..91c4587 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateSerializerDeserializer.java
@@ -64,7 +64,7 @@
long chrononTimeInMs = 0;
try {
StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
- charAccessor.reset(date, 0);
+ charAccessor.reset(date, 0, date.length());
chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, true);
} catch (Exception e) {
throw new HyracksDataException(e);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java
index 3f652c2..4a40198 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADateTimeSerializerDeserializer.java
@@ -66,7 +66,7 @@
long chrononTimeInMs = 0;
try {
StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
- charAccessor.reset(datetime, 0);
+ charAccessor.reset(datetime, 0, datetime.length());
// +1 if it is negative (-)
short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
@@ -80,7 +80,7 @@
chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, false);
- charAccessor.reset(datetime, timeOffset);
+ charAccessor.reset(datetime, timeOffset, datetime.length() - timeOffset);
chrononTimeInMs += ADateAndTimeParser.parseTimePart(charAccessor);
} catch (Exception e) {
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java
index 2aa68a2..5390abe 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ADurationSerializerDeserializer.java
@@ -48,7 +48,7 @@
try {
AMutableDuration aDuration = new AMutableDuration(0, 0);
StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
- charAccessor.reset(duration, 0);
+ charAccessor.reset(duration, 0, duration.length());
ADurationParser.parse(charAccessor, aDuration);
durationSerde.serialize(aDuration, out);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
index 3fb4fa8..61d17c1 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
@@ -78,6 +78,13 @@
return data[offset + 8 * 2];
}
+ /**
+ * create an interval value from two given datetime instance.
+ *
+ * @param interval
+ * @param out
+ * @throws HyracksDataException
+ */
public static void parseDatetime(String interval, DataOutput out) throws HyracksDataException {
AMutableInterval aInterval = new AMutableInterval(0l, 0l, (byte) 0);
@@ -87,8 +94,19 @@
StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
- //Interval Start
- charAccessor.reset(interval, 0);
+ // Get the index for the comma
+ int commaIndex = interval.indexOf(',');
+ if (commaIndex < 0) {
+ throw new AlgebricksException("comma is missing for a string of interval");
+ }
+
+ int nonSpaceIndex = commaIndex - 1;
+ while (interval.charAt(nonSpaceIndex) == ' ') {
+ nonSpaceIndex--;
+ }
+
+ // Interval Start
+ charAccessor.reset(interval, 0, nonSpaceIndex + 1);
// +1 if it is negative (-)
short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
@@ -102,33 +120,17 @@
chrononTimeInMsStart = ADateAndTimeParser.parseDatePart(charAccessor, false);
- charAccessor.reset(interval, timeOffset);
+ charAccessor.reset(interval, timeOffset, nonSpaceIndex - timeOffset + 1);
chrononTimeInMsStart += ADateAndTimeParser.parseTimePart(charAccessor);
- //Interval End
- charAccessor.reset(interval, 0);
-
- // Find the comma in the expression
- int commaSkipIndex = 0;
- int length = charAccessor.getLength();
- for (; length > commaSkipIndex && charAccessor.getCharAt(commaSkipIndex) != ','; commaSkipIndex++) {
+ // Interval End
+ nonSpaceIndex = commaIndex + 1;
+ while (interval.charAt(nonSpaceIndex) == ' ') {
+ nonSpaceIndex++;
}
- if (length <= commaSkipIndex) {
- throw new AlgebricksException(errorMessage + ": comma is missing");
- }
- commaSkipIndex++;
-
- // Skip any possible spaces (' ')
- for (; length > commaSkipIndex && charAccessor.getCharAt(commaSkipIndex) != ' '; commaSkipIndex++) {
- }
-
- if (length <= commaSkipIndex) {
- // TODO: Maybe remove this error and combine with the previous one
- throw new AlgebricksException(errorMessage + ": error while skipping spaces");
- }
- charAccessor.reset(interval, commaSkipIndex);
+ charAccessor.reset(interval, nonSpaceIndex, interval.length() - nonSpaceIndex);
// +1 if it is negative (-)
timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
@@ -142,7 +144,7 @@
chrononTimeInMsEnd = ADateAndTimeParser.parseDatePart(charAccessor, false);
- charAccessor.reset(interval, commaSkipIndex + timeOffset);
+ charAccessor.reset(interval, nonSpaceIndex + timeOffset, interval.length() - nonSpaceIndex - timeOffset);
chrononTimeInMsEnd += ADateAndTimeParser.parseTimePart(charAccessor);
@@ -164,34 +166,32 @@
StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
- //Interval Start
- charAccessor.reset(interval, 0);
+ // Get the index for the comma
+ int commaIndex = interval.indexOf(',');
+ if (commaIndex < 0) {
+ throw new AlgebricksException("comma is missing for a string of interval");
+ }
+
+ int nonSpaceIndex = commaIndex - 1;
+ while (interval.charAt(nonSpaceIndex) == ' ') {
+ nonSpaceIndex--;
+ }
+
+ // Interval Start
+ charAccessor.reset(interval, 0, nonSpaceIndex + 1);
chrononTimeInMsStart = ADateAndTimeParser.parseTimePart(charAccessor);
if (chrononTimeInMsStart < 0) {
chrononTimeInMsStart += GregorianCalendarSystem.CHRONON_OF_DAY;
}
- //Interval End
- int commaSkipIndex = 0;
- int length = charAccessor.getLength();
- for (; length > commaSkipIndex && charAccessor.getCharAt(commaSkipIndex) != ','; commaSkipIndex++) {
+ // Interval End
+ nonSpaceIndex = commaIndex + 1;
+ while (interval.charAt(nonSpaceIndex) == ' ') {
+ nonSpaceIndex++;
}
- if (length <= commaSkipIndex) {
- throw new AlgebricksException(errorMessage + ": comma is missing");
- }
- commaSkipIndex++;
-
- // Skip any possible spaces (' ')
- for (; length > commaSkipIndex && charAccessor.getCharAt(commaSkipIndex) != ' '; commaSkipIndex++) {
- }
-
- if (length <= commaSkipIndex) {
- // TODO: Maybe remove this error and combine with the previous one
- throw new AlgebricksException(errorMessage + ": error while skipping spaces");
- }
- charAccessor.reset(interval, commaSkipIndex);
+ charAccessor.reset(interval, nonSpaceIndex, interval.length() - nonSpaceIndex);
chrononTimeInMsEnd = ADateAndTimeParser.parseTimePart(charAccessor);
if (chrononTimeInMsEnd < 0) {
@@ -216,8 +216,19 @@
try {
StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
- //Interval Start
- charAccessor.reset(interval, 0);
+ // Get the index for the comma
+ int commaIndex = interval.indexOf(',');
+ if (commaIndex < 0) {
+ throw new AlgebricksException("comma is missing for a string of interval");
+ }
+
+ int nonSpaceIndex = commaIndex - 1;
+ while (interval.charAt(nonSpaceIndex) == ' ') {
+ nonSpaceIndex--;
+ }
+
+ // Interval Start
+ charAccessor.reset(interval, 0, nonSpaceIndex + 1);
chrononTimeInMsStart = ADateAndTimeParser.parseDatePart(charAccessor, true);
@@ -225,26 +236,13 @@
tempStart = 1;
}
- //Interval End
- int commaSkipIndex = 0;
- int length = charAccessor.getLength();
- for (; length > commaSkipIndex && charAccessor.getCharAt(commaSkipIndex) != ','; commaSkipIndex++) {
+ // Interval End
+ nonSpaceIndex = commaIndex + 1;
+ while (interval.charAt(nonSpaceIndex) == ' ') {
+ nonSpaceIndex++;
}
- if (length <= commaSkipIndex) {
- throw new AlgebricksException(errorMessage + ": comma is missing");
- }
- commaSkipIndex++;
-
- // Skip any possible spaces (' ')
- for (; length > commaSkipIndex && charAccessor.getCharAt(commaSkipIndex) != ' '; commaSkipIndex++) {
- }
-
- if (length <= commaSkipIndex) {
- // TODO: Maybe remove this error and combine with the previous one
- throw new AlgebricksException(errorMessage + ": error while skipping spaces");
- }
- charAccessor.reset(interval, commaSkipIndex);
+ charAccessor.reset(interval, nonSpaceIndex, interval.length() - nonSpaceIndex);
chrononTimeInMsEnd = ADateAndTimeParser.parseDatePart(charAccessor, true);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java
index c640e80..92f32b8 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ATimeSerializerDeserializer.java
@@ -52,7 +52,7 @@
try {
StringCharSequenceAccessor charAccessor = new StringCharSequenceAccessor();
- charAccessor.reset(time, 0);
+ charAccessor.reset(time, 0, time.length());
chrononTimeInMs = ADateAndTimeParser.parseTimePart(charAccessor);
} catch (Exception e) {
throw new HyracksDataException(e);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ByteArrayCharSequenceAccessor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ByteArrayCharSequenceAccessor.java
index 50d4d1a..453c86f 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ByteArrayCharSequenceAccessor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ByteArrayCharSequenceAccessor.java
@@ -14,15 +14,20 @@
*/
package edu.uci.ics.asterix.om.base.temporal;
+import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
+
public class ByteArrayCharSequenceAccessor implements ICharSequenceAccessor<Byte[]> {
- private byte[] string;
+ private byte[] buf;
private int offset;
- private int beginOffset;
+ private int length;
@Override
- public char getCharAt(int index) {
- return (char) (string[index + offset + beginOffset]);
+ public char getCharAt(int index) throws AsterixRuntimeException {
+ if (index < 0 || index >= length) {
+ throw new AsterixRuntimeException("Byte array char accessor is out of bound: " + index + ":" + length);
+ }
+ return (char) (buf[index + offset]);
}
/**
@@ -35,15 +40,15 @@
* @param offset
* The offset of the substring of the string stored (offset from the beginOffset).
*/
- public void reset(byte[] obj, int beginOffset, int offset) {
- string = obj;
+ public void reset(byte[] obj, int offset, int length) {
+ this.buf = obj;
this.offset = offset;
- this.beginOffset = beginOffset;
+ this.length = length;
}
@Override
public int getLength() {
- return ((string[beginOffset - 2] & 0xff) << 8) + ((string[beginOffset - 1] & 0xff) << 0) - offset;
+ return length;
}
}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICharSequenceAccessor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICharSequenceAccessor.java
index c475523..d5a99a0 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICharSequenceAccessor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ICharSequenceAccessor.java
@@ -14,6 +14,8 @@
*/
package edu.uci.ics.asterix.om.base.temporal;
+import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
+
public interface ICharSequenceAccessor<T> {
/**
@@ -22,7 +24,7 @@
* @param index
* @return
*/
- public char getCharAt(int index);
+ public char getCharAt(int index) throws AsterixRuntimeException;
/**
* Get the length of the wrapped char sequence.
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/StringCharSequenceAccessor.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/StringCharSequenceAccessor.java
index 6c02340..17e483a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/StringCharSequenceAccessor.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/StringCharSequenceAccessor.java
@@ -14,24 +14,31 @@
*/
package edu.uci.ics.asterix.om.base.temporal;
+import edu.uci.ics.asterix.common.exceptions.AsterixRuntimeException;
+
public class StringCharSequenceAccessor implements ICharSequenceAccessor<String> {
private String string;
private int offset;
+ private int length;
@Override
- public char getCharAt(int index) {
+ public char getCharAt(int index) throws AsterixRuntimeException {
+ if (index >= length) {
+ throw new AsterixRuntimeException("String accessor is out of bound.");
+ }
return string.charAt(index + offset);
}
- public void reset(String obj, int offset) {
- string = obj;
+ public void reset(String obj, int offset, int len) {
+ this.string = obj;
this.offset = offset;
+ this.length = len;
}
@Override
public int getLength() {
- return string.length() - offset;
+ return length;
}
}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
index 19c9d94..d6e3303 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
@@ -85,7 +85,9 @@
byte[] serString = outInput.getByteArray();
if (serString[0] == SER_STRING_TYPE_TAG) {
- charAccessor.reset(serString, 3, 0);
+ int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+
+ charAccessor.reset(serString, 3, stringLength);
long chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, true);
short temp = 0;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
index 93ad162..abbe033 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
@@ -82,7 +82,10 @@
eval.evaluate(tuple);
byte[] serString = outInput.getByteArray();
if (serString[0] == SER_STRING_TYPE_TAG) {
- charAccessor.reset(serString, 3, 0);
+
+ int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+
+ charAccessor.reset(serString, 3, stringLength);
// +1 if it is negative (-)
short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
@@ -98,7 +101,7 @@
long chrononTimeInMs = ADateAndTimeParser.parseDatePart(charAccessor, false);
- charAccessor.reset(serString, 3, timeOffset);
+ charAccessor.reset(serString, 3 + timeOffset, stringLength - timeOffset);
chrononTimeInMs += ADateAndTimeParser.parseTimePart(charAccessor);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
index 977bee1..93c6c15 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADurationConstructorDescriptor.java
@@ -84,7 +84,9 @@
if (serString[0] == SER_STRING_TYPE_TAG) {
- charAccessor.reset(serString, 3, 0);
+ int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+
+ charAccessor.reset(serString, 3, stringLength);
ADurationParser.parse(charAccessor, aDuration);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
index dcba2e0..d98b1bc 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
@@ -95,12 +95,20 @@
nullSerde.serialize(ANull.NULL, out);
} else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
&& argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
+
+ int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
+ + (argOut0.getByteArray()[2] & 0xff << 0);
+
// start date
- charAccessor.reset(argOut0.getByteArray(), 3, 0);
+ charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
long intervalStart = ADateAndTimeParser.parseDatePart(charAccessor, true)
/ GregorianCalendarSystem.CHRONON_OF_DAY;
// end date
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+
+ stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
+ + (argOut1.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
long intervalEnd = ADateAndTimeParser.parseDatePart(charAccessor, true)
/ GregorianCalendarSystem.CHRONON_OF_DAY;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
index b8c6a72..dbc14ea 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
@@ -95,7 +95,11 @@
} else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
&& argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
// start date
- charAccessor.reset(argOut0.getByteArray(), 3, 0);
+
+ int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
+ + (argOut0.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
// get offset for time part: +1 if it is negative (-)
short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
@@ -108,11 +112,15 @@
timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
: (short) (9);
long intervalStart = ADateAndTimeParser.parseDatePart(charAccessor, false);
- charAccessor.reset(argOut0.getByteArray(), 3, timeOffset);
+ charAccessor.reset(argOut0.getByteArray(), 3 + timeOffset, stringLength - timeOffset);
intervalStart += ADateAndTimeParser.parseTimePart(charAccessor);
// end date
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+
+ stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
+ + (argOut1.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
// get offset for time part: +1 if it is negative (-)
timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
@@ -125,7 +133,7 @@
timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
: (short) (9);
long intervalEnd = ADateAndTimeParser.parseDatePart(charAccessor, false);
- charAccessor.reset(argOut1.getByteArray(), 3, timeOffset);
+ charAccessor.reset(argOut1.getByteArray(), 3 + timeOffset, stringLength - timeOffset);
intervalEnd += ADateAndTimeParser.parseTimePart(charAccessor);
if (intervalEnd < intervalStart) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
index dfa97c3..36fed9a 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
@@ -96,14 +96,22 @@
} else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
&& argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
// start date
- charAccessor.reset(argOut0.getByteArray(), 3, 0);
+
+ int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
+ + (argOut0.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
long intervalStart = ADateAndTimeParser.parseTimePart(charAccessor);
if (intervalStart < 0) {
intervalStart += GregorianCalendarSystem.CHRONON_OF_DAY;
}
// end date
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+
+ stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
+ + (argOut1.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
long intervalEnd = ADateAndTimeParser.parseTimePart(charAccessor);
if (intervalEnd < 0) {
intervalEnd += GregorianCalendarSystem.CHRONON_OF_DAY;
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
index 50fab30..806fca6 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
@@ -100,10 +100,18 @@
} else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
&& argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
// start date
- charAccessor.reset(argOut0.getByteArray(), 3, 0);
+
+ int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
+ + (argOut0.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
long intervalStart = ADateAndTimeParser.parseDatePart(charAccessor, true);
// duration
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+
+ stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
+ + (argOut1.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
ADurationParser.parse(charAccessor, aDuration);
long intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
index 940cead..79e68a2 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
@@ -99,7 +99,11 @@
} else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
&& argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
// start date
- charAccessor.reset(argOut0.getByteArray(), 3, 0);
+
+ int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
+ + (argOut0.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
// get offset for time part: +1 if it is negative (-)
short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
@@ -112,11 +116,15 @@
timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
: (short) (9);
long intervalStart = ADateAndTimeParser.parseDatePart(charAccessor, false);
- charAccessor.reset(argOut0.getByteArray(), 3, timeOffset);
+ charAccessor.reset(argOut0.getByteArray(), 3 + timeOffset, stringLength - timeOffset);
intervalStart += ADateAndTimeParser.parseTimePart(charAccessor);
// duration
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+
+ stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
+ + (argOut1.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
ADurationParser.parse(charAccessor, aDuration);
long intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
index 09b3b7b..3bdf15e 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
@@ -100,7 +100,11 @@
} else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
&& argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
// start time
- charAccessor.reset(argOut0.getByteArray(), 3, 0);
+
+ int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
+ + (argOut0.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
int intervalStart = ADateAndTimeParser.parseTimePart(charAccessor);
if (intervalStart < 0) {
@@ -108,7 +112,11 @@
}
// duration
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+
+ stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
+ + (argOut1.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
ADurationParser.parse(charAccessor, aDuration);
if (aDuration.getMonths() != 0) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
index b60ac60..0e5fe8d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ATimeConstructorDescriptor.java
@@ -84,7 +84,10 @@
eval.evaluate(tuple);
byte[] serString = outInput.getByteArray();
if (serString[0] == SER_STRING_TYPE_TAG) {
- charAccessor.reset(serString, 3, 0);
+
+ int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
+
+ charAccessor.reset(serString, 3, stringLength);
int chrononTimeInMs = ADateAndTimeParser.parseTimePart(charAccessor);
if (chrononTimeInMs < 0) {
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 72b3baa..5449af2 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
@@ -112,7 +112,10 @@
+ argOut1.getByteArray()[0]);
}
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+ int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
+ + (argOut1.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
int timezone = ADateAndTimeParser.parseTimezonePart(charAccessor, 0);
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 29fbe65..1c6e838 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
@@ -112,7 +112,10 @@
+ argOut1.getByteArray()[0]);
}
- charAccessor.reset(argOut1.getByteArray(), 3, 0);
+ int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
+ + (argOut0.getByteArray()[2] & 0xff << 0);
+
+ charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
int timezone = ADateAndTimeParser.parseTimezonePart(charAccessor, 0);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/AdmSchemafullRecordParserFactory.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/AdmSchemafullRecordParserFactory.java
index d7714dc..3093c98 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/AdmSchemafullRecordParserFactory.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/AdmSchemafullRecordParserFactory.java
@@ -24,6 +24,7 @@
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ALineSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APoint3DSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.APointSerializerDeserializer;
@@ -322,6 +323,22 @@
parseDuration(token.image, out);
break;
}
+ case AdmLexerConstants.INTERVAL_CONS: {
+ parseConstructor(ATypeTag.INTERVAL, objectType, out);
+ break;
+ }
+ case AdmLexerConstants.TIME_INTERVAL_LITERAL: {
+ parseTimeInterval(token.image.substring(2, token.image.length() - 1), out);
+ break;
+ }
+ case AdmLexerConstants.DATE_INTERVAL_LITERAL: {
+ parseDateInterval(token.image.substring(2, token.image.length() - 1), out);
+ break;
+ }
+ case AdmLexerConstants.DATETIME_INTERVAL_LITERAL: {
+ parseDatetimeInterval(token.image.substring(2, token.image.length() - 1), out);
+ break;
+ }
case AdmLexerConstants.POINT_CONS: {
parseConstructor(ATypeTag.POINT, objectType, out);
break;
@@ -689,7 +706,30 @@
} catch (HyracksDataException e) {
throw new AsterixException(e);
}
+ }
+ private void parseTimeInterval(String timeInterval, DataOutput out) throws AsterixException {
+ try {
+ AIntervalSerializerDeserializer.parseTime(timeInterval, out);
+ } catch (HyracksDataException e) {
+ throw new AsterixException(e);
+ }
+ }
+
+ private void parseDateInterval(String dateInterval, DataOutput out) throws AsterixException {
+ try {
+ AIntervalSerializerDeserializer.parseDate(dateInterval, out);
+ } catch (HyracksDataException e) {
+ throw new AsterixException(e);
+ }
+ }
+
+ private void parseDatetimeInterval(String datetimeInterval, DataOutput out) throws AsterixException {
+ try {
+ AIntervalSerializerDeserializer.parseDatetime(datetimeInterval, out);
+ } catch (HyracksDataException e) {
+ throw new AsterixException(e);
+ }
}
private IAType getComplexType(IAType aObjectType, ATypeTag tag) {
diff --git a/asterix-runtime/src/main/javacc/nontagged/AdmLexer.jj b/asterix-runtime/src/main/javacc/nontagged/AdmLexer.jj
index 9d9f3ff..b52f346 100644
--- a/asterix-runtime/src/main/javacc/nontagged/AdmLexer.jj
+++ b/asterix-runtime/src/main/javacc/nontagged/AdmLexer.jj
@@ -197,6 +197,28 @@
<DEFAULT>
TOKEN :
+{
<INTERVAL_CONS : ("interval")>
+}
+
+<DEFAULT>
+TOKEN :
+{
<DATE_INTERVAL_LITERAL : ("I") "(" <DATE_LITERAL> "," <DATE_LITERAL> ")" >
+}
+
+<DEFAULT>
+TOKEN :
+{
+ <TIME_INTERVAL_LITERAL : ("I") "(" <TIME_LITERAL> "," <TIME_LITERAL> ")" >
+}
+
+<DEFAULT>
+TOKEN :
+{
+ <DATETIME_INTERVAL_LITERAL : ("I") "(" <DATETIME_LITERAL> "," <DATETIME_LITERAL> ")" >
+}
+
+<DEFAULT>
+TOKEN :
{
<#DIGIT : ["0" - "9"]>
}