addressed Sattam's comments on eliminating object creation and copy-and-paste code in the interval parser.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_temp_missing_tests@1341 eaa15691-b419-025a-1212-ee371bd00084
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 aadaac3..34c3a5b 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
@@ -36,7 +36,7 @@
@SuppressWarnings("unchecked")
private static final ISerializerDeserializer<ADateTime> datetimeSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ADATETIME);
-
+ private static final AMutableDateTime aDateTime = new AMutableDateTime(0L);
private static final String errorMessage = "This can not be an instance of datetime";
private ADateTimeSerializerDeserializer() {
@@ -61,7 +61,6 @@
}
public static void parse(String datetime, DataOutput out) throws HyracksDataException {
- AMutableDateTime aDateTime = new AMutableDateTime(0L);
long chrononTimeInMs = 0;
try {
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 2c38443..6930f60 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
@@ -20,6 +20,7 @@
@SuppressWarnings("unchecked")
private static final ISerializerDeserializer<ADuration> durationSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ADURATION);
+ private static final AMutableDuration aDuration = new AMutableDuration(0, 0);
private ADurationSerializerDeserializer() {
}
@@ -45,9 +46,7 @@
public static void parse(String duration, DataOutput out) throws HyracksDataException {
try {
- AMutableDuration aDuration = new AMutableDuration(0, 0);
ADurationParserFactory.parseDuration(duration, 0, duration.length(), aDuration);
-
durationSerde.serialize(aDuration, out);
} catch (Exception e) {
throw new HyracksDataException(e);
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 5156bf9..8c4def0 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
@@ -38,7 +38,7 @@
@SuppressWarnings("unchecked")
private static final ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.AINTERVAL);
-
+ private static final AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
private static final String errorMessage = "This can not be an instance of interval";
private AIntervalSerializerDeserializer() {
@@ -63,7 +63,6 @@
} catch (IOException e) {
throw new HyracksDataException(e);
}
-
}
public static long getIntervalStart(byte[] data, int offset) {
@@ -86,7 +85,6 @@
* @throws HyracksDataException
*/
public static void parseDatetime(String interval, DataOutput out) throws HyracksDataException {
- AMutableInterval aInterval = new AMutableInterval(0l, 0l, (byte) 0);
long chrononTimeInMsStart = 0;
long chrononTimeInMsEnd = 0;
@@ -104,58 +102,29 @@
endOffset = commaIndex - 1;
- while (interval.charAt(endOffset) == ' ') {
- endOffset--;
+ timeSeperatorOffsetInDatetimeString = interval.indexOf('T');
+
+ if (timeSeperatorOffsetInDatetimeString < 0) {
+ throw new AlgebricksException(errorMessage + ": missing T for a datetime value.");
}
- while (interval.charAt(startOffset) == '"' || interval.charAt(startOffset) == ' ') {
- startOffset++;
- }
+ chrononTimeInMsStart = parseDatePart(interval, startOffset, timeSeperatorOffsetInDatetimeString - 1);
- // +1 if it is negative (-)
- timeSeperatorOffsetInDatetimeString = ((interval.charAt(startOffset) == '-') ? 1 : 0);
-
- timeSeperatorOffsetInDatetimeString += 8;
-
- if (interval.charAt(startOffset + timeSeperatorOffsetInDatetimeString) != 'T') {
- timeSeperatorOffsetInDatetimeString += 2;
- if (interval.charAt(startOffset + timeSeperatorOffsetInDatetimeString) != 'T') {
- throw new AlgebricksException(errorMessage + ": missing T for a datetime value.");
- }
- }
-
- chrononTimeInMsStart = ADateParserFactory.parseDatePart(interval, startOffset, timeSeperatorOffsetInDatetimeString);
-
- chrononTimeInMsStart += ATimeParserFactory.parseTimePart(interval, startOffset + timeSeperatorOffsetInDatetimeString + 1, endOffset
- - (startOffset + timeSeperatorOffsetInDatetimeString + 1) + 1);
+ chrononTimeInMsStart += parseTimePart(interval, timeSeperatorOffsetInDatetimeString + 1, endOffset);
// Interval End
startOffset = commaIndex + 1;
endOffset = interval.length() - 1;
- while (interval.charAt(endOffset) == '"' || interval.charAt(endOffset) == ' ') {
- endOffset--;
+
+ timeSeperatorOffsetInDatetimeString = interval.indexOf('T', startOffset);
+
+ if (timeSeperatorOffsetInDatetimeString < 0) {
+ throw new AlgebricksException(errorMessage + ": missing T for a datetime value.");
}
- while (interval.charAt(startOffset) == ' ') {
- startOffset++;
- }
+ chrononTimeInMsEnd = parseDatePart(interval, startOffset, timeSeperatorOffsetInDatetimeString - 1);
- // +1 if it is negative (-)
- timeSeperatorOffsetInDatetimeString = ((interval.charAt(startOffset) == '-') ? 1 : 0);
-
- timeSeperatorOffsetInDatetimeString += 8;
-
- if (interval.charAt(startOffset + timeSeperatorOffsetInDatetimeString) != 'T') {
- timeSeperatorOffsetInDatetimeString += 2;
- if (interval.charAt(startOffset + timeSeperatorOffsetInDatetimeString) != 'T') {
- throw new AlgebricksException(errorMessage + ": missing T for a datetime value.");
- }
- }
-
- chrononTimeInMsEnd = ADateParserFactory.parseDatePart(interval, startOffset, timeSeperatorOffsetInDatetimeString);
-
- chrononTimeInMsEnd += ATimeParserFactory.parseTimePart(interval, startOffset + timeSeperatorOffsetInDatetimeString + 1, endOffset
- - (startOffset + timeSeperatorOffsetInDatetimeString + 1) + 1);
+ chrononTimeInMsEnd += parseTimePart(interval, timeSeperatorOffsetInDatetimeString + 1, endOffset);
} catch (Exception e) {
throw new HyracksDataException(e);
}
@@ -166,7 +135,6 @@
}
public static void parseTime(String interval, DataOutput out) throws HyracksDataException {
- AMutableInterval aInterval = new AMutableInterval(0l, 0l, (byte) 0);
long chrononTimeInMsStart = 0;
long chrononTimeInMsEnd = 0;
@@ -183,16 +151,8 @@
endOffset = commaIndex - 1;
- while (interval.charAt(endOffset) == ' ') {
- endOffset--;
- }
-
- while (interval.charAt(startOffset) == '"' || interval.charAt(startOffset) == ' ') {
- startOffset++;
- }
-
// Interval Start
- chrononTimeInMsStart = ATimeParserFactory.parseTimePart(interval, startOffset, endOffset - startOffset + 1);
+ chrononTimeInMsStart = parseTimePart(interval, startOffset, endOffset);
if (chrononTimeInMsStart < 0) {
chrononTimeInMsStart += GregorianCalendarSystem.CHRONON_OF_DAY;
@@ -200,17 +160,9 @@
// Interval End
startOffset = commaIndex + 1;
- while (interval.charAt(startOffset) == ' ') {
- startOffset++;
- }
-
endOffset = interval.length() - 1;
- while (interval.charAt(endOffset) == '"' || interval.charAt(endOffset) == ' ') {
- endOffset--;
- }
-
- chrononTimeInMsEnd = ATimeParserFactory.parseTimePart(interval, startOffset, endOffset - startOffset + 1);
+ chrononTimeInMsEnd = parseTimePart(interval, startOffset, endOffset);
if (chrononTimeInMsEnd < 0) {
chrononTimeInMsEnd += GregorianCalendarSystem.CHRONON_OF_DAY;
@@ -225,12 +177,9 @@
}
public static void parseDate(String interval, DataOutput out) throws HyracksDataException {
- AMutableInterval aInterval = new AMutableInterval(0l, 0l, (byte) 0);
long chrononTimeInMsStart = 0;
long chrononTimeInMsEnd = 0;
- short tempStart = 0;
- short tempEnd = 0;
try {
// the starting point for parsing (so for the accessor)
@@ -245,37 +194,50 @@
endOffset = commaIndex - 1;
- while (interval.charAt(endOffset) == ' ') {
- endOffset--;
- }
-
- while (interval.charAt(startOffset) == '"' || interval.charAt(startOffset) == ' ') {
- startOffset++;
- }
-
- chrononTimeInMsStart = ADateParserFactory.parseDatePart(interval, startOffset, endOffset - startOffset + 1);
+ chrononTimeInMsStart = parseDatePart(interval, startOffset, endOffset);
// Interval End
startOffset = commaIndex + 1;
endOffset = interval.length() - 1;
- while (interval.charAt(endOffset) == '"' || interval.charAt(endOffset) == ' ') {
- endOffset--;
- }
- while (interval.charAt(startOffset) == ' ') {
- startOffset++;
- }
-
- chrononTimeInMsEnd = ADateParserFactory.parseDatePart(interval, startOffset, endOffset - startOffset + 1);
+ chrononTimeInMsEnd = parseDatePart(interval, startOffset, endOffset);
} catch (Exception e) {
throw new HyracksDataException(e);
}
- aInterval.setValue((chrononTimeInMsStart / GregorianCalendarSystem.CHRONON_OF_DAY) - tempStart,
- (chrononTimeInMsEnd / GregorianCalendarSystem.CHRONON_OF_DAY) - tempEnd, ATypeTag.DATE.serialize());
+ aInterval.setValue((chrononTimeInMsStart / GregorianCalendarSystem.CHRONON_OF_DAY),
+ (chrononTimeInMsEnd / GregorianCalendarSystem.CHRONON_OF_DAY), ATypeTag.DATE.serialize());
intervalSerde.serialize(aInterval, out);
}
+ private static long parseDatePart(String interval, int startOffset, int endOffset) throws AlgebricksException,
+ HyracksDataException {
+
+ while (interval.charAt(endOffset) == '"' || interval.charAt(endOffset) == ' ') {
+ endOffset--;
+ }
+
+ while (interval.charAt(startOffset) == '"' || interval.charAt(startOffset) == ' ') {
+ startOffset++;
+ }
+
+ return ADateParserFactory.parseDatePart(interval, startOffset, endOffset - startOffset + 1);
+ }
+
+ private static int parseTimePart(String interval, int startOffset, int endOffset) throws AlgebricksException,
+ HyracksDataException {
+
+ while (interval.charAt(endOffset) == '"' || interval.charAt(endOffset) == ' ') {
+ endOffset--;
+ }
+
+ while (interval.charAt(startOffset) == '"' || interval.charAt(startOffset) == ' ') {
+ startOffset++;
+ }
+
+ return ATimeParserFactory.parseTimePart(interval, startOffset, endOffset - startOffset + 1);
+ }
+
}
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 78baeed..8c3134a 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
@@ -21,7 +21,8 @@
@SuppressWarnings("unchecked")
private static final ISerializerDeserializer<ATime> timeSerde = AqlSerializerDeserializerProvider.INSTANCE
.getSerializerDeserializer(BuiltinType.ATIME);
-
+ private static final AMutableTime aTime = new AMutableTime(0);
+
private ATimeSerializerDeserializer() {
}
@@ -46,7 +47,6 @@
}
public static void parse(String time, DataOutput out) throws HyracksDataException {
- AMutableTime aTime = new AMutableTime(0);
int chrononTimeInMs;
try {
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ATimeParserFactory.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ATimeParserFactory.java
index 4c4e3fa..c0f0957 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ATimeParserFactory.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/base/temporal/ATimeParserFactory.java
@@ -58,7 +58,7 @@
* @return
* @throws HyracksDataException
*/
- public static <T> int parseTimePart(String timeString, int start, int length) throws HyracksDataException {
+ public static int parseTimePart(String timeString, int start, int length) throws HyracksDataException {
int offset = 0;
@@ -162,7 +162,7 @@
* @return
* @throws HyracksDataException
*/
- public static <T> int parseTimezonePart(String timeString, int start) throws HyracksDataException {
+ public static int parseTimezonePart(String timeString, int start) throws HyracksDataException {
int timezone = 0;
if (timeString.charAt(start) != 'Z') {
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 275bf47..21d098a 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
@@ -108,9 +108,6 @@
+ argOut1.getByteArray()[0]);
}
- int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
- + (argOut1.getByteArray()[2] & 0xff << 0);
-
int timezone = ATimeParserFactory.parseTimezonePart(argOut1.getByteArray(), 3);
if (!calInstance.validateTimeZone(timezone)) {
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 3f40c5c..1f8842e 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
@@ -108,9 +108,6 @@
+ argOut1.getByteArray()[0]);
}
- int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
- + (argOut0.getByteArray()[2] & 0xff << 0);
-
int timezone = ATimeParserFactory.parseTimezonePart(argOut1.getByteArray(), 3);
if (!calInstance.validateTimeZone(timezone)) {