asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject [2/4] incubator-asterixdb git commit: ASTERIXDB-1281 - Interval format update to AQL and ADM
Date Wed, 03 Feb 2016 16:34:11 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java b/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
index 20b4124..b10b9e9 100644
--- a/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
+++ b/asterix-external-data/src/main/java/org/apache/asterix/external/parser/AbstractDataParser.java
@@ -71,7 +71,6 @@ import org.apache.asterix.om.base.temporal.ADurationParserFactory;
 import org.apache.asterix.om.base.temporal.ADurationParserFactory.ADurationParseOption;
 import org.apache.asterix.om.base.temporal.ATimeParserFactory;
 import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
-import org.apache.asterix.om.types.ATypeTag;
 import org.apache.asterix.om.types.BuiltinType;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -187,7 +186,7 @@ public abstract class AbstractDataParser implements IDataParser {
     protected final static ISerializerDeserializer<ALine> lineSerde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.ALINE);
     @SuppressWarnings("unchecked")
-    private static final ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
+    protected static final ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
             .getSerializerDeserializer(BuiltinType.AINTERVAL);
 
     protected String filename;
@@ -333,104 +332,7 @@ public abstract class AbstractDataParser implements IDataParser {
         binarySerde.serialize(aBinary, out);
     }
 
-    protected void parseDateTimeInterval(String interval, DataOutput out) throws HyracksDataException {
-        // the starting point for parsing (so for the accessor)
-        int startOffset = 0;
-        int endOffset, timeSeperatorOffsetInDatetimeString;
-
-        // Get the index for the comma
-        int commaIndex = interval.indexOf(',');
-        if (commaIndex < 1) {
-            throw new HyracksDataException("comma is missing for a string of interval");
-        }
-
-        endOffset = commaIndex - 1;
-        timeSeperatorOffsetInDatetimeString = interval.indexOf('T');
-
-        if (timeSeperatorOffsetInDatetimeString < 0) {
-            throw new HyracksDataException("This can not be an instance of interval: missing T for a datetime value.");
-        }
-
-        long chrononTimeInMsStart = parseDatePart(interval, startOffset, timeSeperatorOffsetInDatetimeString - 1);
-
-        chrononTimeInMsStart += parseTimePart(interval, timeSeperatorOffsetInDatetimeString + 1, endOffset);
-
-        // Interval End
-        startOffset = commaIndex + 1;
-        endOffset = interval.length() - 1;
-
-        timeSeperatorOffsetInDatetimeString = interval.indexOf('T', startOffset);
-
-        if (timeSeperatorOffsetInDatetimeString < 0) {
-            throw new HyracksDataException("This can not be an instance of interval: missing T for a datetime value.");
-        }
-
-        long chrononTimeInMsEnd = parseDatePart(interval, startOffset, timeSeperatorOffsetInDatetimeString - 1);
-
-        chrononTimeInMsEnd += parseTimePart(interval, timeSeperatorOffsetInDatetimeString + 1, endOffset);
-
-        aInterval.setValue(chrononTimeInMsStart, chrononTimeInMsEnd, ATypeTag.DATETIME.serialize());
-
-        intervalSerde.serialize(aInterval, out);
-    }
-
-    protected void parseTimeInterval(String interval, DataOutput out) throws HyracksDataException {
-        int startOffset = 0;
-        int endOffset;
-
-        // Get the index for the comma
-        int commaIndex = interval.indexOf(',');
-        if (commaIndex < 0) {
-            throw new HyracksDataException("comma is missing for a string of interval");
-        }
-
-        endOffset = commaIndex - 1;
-        // Interval Start
-        long chrononTimeInMsStart = parseTimePart(interval, startOffset, endOffset);
-
-        if (chrononTimeInMsStart < 0) {
-            chrononTimeInMsStart += GregorianCalendarSystem.CHRONON_OF_DAY;
-        }
-
-        // Interval End
-        startOffset = commaIndex + 1;
-        endOffset = interval.length() - 1;
-
-        long chrononTimeInMsEnd = parseTimePart(interval, startOffset, endOffset);
-        if (chrononTimeInMsEnd < 0) {
-            chrononTimeInMsEnd += GregorianCalendarSystem.CHRONON_OF_DAY;
-        }
-
-        aInterval.setValue(chrononTimeInMsStart, chrononTimeInMsEnd, ATypeTag.TIME.serialize());
-        intervalSerde.serialize(aInterval, out);
-    }
-
-    protected void parseDateInterval(String interval, DataOutput out) throws HyracksDataException {
-        // the starting point for parsing (so for the accessor)
-        int startOffset = 0;
-        int endOffset;
-
-        // Get the index for the comma
-        int commaIndex = interval.indexOf(',');
-        if (commaIndex < 1) {
-            throw new HyracksDataException("comma is missing for a string of interval");
-        }
-
-        endOffset = commaIndex - 1;
-        long chrononTimeInMsStart = parseDatePart(interval, startOffset, endOffset);
-
-        // Interval End
-        startOffset = commaIndex + 1;
-        endOffset = interval.length() - 1;
-
-        long chrononTimeInMsEnd = parseDatePart(interval, startOffset, endOffset);
-
-        aInterval.setValue((chrononTimeInMsStart / GregorianCalendarSystem.CHRONON_OF_DAY),
-                (chrononTimeInMsEnd / GregorianCalendarSystem.CHRONON_OF_DAY), ATypeTag.DATE.serialize());
-        intervalSerde.serialize(aInterval, out);
-    }
-
-    private long parseDatePart(String interval, int startOffset, int endOffset) throws HyracksDataException {
+    protected long parseDatePart(String interval, int startOffset, int endOffset) throws HyracksDataException {
 
         while (interval.charAt(endOffset) == '"' || interval.charAt(endOffset) == ' ') {
             endOffset--;
@@ -443,7 +345,7 @@ public abstract class AbstractDataParser implements IDataParser {
         return ADateParserFactory.parseDatePart(interval, startOffset, endOffset - startOffset + 1);
     }
 
-    private int parseTimePart(String interval, int startOffset, int endOffset) throws HyracksDataException {
+    protected int parseTimePart(String interval, int startOffset, int endOffset) throws HyracksDataException {
 
         while (interval.charAt(endOffset) == '"' || interval.charAt(endOffset) == ' ') {
             endOffset--;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-external-data/src/main/resources/adm.grammar
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/main/resources/adm.grammar b/asterix-external-data/src/main/resources/adm.grammar
index 973c2b9..2626a31 100644
--- a/asterix-external-data/src/main/resources/adm.grammar
+++ b/asterix-external-data/src/main/resources/adm.grammar
@@ -47,9 +47,7 @@ POLYGON_CONS   = string(polygon)
 RECTANGLE_CONS = string(rectangle)
 CIRCLE_CONS    = string(circle)
 TIME_CONS      = string(time)
-INTERVAL_TIME_CONS      = string(interval-time)
-INTERVAL_DATE_CONS      = string(interval-date)
-INTERVAL_DATETIME_CONS  = string(interval-datetime)
+INTERVAL_CONS  = string(interval)
 YEAR_MONTH_DURATION_CONS = string(year-month-duration)
 DAY_TIME_DURATION_CONS   = string(day-time-duration)
 UUID_CONS      = string(uuid)

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-external-data/src/test/java/org/apache/asterix/runtime/operator/file/ADMDataParserTest.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/runtime/operator/file/ADMDataParserTest.java b/asterix-external-data/src/test/java/org/apache/asterix/runtime/operator/file/ADMDataParserTest.java
index 698e414..c6939c9 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/runtime/operator/file/ADMDataParserTest.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/runtime/operator/file/ADMDataParserTest.java
@@ -24,7 +24,9 @@ import java.io.DataOutputStream;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.asterix.external.parser.ADMDataParser;
-import org.apache.asterix.om.base.AMutableInterval;
+import org.apache.asterix.om.base.AMutableDate;
+import org.apache.asterix.om.base.AMutableDateTime;
+import org.apache.asterix.om.base.AMutableTime;
 import org.junit.Assert;
 import org.junit.Test;
 
@@ -34,25 +36,23 @@ public class ADMDataParserTest {
 
     @Test
     public void test() {
-        String[] dateIntervals = { "-9537-08-04, 9656-06-03", "-9537-04-04, 9656-06-04", "-9537-10-04, 9626-09-05" };
-        AMutableInterval[] parsedDateIntervals = new AMutableInterval[] {
-                new AMutableInterval(-4202630, 2807408, (byte) 17), new AMutableInterval(-4202752, 2807409, (byte) 17),
-                new AMutableInterval(-4202569, 2796544, (byte) 17), };
+        String[] dates = { "-9537-08-04", "9656-06-03", "-9537-04-04", "9656-06-04", "-9537-10-04", "9626-09-05" };
+        AMutableDate[] parsedDates = new AMutableDate[] { new AMutableDate(-4202630), new AMutableDate(2807408),
+                new AMutableDate(-4202752), new AMutableDate(2807409), new AMutableDate(-4202569),
+                new AMutableDate(2796544), };
 
-        String[] timeIntervals = { "12:04:45.689Z, 12:41:59.002Z", "12:10:45.169Z, 15:37:48.736Z",
-                "04:16:42.321Z, 12:22:56.816Z" };
-        AMutableInterval[] parsedTimeIntervals = new AMutableInterval[] {
-                new AMutableInterval(43485689, 45719002, (byte) 18),
-                new AMutableInterval(43845169, 56268736, (byte) 18),
-                new AMutableInterval(15402321, 44576816, (byte) 18), };
+        String[] times = { "12:04:45.689Z", "12:41:59.002Z", "12:10:45.169Z", "15:37:48.736Z", "04:16:42.321Z",
+                "12:22:56.816Z" };
+        AMutableTime[] parsedTimes = new AMutableTime[] { new AMutableTime(43485689), new AMutableTime(45719002),
+                new AMutableTime(43845169), new AMutableTime(56268736), new AMutableTime(15402321),
+                new AMutableTime(44576816), };
 
-        String[] dateTimeIntervals = { "-2640-10-11T17:32:15.675Z, 4104-02-01T05:59:11.902Z",
-                "0534-12-08T08:20:31.487Z, 6778-02-16T22:40:21.653Z",
-                "2129-12-12T13:18:35.758Z, 8647-07-01T13:10:19.691Z" };
-        AMutableInterval[] parsedDateTimeIntervals = new AMutableInterval[] {
-                new AMutableInterval(-145452954464325L, 67345192751902L, (byte) 16),
-                new AMutableInterval(-45286270768513L, 151729886421653L, (byte) 16),
-                new AMutableInterval(5047449515758L, 210721439419691L, (byte) 16) };
+        String[] dateTimes = { "-2640-10-11T17:32:15.675Z", "4104-02-01T05:59:11.902Z", "0534-12-08T08:20:31.487Z",
+                "6778-02-16T22:40:21.653Z", "2129-12-12T13:18:35.758Z", "8647-07-01T13:10:19.691Z" };
+        AMutableDateTime[] parsedDateTimes = new AMutableDateTime[] { new AMutableDateTime(-145452954464325L),
+                new AMutableDateTime(67345192751902L), new AMutableDateTime(-45286270768513L),
+                new AMutableDateTime(151729886421653L), new AMutableDateTime(5047449515758L),
+                new AMutableDateTime(210721439419691L) };
 
         Thread[] threads = new Thread[16];
         AtomicInteger errorCount = new AtomicInteger(0);
@@ -67,28 +67,28 @@ public class ADMDataParserTest {
                     try {
                         int round = 0;
                         while (round++ < 10000) {
-                            // Test parseDateInterval.
-                            for (int index = 0; index < dateIntervals.length; ++index) {
-                                PA.invokeMethod(parser, "parseDateInterval(java.lang.String, java.io.DataOutput)",
-                                        dateIntervals[index], dos);
-                                AMutableInterval aInterval = (AMutableInterval) PA.getValue(parser, "aInterval");
-                                Assert.assertTrue(aInterval.equals(parsedDateIntervals[index]));
+                            // Test parseDate.
+                            for (int index = 0; index < dates.length; ++index) {
+                                PA.invokeMethod(parser, "parseDate(java.lang.String, java.io.DataOutput)",
+                                        dates[index], dos);
+                                AMutableDate aDate = (AMutableDate) PA.getValue(parser, "aDate");
+                                Assert.assertTrue(aDate.equals(parsedDates[index]));
                             }
 
-                            // Tests parseTimeInterval.
-                            for (int index = 0; index < timeIntervals.length; ++index) {
-                                PA.invokeMethod(parser, "parseTimeInterval(java.lang.String, java.io.DataOutput)",
-                                        timeIntervals[index], dos);
-                                AMutableInterval aInterval = (AMutableInterval) PA.getValue(parser, "aInterval");
-                                Assert.assertTrue(aInterval.equals(parsedTimeIntervals[index]));
+                            // Tests parseTime.
+                            for (int index = 0; index < times.length; ++index) {
+                                PA.invokeMethod(parser, "parseTime(java.lang.String, java.io.DataOutput)",
+                                        times[index], dos);
+                                AMutableTime aTime = (AMutableTime) PA.getValue(parser, "aTime");
+                                Assert.assertTrue(aTime.equals(parsedTimes[index]));
                             }
 
-                            // Tests parseDateTimeInterval.
-                            for (int index = 0; index < dateTimeIntervals.length; ++index) {
-                                PA.invokeMethod(parser, "parseDateTimeInterval(java.lang.String, java.io.DataOutput)",
-                                        dateTimeIntervals[index], dos);
-                                AMutableInterval aInterval = (AMutableInterval) PA.getValue(parser, "aInterval");
-                                Assert.assertTrue(aInterval.equals(parsedDateTimeIntervals[index]));
+                            // Tests parseDateTime.
+                            for (int index = 0; index < dateTimes.length; ++index) {
+                                PA.invokeMethod(parser, "parseDateTime(java.lang.String, java.io.DataOutput)",
+                                        dateTimes[index], dos);
+                                AMutableDateTime aDateTime = (AMutableDateTime) PA.getValue(parser, "aDateTime");
+                                Assert.assertTrue(aDateTime.equals(parsedDateTimes[index]));
                             }
                         }
                     } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalAscPartialBinaryComparatorFactory.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalAscPartialBinaryComparatorFactory.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalAscPartialBinaryComparatorFactory.java
index 6efc7ff..bb96d5d 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalAscPartialBinaryComparatorFactory.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalAscPartialBinaryComparatorFactory.java
@@ -18,7 +18,6 @@
  */
 package org.apache.asterix.dataflow.data.nontagged.comparators;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
@@ -45,20 +44,14 @@ public class AIntervalAscPartialBinaryComparatorFactory implements IBinaryCompar
                 // The ascending interval comparator sorts intervals first by start point, then by end point.
                 // If the interval have the same point values, the final comparison orders the intervals by type
                 // (datetime, date, time).
-                int c = Long.compare(
-                        AInt64SerializerDeserializer.getLong(b1,
-                                s1 + AIntervalSerializerDeserializer.getIntervalStartOffset()),
-                        AInt64SerializerDeserializer.getLong(b2,
-                                s2 + AIntervalSerializerDeserializer.getIntervalStartOffset()));
+                int c = Long.compare(AIntervalSerializerDeserializer.getIntervalStart(b1, s1),
+                        AIntervalSerializerDeserializer.getIntervalStart(b2, s2));
                 if (c == 0) {
-                    c = Long.compare(
-                            AInt64SerializerDeserializer.getLong(b1,
-                                    s1 + AIntervalSerializerDeserializer.getIntervalEndOffset()),
-                            AInt64SerializerDeserializer.getLong(b2,
-                                    s2 + AIntervalSerializerDeserializer.getIntervalEndOffset()));
+                    c = Long.compare(AIntervalSerializerDeserializer.getIntervalEnd(b1, s1),
+                            AIntervalSerializerDeserializer.getIntervalEnd(b2, s2));
                     if (c == 0) {
-                        c = Byte.compare(b1[s1 + AIntervalSerializerDeserializer.getIntervalTagOffset()], b2[s2
-                                + AIntervalSerializerDeserializer.getIntervalTagOffset()]);
+                        c = Byte.compare(AIntervalSerializerDeserializer.getIntervalTimeType(b1, s1),
+                                AIntervalSerializerDeserializer.getIntervalTimeType(b2, s2));
                     }
                 }
                 return c;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalDescPartialBinaryComparatorFactory.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalDescPartialBinaryComparatorFactory.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalDescPartialBinaryComparatorFactory.java
index 9a09623..5ee553c 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalDescPartialBinaryComparatorFactory.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/comparators/AIntervalDescPartialBinaryComparatorFactory.java
@@ -18,7 +18,6 @@
  */
 package org.apache.asterix.dataflow.data.nontagged.comparators;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparator;
 import org.apache.hyracks.api.dataflow.value.IBinaryComparatorFactory;
@@ -45,20 +44,14 @@ public class AIntervalDescPartialBinaryComparatorFactory implements IBinaryCompa
                 // The descending interval comparator sorts intervals first by end point, then by start point.
                 // If the interval have the same point values, the final comparison orders the intervals by type
                 // (time, date, datetime).
-                int c = Long.compare(
-                        AInt64SerializerDeserializer.getLong(b1,
-                                s1 + AIntervalSerializerDeserializer.getIntervalEndOffset()),
-                        AInt64SerializerDeserializer.getLong(b2,
-                                s2 + AIntervalSerializerDeserializer.getIntervalEndOffset()));
+                int c = Long.compare(AIntervalSerializerDeserializer.getIntervalEnd(b1, s1),
+                        AIntervalSerializerDeserializer.getIntervalEnd(b2, s2));
                 if (c == 0) {
-                    c = Long.compare(
-                            AInt64SerializerDeserializer.getLong(b1,
-                                    s1 + AIntervalSerializerDeserializer.getIntervalStartOffset()),
-                            AInt64SerializerDeserializer.getLong(b2,
-                                    s2 + AIntervalSerializerDeserializer.getIntervalStartOffset()));
+                    c = Long.compare(AIntervalSerializerDeserializer.getIntervalStart(b1, s1),
+                            AIntervalSerializerDeserializer.getIntervalStart(b2, s2));
                     if (c == 0) {
-                        c = Byte.compare(b1[s1 + AIntervalSerializerDeserializer.getIntervalTagOffset()],
-                                b2[s2 + AIntervalSerializerDeserializer.getIntervalTagOffset()]);
+                        c = Byte.compare(AIntervalSerializerDeserializer.getIntervalTimeType(b1, s1),
+                                AIntervalSerializerDeserializer.getIntervalTimeType(b2, s2));
                     }
                 }
                 // Since the comparisons are based on ascending order, the result is reversed.

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/adm/AIntervalPrinter.java
----------------------------------------------------------------------
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 99c02e8..3c60cd2 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,9 +20,9 @@ package org.apache.asterix.dataflow.data.nontagged.printers.adm;
 
 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.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
 import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.data.IPrinter;
 
@@ -42,29 +42,34 @@ public class AIntervalPrinter implements IPrinter {
      */
     @Override
     public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
-        ps.print("interval");
+        ps.print("interval(");
 
-        short typetag = AInt8SerializerDeserializer.getByte(b, s + 1 + 8 * 2);
+        byte typetag = AIntervalSerializerDeserializer.getIntervalTimeType(b, s + 1);
+        int startOffset = AIntervalSerializerDeserializer.getIntervalStartOffset(b, s + 1) - 1;
+        int startSize = AIntervalSerializerDeserializer.getStartSize(b, s + 1);
+        int endOffset = AIntervalSerializerDeserializer.getIntervalEndOffset(b, s + 1) - 1;
+        int endSize = AIntervalSerializerDeserializer.getEndSize(b, s + 1);
 
-        if (typetag == ATypeTag.DATE.serialize()) {
-            ps.print("-date(\"");
-            PrintTools.printDateString(b, s + 4, 4, ps);
-            ps.print(", ");
-            PrintTools.printDateString(b, s + 12, 4, ps);
-        } else if (typetag == ATypeTag.TIME.serialize()) {
-            ps.print("-time(\"");
-            PrintTools.printTimeString(b, s + 4, 4, ps);
-            ps.print(", ");
-            PrintTools.printTimeString(b, s + 12, 4, ps);
-        } else if (typetag == ATypeTag.DATETIME.serialize()) {
-            ps.print("-datetime(\"");
-            PrintTools.printDateTimeString(b, s, 8, ps);
-            ps.print(", ");
-            PrintTools.printDateTimeString(b, s + 8, 8, ps);
-        } else {
-            throw new AlgebricksException("Unsupport internal time types in interval: " + typetag);
+        IPrinter timeInstancePrinter;
+        ATypeTag intervalType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(typetag);
+        switch (intervalType) {
+            case DATE:
+                timeInstancePrinter = ADatePrinter.INSTANCE;
+                break;
+            case TIME:
+                timeInstancePrinter = ATimePrinter.INSTANCE;
+                break;
+            case DATETIME:
+                timeInstancePrinter = ADateTimePrinter.INSTANCE;
+                break;
+            default:
+                throw new AlgebricksException("Unsupport internal time types in interval: " + typetag);
         }
 
-        ps.print("\")");
+        timeInstancePrinter.print(b, startOffset, startSize, ps);
+        ps.print(", ");
+        timeInstancePrinter.print(b, endOffset, endSize, ps);
+
+        ps.print(")");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AIntervalPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AIntervalPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AIntervalPrinter.java
index e77ef94..3f8a647 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AIntervalPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/clean/AIntervalPrinter.java
@@ -20,8 +20,12 @@ package org.apache.asterix.dataflow.data.nontagged.printers.json.clean;
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADatePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADateTimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ATimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
 import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.data.IPrinter;
 
@@ -43,29 +47,32 @@ public class AIntervalPrinter implements IPrinter {
     public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
         ps.print("{ \"interval\": { \"start\": ");
 
-        short typetag = AInt8SerializerDeserializer.getByte(b, s + 1 + 8 * 2);
+        byte typetag = AIntervalSerializerDeserializer.getIntervalTimeType(b, s + 1);
+        int startOffset = AIntervalSerializerDeserializer.getIntervalStartOffset(b, s + 1) - 1;
+        int startSize = AIntervalSerializerDeserializer.getStartSize(b, s + 1);
+        int endOffset = AIntervalSerializerDeserializer.getIntervalEndOffset(b, s + 1) - 1;
+        int endSize = AIntervalSerializerDeserializer.getEndSize(b, s + 1);
 
         IPrinter timeInstancePrinter;
-
-        if (typetag == ATypeTag.DATE.serialize()) {
-            timeInstancePrinter = ADatePrinter.INSTANCE;
-            ((ADatePrinter) timeInstancePrinter).print(b, s + 4, 4, ps);
-            ps.print(", \"end\": ");
-            ((ADatePrinter) timeInstancePrinter).print(b, s + 12, 4, ps);
-        } else if (typetag == ATypeTag.TIME.serialize()) {
-            timeInstancePrinter = ATimePrinter.INSTANCE;
-            ((ATimePrinter) timeInstancePrinter).print(b, s + 4, 4, ps);
-            ps.print(", \"end\": ");
-            ((ATimePrinter) timeInstancePrinter).print(b, s + 12, 4, ps);
-        } else if (typetag == ATypeTag.DATETIME.serialize()) {
-            timeInstancePrinter = ADateTimePrinter.INSTANCE;
-            ((ADateTimePrinter) timeInstancePrinter).print(b, s, 8, ps);
-            ps.print(", \"end\": ");
-            ((ADateTimePrinter) timeInstancePrinter).print(b, s + 8, 8, ps);
-        } else {
-            throw new AlgebricksException("Unsupport internal time types in interval: " + typetag);
+        ATypeTag intervalType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(typetag);
+        switch (intervalType) {
+            case DATE:
+                timeInstancePrinter = ADatePrinter.INSTANCE;
+                break;
+            case TIME:
+                timeInstancePrinter = ATimePrinter.INSTANCE;
+                break;
+            case DATETIME:
+                timeInstancePrinter = ADateTimePrinter.INSTANCE;
+                break;
+            default:
+                throw new AlgebricksException("Unsupport internal time types in interval: " + typetag);
         }
 
+        timeInstancePrinter.print(b, startOffset, startSize, ps);
+        ps.print(", \"end\": ");
+        timeInstancePrinter.print(b, endOffset, endSize, ps);
+
         ps.print("}}");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AIntervalPrinter.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AIntervalPrinter.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AIntervalPrinter.java
index 7727f92..84bf23c 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AIntervalPrinter.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/printers/json/lossless/AIntervalPrinter.java
@@ -20,8 +20,12 @@ package org.apache.asterix.dataflow.data.nontagged.printers.json.lossless;
 
 import java.io.PrintStream;
 
-import org.apache.asterix.dataflow.data.nontagged.serde.AInt8SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADatePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ADateTimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.printers.adm.ATimePrinter;
+import org.apache.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
 import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.EnumDeserializer;
 import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
 import org.apache.hyracks.algebricks.data.IPrinter;
 
@@ -43,29 +47,32 @@ public class AIntervalPrinter implements IPrinter {
     public void print(byte[] b, int s, int l, PrintStream ps) throws AlgebricksException {
         ps.print("{ \"interval\": { \"start\": ");
 
-        short typetag = AInt8SerializerDeserializer.getByte(b, s + 1 + 8 * 2);
+        byte typetag = AIntervalSerializerDeserializer.getIntervalTimeType(b, s + 1);
+        int startOffset = AIntervalSerializerDeserializer.getIntervalStartOffset(b, s + 1) - 1;
+        int startSize = AIntervalSerializerDeserializer.getStartSize(b, s + 1);
+        int endOffset = AIntervalSerializerDeserializer.getIntervalEndOffset(b, s + 1) - 1;
+        int endSize = AIntervalSerializerDeserializer.getEndSize(b, s + 1);
 
         IPrinter timeInstancePrinter;
-
-        if (typetag == ATypeTag.DATE.serialize()) {
-            timeInstancePrinter = ADatePrinter.INSTANCE;
-            ((ADatePrinter) timeInstancePrinter).print(b, s + 4, 4, ps);
-            ps.print(", \"end\": ");
-            ((ADatePrinter) timeInstancePrinter).print(b, s + 12, 4, ps);
-        } else if (typetag == ATypeTag.TIME.serialize()) {
-            timeInstancePrinter = ATimePrinter.INSTANCE;
-            ((ATimePrinter) timeInstancePrinter).print(b, s + 4, 4, ps);
-            ps.print(", \"end\": ");
-            ((ATimePrinter) timeInstancePrinter).print(b, s + 12, 4, ps);
-        } else if (typetag == ATypeTag.DATETIME.serialize()) {
-            timeInstancePrinter = ADateTimePrinter.INSTANCE;
-            ((ADateTimePrinter) timeInstancePrinter).print(b, s, 8, ps);
-            ps.print(", \"end\": ");
-            ((ADateTimePrinter) timeInstancePrinter).print(b, s + 8, 8, ps);
-        } else {
-            throw new AlgebricksException("Unsupport internal time types in interval: " + typetag);
+        ATypeTag intervalType = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(typetag);
+        switch (intervalType) {
+            case DATE:
+                timeInstancePrinter = ADatePrinter.INSTANCE;
+                break;
+            case TIME:
+                timeInstancePrinter = ATimePrinter.INSTANCE;
+                break;
+            case DATETIME:
+                timeInstancePrinter = ADateTimePrinter.INSTANCE;
+                break;
+            default:
+                throw new AlgebricksException("Unsupport internal time types in interval: " + typetag);
         }
 
+        timeInstancePrinter.print(b, startOffset, startSize, ps);
+        ps.print(", \"end\": ");
+        timeInstancePrinter.print(b, endOffset, endSize, ps);
+
         ps.print("}}");
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
index 94a8917..d5b6488 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
@@ -23,17 +23,27 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import org.apache.asterix.om.base.AInterval;
+import org.apache.asterix.om.types.ATypeTag;
 import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
 import org.apache.hyracks.api.exceptions.HyracksDataException;
+import org.apache.hyracks.data.std.primitive.BytePointable;
+import org.apache.hyracks.data.std.primitive.IntegerPointable;
+import org.apache.hyracks.data.std.primitive.LongPointable;
 
+/*
+ * This class serializes and de-serializes the binary data representation of an interval.
+ *
+ * Interval {
+ *   byte type;
+ *   T start;
+ *   T end;
+ *
+ * T can be of type date, time or datetime.
+ */
 public class AIntervalSerializerDeserializer implements ISerializerDeserializer<AInterval> {
 
     private static final long serialVersionUID = 1L;
 
-    private static final int INTERVAL_START_POINT_OFFSET = 0;
-    private static final int INTERVAL_END_POINT_OFFSET = INTERVAL_START_POINT_OFFSET + Long.BYTES;
-    private static final int INTERVAL_TAG_OFFSET = INTERVAL_END_POINT_OFFSET + Long.BYTES;
-
     public static final AIntervalSerializerDeserializer INSTANCE = new AIntervalSerializerDeserializer();
 
     private AIntervalSerializerDeserializer() {
@@ -42,7 +52,16 @@ public class AIntervalSerializerDeserializer implements ISerializerDeserializer<
     @Override
     public AInterval deserialize(DataInput in) throws HyracksDataException {
         try {
-            return new AInterval(in.readLong(), in.readLong(), in.readByte());
+            byte tag = in.readByte();
+            long start = 0, end = 0;
+            if (tag == ATypeTag.DATETIME.serialize()) {
+                start = in.readLong();
+                end = in.readLong();
+            } else {
+                start = in.readInt();
+                end = in.readInt();
+            }
+            return new AInterval(start, end, tag);
         } catch (IOException e) {
             throw new HyracksDataException(e);
         }
@@ -52,36 +71,75 @@ public class AIntervalSerializerDeserializer implements ISerializerDeserializer<
     @Override
     public void serialize(AInterval instance, DataOutput out) throws HyracksDataException {
         try {
-            out.writeLong(instance.getIntervalStart());
-            out.writeLong(instance.getIntervalEnd());
             out.writeByte(instance.getIntervalType());
+            if (instance.getIntervalType() == ATypeTag.DATETIME.serialize()) {
+                out.writeLong(instance.getIntervalStart());
+                out.writeLong(instance.getIntervalEnd());
+            } else {
+                out.writeInt((int) instance.getIntervalStart());
+                out.writeInt((int) instance.getIntervalEnd());
+            }
         } catch (IOException e) {
             throw new HyracksDataException(e);
         }
     }
 
-    public static long getIntervalStart(byte[] data, int offset) {
-        return AInt64SerializerDeserializer.getLong(data, offset + getIntervalStartOffset());
+    public static byte getIntervalTimeType(byte[] data, int start) {
+        return BytePointable.getByte(data, getIntervalTypeOffset(data, start));
     }
 
-    public static long getIntervalEnd(byte[] data, int offset) {
-        return AInt64SerializerDeserializer.getLong(data, offset + getIntervalEndOffset());
+    public static int getIntervalTypeOffset(byte[] data, int start) {
+        return start;
     }
 
-    public static int getIntervalStartOffset() {
-        return INTERVAL_START_POINT_OFFSET;
+    public static int getTypeSize() {
+        return Byte.BYTES;
     }
 
-    public static int getIntervalEndOffset() {
-        return INTERVAL_END_POINT_OFFSET;
+    public static long getIntervalStart(byte[] data, int start) {
+        if (getIntervalTimeType(data, start) == ATypeTag.DATETIME.serialize()) {
+            return LongPointable.getLong(data, getIntervalStartOffset(data, start));
+        } else {
+            return IntegerPointable.getInteger(data, getIntervalStartOffset(data, start));
+        }
+    }
+
+    public static int getIntervalStartOffset(byte[] data, int start) {
+        int offset = getIntervalTypeOffset(data, start) + getTypeSize();
+        return offset;
     }
 
-    public static int getIntervalTagOffset() {
-        return INTERVAL_TAG_OFFSET;
+    public static int getStartSize(byte[] data, int start) {
+        if (getIntervalTimeType(data, start) == ATypeTag.DATETIME.serialize()) {
+            return Long.BYTES;
+        } else {
+            return Integer.BYTES;
+        }
+    }
+
+    public static long getIntervalEnd(byte[] data, int start) {
+        if (getIntervalTimeType(data, start) == ATypeTag.DATETIME.serialize()) {
+            return LongPointable.getLong(data, getIntervalEndOffset(data, start));
+        } else {
+            return IntegerPointable.getInteger(data, getIntervalEndOffset(data, start));
+        }
+    }
+
+    public static int getIntervalEndOffset(byte[] data, int start) {
+        int offset = getIntervalStartOffset(data, start) + getStartSize(data, start);
+        return offset;
+    }
+
+    public static int getEndSize(byte[] data, int start) {
+        if (getIntervalTimeType(data, start) == ATypeTag.DATETIME.serialize()) {
+            return Long.BYTES;
+        } else {
+            return Integer.BYTES;
+        }
     }
 
-    public static byte getIntervalTimeType(byte[] data, int offset) {
-        return data[offset + 8 * 2];
+    public static int getIntervalLength(byte[] data, int start) {
+        return getTypeSize() + getStartSize(data, start) + getEndSize(data, start);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AOrderedListSerializerDeserializer.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AOrderedListSerializerDeserializer.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AOrderedListSerializerDeserializer.java
index 0004977..fba898d 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AOrderedListSerializerDeserializer.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AOrderedListSerializerDeserializer.java
@@ -67,21 +67,7 @@ public class AOrderedListSerializerDeserializer implements ISerializerDeserializ
     @Override
     public AOrderedList deserialize(DataInput in) throws HyracksDataException {
         try {
-            boolean fixedSize = false;
             ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(in.readByte());
-            switch (typeTag) {
-                case STRING:
-                case BINARY:
-                case RECORD:
-                case ORDEREDLIST:
-                case UNORDEREDLIST:
-                case ANY:
-                    fixedSize = false;
-                    break;
-                default:
-                    fixedSize = true;
-                    break;
-            }
 
             IAType currentItemType = itemType;
             @SuppressWarnings("rawtypes")
@@ -97,7 +83,7 @@ public class AOrderedListSerializerDeserializer implements ISerializerDeserializ
             int numberOfitems;
             numberOfitems = in.readInt();
             if (numberOfitems > 0) {
-                if (!fixedSize) {
+                if (!NonTaggedFormatUtil.isFixedSizedCollection(currentItemType)) {
                     for (int i = 0; i < numberOfitems; i++)
                         in.readInt();
                 }
@@ -147,17 +133,11 @@ public class AOrderedListSerializerDeserializer implements ISerializerDeserializ
     public static int getItemOffset(byte[] serOrderedList, int offset, int itemIndex) throws AsterixException {
         if (serOrderedList[offset] == ATypeTag.ORDEREDLIST.serialize()) {
             ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[offset + 1]);
-            switch (typeTag) {
-                case STRING:
-                case BINARY:
-                case RECORD:
-                case ORDEREDLIST:
-                case UNORDEREDLIST:
-                case ANY:
-                    return offset + AInt32SerializerDeserializer.getInt(serOrderedList, offset + 10 + (4 * itemIndex));
-                default:
-                    int length = NonTaggedFormatUtil.getFieldValueLength(serOrderedList, offset + 1, typeTag, true);
-                    return offset + 10 + (length * itemIndex);
+            if (NonTaggedFormatUtil.isFixedSizedCollection(typeTag)) {
+                int length = NonTaggedFormatUtil.getFieldValueLength(serOrderedList, offset + 1, typeTag, true);
+                return offset + 10 + (length * itemIndex);
+            } else {
+                return offset + AInt32SerializerDeserializer.getInt(serOrderedList, offset + 10 + (4 * itemIndex));
             }
             // 10 = tag (1) + itemTag (1) + list size (4) + number of items (4)
         } else

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AUnorderedListSerializerDeserializer.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AUnorderedListSerializerDeserializer.java b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AUnorderedListSerializerDeserializer.java
index 87e2ab7..9475e6a 100644
--- a/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AUnorderedListSerializerDeserializer.java
+++ b/asterix-om/src/main/java/org/apache/asterix/dataflow/data/nontagged/serde/AUnorderedListSerializerDeserializer.java
@@ -69,21 +69,7 @@ public class AUnorderedListSerializerDeserializer implements ISerializerDeserial
     public AUnorderedList deserialize(DataInput in) throws HyracksDataException {
         // TODO: schemaless unordered list deserializer
         try {
-            boolean fixedSize = false;
             ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(in.readByte());
-            switch (typeTag) {
-                case STRING:
-                case BINARY:
-                case RECORD:
-                case ORDEREDLIST:
-                case UNORDEREDLIST:
-                case ANY:
-                    fixedSize = false;
-                    break;
-                default:
-                    fixedSize = true;
-                    break;
-            }
 
             IAType currentItemType = itemType;
             @SuppressWarnings("rawtypes")
@@ -99,7 +85,7 @@ public class AUnorderedListSerializerDeserializer implements ISerializerDeserial
             numberOfitems = in.readInt();
             ArrayList<IAObject> items = new ArrayList<IAObject>();
             if (numberOfitems > 0) {
-                if (!fixedSize) {
+                if (!NonTaggedFormatUtil.isFixedSizedCollection(currentItemType)) {
                     for (int i = 0; i < numberOfitems; i++)
                         in.readInt();
                 }
@@ -149,17 +135,11 @@ public class AUnorderedListSerializerDeserializer implements ISerializerDeserial
     public static int getItemOffset(byte[] serOrderedList, int offset, int itemIndex) throws AsterixException {
         if (serOrderedList[offset] == ATypeTag.UNORDEREDLIST.serialize()) {
             ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serOrderedList[offset + 1]);
-            switch (typeTag) {
-                case STRING:
-                case BINARY:
-                case RECORD:
-                case ORDEREDLIST:
-                case UNORDEREDLIST:
-                case ANY:
-                    return offset + AInt32SerializerDeserializer.getInt(serOrderedList, offset + 10 + (4 * itemIndex));
-                default:
-                    int length = NonTaggedFormatUtil.getFieldValueLength(serOrderedList, offset + 1, typeTag, true);
-                    return offset + 10 + (length * itemIndex);
+            if (NonTaggedFormatUtil.isFixedSizedCollection(typeTag)) {
+                int length = NonTaggedFormatUtil.getFieldValueLength(serOrderedList, offset + 1, typeTag, true);
+                return offset + 10 + (length * itemIndex);
+            } else {
+                return offset + AInt32SerializerDeserializer.getInt(serOrderedList, offset + 10 + (4 * itemIndex));
             }
             // 10 = tag (1) + itemTag (1) + list size (4) + number of items (4)
         } else

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java b/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
index 7b8a9fa..f1b0e67 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/functions/AsterixBuiltinFunctions.java
@@ -508,12 +508,8 @@ public class AsterixBuiltinFunctions {
     public final static FunctionIdentifier DAY_TIME_DURATION_CONSTRUCTOR = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "day-time-duration", 1);
 
-    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_DATE = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "interval-from-date", 2);
-    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_TIME = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "interval-from-time", 2);
-    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_DATETIME = new FunctionIdentifier(
-            FunctionConstants.ASTERIX_NS, "interval-from-datetime", 2);
+    public final static FunctionIdentifier INTERVAL_CONSTRUCTOR = new FunctionIdentifier(
+            FunctionConstants.ASTERIX_NS, "interval", 2);
     public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_DATE = new FunctionIdentifier(
             FunctionConstants.ASTERIX_NS, "interval-start-from-date", 2);
     public final static FunctionIdentifier INTERVAL_CONSTRUCTOR_START_FROM_TIME = new FunctionIdentifier(
@@ -1026,9 +1022,7 @@ public class AsterixBuiltinFunctions {
         addFunction(DURATION_FROM_INTERVAL, OptionalADayTimeDurationTypeComputer.INSTANCE, true);
 
         // interval constructors
-        addFunction(INTERVAL_CONSTRUCTOR_DATE, OptionalAIntervalTypeComputer.INSTANCE, true);
-        addFunction(INTERVAL_CONSTRUCTOR_TIME, OptionalAIntervalTypeComputer.INSTANCE, true);
-        addFunction(INTERVAL_CONSTRUCTOR_DATETIME, OptionalAIntervalTypeComputer.INSTANCE, true);
+        addFunction(INTERVAL_CONSTRUCTOR, OptionalAIntervalTypeComputer.INSTANCE, true);
         addFunction(INTERVAL_CONSTRUCTOR_START_FROM_DATE, OptionalAIntervalTypeComputer.INSTANCE, true);
         addFunction(INTERVAL_CONSTRUCTOR_START_FROM_DATETIME, OptionalAIntervalTypeComputer.INSTANCE, true);
         addFunction(INTERVAL_CONSTRUCTOR_START_FROM_TIME, OptionalAIntervalTypeComputer.INSTANCE, true);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/om/pointables/AListVisitablePointable.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/AListVisitablePointable.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/AListVisitablePointable.java
index 42371ea..2f7d9af 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/pointables/AListVisitablePointable.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/AListVisitablePointable.java
@@ -101,19 +101,9 @@ public class AListVisitablePointable extends AbstractVisitablePointable {
 
         int numberOfitems = AInt32SerializerDeserializer.getInt(b, s + 6);
         int itemOffset;
-        if (typedItemList) {
-            switch (itemTag) {
-                case STRING:
-                case BINARY:
-                case RECORD:
-                case ORDEREDLIST:
-                case UNORDEREDLIST:
-                case ANY:
-                    itemOffset = s + 10 + (numberOfitems * 4);
-                    break;
-                default:
-                    itemOffset = s + 10;
-            }
+
+        if (typedItemList && NonTaggedFormatUtil.isFixedSizedCollection(itemTag)) {
+            itemOffset = s + 10;
         } else {
             itemOffset = s + 10 + (numberOfitems * 4);
         }

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
index 734319a..2f8e5f9 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/clean/APrintVisitor.java
@@ -34,6 +34,7 @@ import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt16Prin
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt32Printer;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt64Printer;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AInt8Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.AIntervalPrinter;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ALinePrinter;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.ANullPrinter;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.clean.APoint3DPrinter;
@@ -154,6 +155,10 @@ public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<Prin
                     ADurationPrinter.INSTANCE.print(b, s, l, ps);
                     break;
                 }
+                case INTERVAL: {
+                    AIntervalPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
                 case POINT: {
                     APointPrinter.INSTANCE.print(b, s, l, ps);
                     break;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java
index d291d33..3d8958a 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/pointables/printer/json/lossless/APrintVisitor.java
@@ -34,6 +34,7 @@ import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt16P
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt32Printer;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt64Printer;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AInt8Printer;
+import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.AIntervalPrinter;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ALinePrinter;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.ANullPrinter;
 import org.apache.asterix.dataflow.data.nontagged.printers.json.lossless.APoint3DPrinter;
@@ -154,6 +155,10 @@ public class APrintVisitor implements IVisitablePointableVisitor<Void, Pair<Prin
                     ADurationPrinter.INSTANCE.print(b, s, l, ps);
                     break;
                 }
+                case INTERVAL: {
+                    AIntervalPrinter.INSTANCE.print(b, s, l, ps);
+                    break;
+                }
                 case POINT: {
                     APointPrinter.INSTANCE.print(b, s, l, ps);
                     break;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
----------------------------------------------------------------------
diff --git a/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java b/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
index 6377bcc..c24ce45 100644
--- a/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
+++ b/asterix-om/src/main/java/org/apache/asterix/om/util/NonTaggedFormatUtil.java
@@ -23,6 +23,7 @@ import java.util.List;
 import org.apache.asterix.common.config.DatasetConfig.IndexType;
 import org.apache.asterix.common.exceptions.AsterixException;
 import org.apache.asterix.dataflow.data.nontagged.serde.AInt16SerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AOrderedListSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.ARecordSerializerDeserializer;
 import org.apache.asterix.dataflow.data.nontagged.serde.AUnorderedListSerializerDeserializer;
@@ -48,19 +49,27 @@ public final class NonTaggedFormatUtil {
 
     public static final boolean isFixedSizedCollection(IAType type) {
         switch (type.getTypeTag()) {
+            case UNION:
+                if (!((AUnionType) type).isNullableType())
+                    return false;
+                else
+                    return isFixedSizedCollection(((AUnionType) type).getNullableType());
+            default:
+                return isFixedSizedCollection(type.getTypeTag());
+        }
+    }
+
+    public static final boolean isFixedSizedCollection(ATypeTag type) {
+        switch (type) {
             case STRING:
             case BINARY:
             case RECORD:
+            case INTERVAL:
             case ORDEREDLIST:
             case UNORDEREDLIST:
             case POLYGON:
             case ANY:
                 return false;
-            case UNION:
-                if (!((AUnionType) type).isNullableType())
-                    return false;
-                else
-                    return isFixedSizedCollection(((AUnionType) type).getNullableType());
             default:
                 return true;
         }
@@ -130,7 +139,10 @@ public final class NonTaggedFormatUtil {
             case UUID:
                 return 16;
             case INTERVAL:
-                return 17;
+                if (tagged)
+                    return AIntervalSerializerDeserializer.getIntervalLength(serNonTaggedAObject, offset + 1);
+                else
+                    return AIntervalSerializerDeserializer.getIntervalLength(serNonTaggedAObject, offset);
             case POINT3D:
             case CIRCLE:
                 return 24;

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalConstructorDescriptor.java
new file mode 100644
index 0000000..a342b70
--- /dev/null
+++ b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalConstructorDescriptor.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.asterix.runtime.evaluators.constructors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
+import org.apache.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
+import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import org.apache.asterix.om.base.AInterval;
+import org.apache.asterix.om.base.AMutableInterval;
+import org.apache.asterix.om.base.ANull;
+import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
+import org.apache.asterix.om.functions.IFunctionDescriptor;
+import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
+import org.apache.asterix.om.types.ATypeTag;
+import org.apache.asterix.om.types.BuiltinType;
+import org.apache.asterix.om.types.EnumDeserializer;
+import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
+import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
+import org.apache.hyracks.data.std.api.IDataOutputProvider;
+import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
+import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class AIntervalConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = AsterixBuiltinFunctions.INTERVAL_CONSTRUCTOR;
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new AIntervalConstructorDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
+        return new ICopyEvaluatorFactory() {
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private DataOutput out = output.getDataOutput();
+                    private ArrayBackedValueStorage argOut0 = new ArrayBackedValueStorage();
+                    private ArrayBackedValueStorage argOut1 = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval0 = args[0].createEvaluator(argOut0);
+                    private ICopyEvaluator eval1 = args[1].createEvaluator(argOut1);
+                    private String errorMessage = "This can not be an instance of interval (only support Date/Time/Datetime)";
+                    private AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINTERVAL);
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+
+                        argOut0.reset();
+                        argOut1.reset();
+                        eval0.evaluate(tuple);
+                        eval1.evaluate(tuple);
+
+                        try {
+
+                            if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
+                                    || argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
+                                nullSerde.serialize(ANull.NULL, out);
+                                return;
+                            }
+
+                            if (argOut0.getByteArray()[0] != argOut1.getByteArray()[0]) {
+                                throw new AlgebricksException(
+                                        FID.getName()
+                                                + ": expects both arguments to be of the same type. Either DATE/TIME/DATETIME, but got "
+                                                + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(
+                                                        argOut0.getByteArray()[0])
+                                                + " and " + EnumDeserializer.ATYPETAGDESERIALIZER
+                                                        .deserialize(argOut0.getByteArray()[1]));
+                            }
+
+                            long intervalStart = 0, intervalEnd = 0;
+                            ATypeTag intervalType = EnumDeserializer.ATYPETAGDESERIALIZER
+                                    .deserialize(argOut0.getByteArray()[0]);
+
+                            switch (intervalType) {
+                                case DATE:
+                                    intervalStart = ADateSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
+                                    intervalEnd = ADateSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
+                                    break;
+                                case TIME:
+                                    intervalStart = ATimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
+                                    intervalEnd = ATimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
+                                    break;
+                                case DATETIME:
+                                    intervalStart = ADateTimeSerializerDeserializer.getChronon(argOut0.getByteArray(),
+                                            1);
+                                    intervalEnd = ADateTimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
+                                    break;
+                                default:
+                                    throw new AlgebricksException(
+                                            FID.getName() + ": expects NULL/DATE/TIME/DATETIME as arguments, but got "
+                                                    + intervalType);
+                            }
+
+                            if (intervalEnd < intervalStart) {
+                                throw new AlgebricksException(
+                                        FID.getName() + ": interval end must not be less than the interval start.");
+                            }
+
+                            aInterval.setValue(intervalStart, intervalEnd, intervalType.serialize());
+                            intervalSerde.serialize(aInterval, out);
+
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(errorMessage);
+                        } catch (Exception e2) {
+                            throw new AlgebricksException(e2);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
deleted file mode 100644
index ecfed56..0000000
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.runtime.evaluators.constructors;
-
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
-import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import org.apache.asterix.om.base.AInterval;
-import org.apache.asterix.om.base.AMutableInterval;
-import org.apache.asterix.om.base.ANull;
-import org.apache.asterix.om.base.temporal.ADateParserFactory;
-import org.apache.asterix.om.base.temporal.GregorianCalendarSystem;
-import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
-import org.apache.asterix.om.functions.IFunctionDescriptor;
-import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
-import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
-import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
-import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
-import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-public class AIntervalFromDateConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-    private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = AsterixBuiltinFunctions.INTERVAL_CONSTRUCTOR_DATE;
-    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        @Override
-        public IFunctionDescriptor createFunctionDescriptor() {
-            return new AIntervalFromDateConstructorDescriptor();
-        }
-    };
-
-    @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        return new ICopyEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
-
-                    private DataOutput out = output.getDataOutput();
-
-                    private ArrayBackedValueStorage argOut0 = new ArrayBackedValueStorage();
-                    private ArrayBackedValueStorage argOut1 = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval0 = args[0].createEvaluator(argOut0);
-                    private ICopyEvaluator eval1 = args[1].createEvaluator(argOut1);
-                    private String errorMessage = "This can not be an instance of interval (from Date)";
-                    //TODO: Where to move and fix these?
-                    private AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINTERVAL);
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ANULL);
-                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
-
-                    @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
-                        argOut0.reset();
-                        argOut1.reset();
-                        eval0.evaluate(tuple);
-                        eval1.evaluate(tuple);
-
-                        try {
-
-                            if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                                    || argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                nullSerde.serialize(ANull.NULL, out);
-                                return;
-                            }
-
-                            long intervalStart = 0, intervalEnd = 0;
-
-                            if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
-                                intervalStart = ADateSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
-                            } else if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
-                                int stringLength = utf8Ptr.getUTF8Length();
-                                intervalStart = ADateParserFactory.parseDatePart(utf8Ptr.getByteArray(),
-                                        utf8Ptr.getCharStartOffset(), stringLength)
-                                        / GregorianCalendarSystem.CHRONON_OF_DAY;
-                            } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/STRING/DATE for the first argument, but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0]));
-                            }
-
-                            if (argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
-                                intervalEnd = ADateSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
-                            } else if (argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
-                                int stringLength = utf8Ptr.getUTF8Length();
-                                intervalEnd = ADateParserFactory.parseDatePart(utf8Ptr.getByteArray(),
-                                        utf8Ptr.getCharStartOffset(), stringLength)
-                                        / GregorianCalendarSystem.CHRONON_OF_DAY;
-                            } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/STRING/DATE for the second argument, but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut1.getByteArray()[0]));
-                            }
-
-                            if (intervalEnd < intervalStart) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": interval end must not be less than the interval start.");
-                            }
-
-                            aInterval.setValue(intervalStart, intervalEnd, ATypeTag.SERIALIZED_DATE_TYPE_TAG);
-                            intervalSerde.serialize(aInterval, out);
-
-                        } catch (IOException e1) {
-                            throw new AlgebricksException(errorMessage);
-                        } catch (Exception e2) {
-                            throw new AlgebricksException(e2);
-                        }
-                    }
-                };
-            }
-        };
-    }
-
-    @Override
-    public FunctionIdentifier getIdentifier() {
-        return FID;
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/d434b50f/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
deleted file mode 100644
index 2972912..0000000
--- a/asterix-runtime/src/main/java/org/apache/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.asterix.runtime.evaluators.constructors;
-
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
-import org.apache.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
-import org.apache.asterix.om.base.AInterval;
-import org.apache.asterix.om.base.AMutableInterval;
-import org.apache.asterix.om.base.ANull;
-import org.apache.asterix.om.base.temporal.ADateParserFactory;
-import org.apache.asterix.om.base.temporal.ATimeParserFactory;
-import org.apache.asterix.om.functions.AsterixBuiltinFunctions;
-import org.apache.asterix.om.functions.IFunctionDescriptor;
-import org.apache.asterix.om.functions.IFunctionDescriptorFactory;
-import org.apache.asterix.om.types.ATypeTag;
-import org.apache.asterix.om.types.BuiltinType;
-import org.apache.asterix.om.types.EnumDeserializer;
-import org.apache.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
-import org.apache.hyracks.algebricks.common.exceptions.AlgebricksException;
-import org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluator;
-import org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
-import org.apache.hyracks.api.dataflow.value.ISerializerDeserializer;
-import org.apache.hyracks.data.std.api.IDataOutputProvider;
-import org.apache.hyracks.data.std.primitive.UTF8StringPointable;
-import org.apache.hyracks.data.std.util.ArrayBackedValueStorage;
-import org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-
-public class AIntervalFromDateTimeConstructorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
-
-    private static final long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = AsterixBuiltinFunctions.INTERVAL_CONSTRUCTOR_DATETIME;
-
-    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
-        @Override
-        public IFunctionDescriptor createFunctionDescriptor() {
-            return new AIntervalFromDateTimeConstructorDescriptor();
-        }
-    };
-
-    @Override
-    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) {
-        return new ICopyEvaluatorFactory() {
-            private static final long serialVersionUID = 1L;
-
-            @Override
-            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
-                return new ICopyEvaluator() {
-
-                    private DataOutput out = output.getDataOutput();
-
-                    private ArrayBackedValueStorage argOut0 = new ArrayBackedValueStorage();
-                    private ArrayBackedValueStorage argOut1 = new ArrayBackedValueStorage();
-                    private ICopyEvaluator eval0 = args[0].createEvaluator(argOut0);
-                    private ICopyEvaluator eval1 = args[1].createEvaluator(argOut1);
-                    private String errorMessage = "This can not be an instance of interval (from DateTime)";
-                    //TODO: Where to move and fix these?
-                    private AMutableInterval aInterval = new AMutableInterval(0L, 0L, (byte) 0);
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.AINTERVAL);
-                    @SuppressWarnings("unchecked")
-                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
-                            .getSerializerDeserializer(BuiltinType.ANULL);
-                    private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();
-
-                    @Override
-                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
-
-                        argOut0.reset();
-                        argOut1.reset();
-                        eval0.evaluate(tuple);
-                        eval1.evaluate(tuple);
-
-                        try {
-
-                            if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG
-                                    || argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_NULL_TYPE_TAG) {
-                                nullSerde.serialize(ANull.NULL, out);
-                                return;
-                            }
-
-                            long intervalStart = 0, intervalEnd = 0;
-
-                            if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
-                                intervalStart = ADateTimeSerializerDeserializer.getChronon(argOut0.getByteArray(), 1);
-                            } else if (argOut0.getByteArray()[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                // start datetime
-                                utf8Ptr.set(argOut0.getByteArray(), 1, argOut0.getLength() - 1);
-
-                                int stringLength = utf8Ptr.getUTF8Length();
-                                // get offset for time part: +1 if it is negative (-)
-                                int startOffset = utf8Ptr.getCharStartOffset();
-                                short timeOffset = (short) ((argOut0.getByteArray()[startOffset] == '-') ? 1 : 0);
-                                timeOffset += 8;
-                                if (argOut0.getByteArray()[startOffset + timeOffset] != 'T') {
-                                    timeOffset += 2;
-                                    if (argOut0.getByteArray()[startOffset + timeOffset] != 'T') {
-                                        throw new AlgebricksException(errorMessage + ": missing T");
-                                    }
-                                }
-                                intervalStart = ADateParserFactory.parseDatePart(argOut0.getByteArray(), startOffset,
-                                        timeOffset);
-                                intervalStart += ATimeParserFactory.parseTimePart(argOut0.getByteArray(),
-                                        startOffset + timeOffset + 1, stringLength - timeOffset - 1);
-                            } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/STRING/DATETIME for the first argument, but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0]));
-                            }
-
-                            if (argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_DATETIME_TYPE_TAG) {
-                                intervalEnd = ADateTimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
-                            } else if (argOut1.getByteArray()[0] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
-                                // start datetime
-                                utf8Ptr.set(argOut1.getByteArray(), 1, argOut1.getLength() - 1);
-                                int stringLength = utf8Ptr.getUTF8Length();
-                                // get offset for time part: +1 if it is negative (-)
-                                int startOffset = utf8Ptr.getCharStartOffset();
-                                short timeOffset = (short) ((argOut1.getByteArray()[startOffset] == '-') ? 1 : 0);
-                                timeOffset += 8;
-                                if (argOut1.getByteArray()[startOffset + timeOffset] != 'T') {
-                                    timeOffset += 2;
-                                    if (argOut1.getByteArray()[startOffset + timeOffset] != 'T') {
-                                        throw new AlgebricksException(errorMessage + ": missing T");
-                                    }
-                                }
-                                intervalEnd = ADateParserFactory.parseDatePart(argOut1.getByteArray(), startOffset,
-                                        timeOffset);
-                                intervalEnd += ATimeParserFactory.parseTimePart(argOut1.getByteArray(),
-                                        startOffset + timeOffset + 1, stringLength - timeOffset - 1);
-                            } else {
-                                throw new AlgebricksException(FID.getName()
-                                        + ": expects NULL/STRING/DATETIME for the second argument, but got "
-                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut1.getByteArray()[0]));
-                            }
-
-                            if (intervalEnd < intervalStart) {
-                                throw new AlgebricksException(
-                                        FID.getName() + ": interval end must not be less than the interval start.");
-                            }
-
-                            aInterval.setValue(intervalStart, intervalEnd, ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
-                            intervalSerde.serialize(aInterval, out);
-
-                        } catch (IOException e1) {
-                            throw new AlgebricksException(errorMessage);
-                        } catch (Exception e2) {
-                            throw new AlgebricksException(e2);
-                        }
-                    }
-                };
-            }
-        };
-    }
-
-    @Override
-    public FunctionIdentifier getIdentifier() {
-        return FID;
-    }
-
-}
\ No newline at end of file


Mime
View raw message