asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ima...@apache.org
Subject [55/58] [abbrv] incubator-asterixdb git commit: Temporal update based on a merge from an old branch.
Date Fri, 24 Apr 2015 18:43:21 GMT
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
index 9b17c90..04a61a5 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
@@ -18,7 +18,9 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADayTimeDurationSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AYearMonthDurationSerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.AInterval;
 import edu.uci.ics.asterix.om.base.AMutableDuration;
@@ -53,6 +55,8 @@ public class AIntervalStartFromDateConstructorDescriptor extends AbstractScalarF
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final static byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
     private final static byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
+    private final static byte SER_YEAR_MONTH_DURATION_TYPE_TAG = ATypeTag.YEARMONTHDURATION.serialize();
+    private final static byte SER_DAY_TIME_DURATION_TYPE_TAG = ATypeTag.DAYTIMEDURATION.serialize();
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -123,6 +127,14 @@ public class AIntervalStartFromDateConstructorDescriptor extends AbstractScalarF
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
                                         ADurationSerializerDeserializer.getYearMonth(argOut1.getByteArray(), 1),
                                         ADurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1), false);
+                            } else if (argOut1.getByteArray()[0] == SER_DAY_TIME_DURATION_TYPE_TAG) {
+                                intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
+                                        0,
+                                        ADayTimeDurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1), false);
+                            } else if (argOut1.getByteArray()[0] == SER_YEAR_MONTH_DURATION_TYPE_TAG) {
+                                intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
+                                        AYearMonthDurationSerializerDeserializer.getYearMonth(argOut1.getByteArray(), 1),
+                                        0, false);
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
                                 // duration
                                 int stringLength = (argOut1.getByteArray()[1] & 0xff << 8)

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
index ce4681a..8191a98 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
@@ -18,7 +18,9 @@ import java.io.DataOutput;
 import java.io.IOException;
 
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADayTimeDurationSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AYearMonthDurationSerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
 import edu.uci.ics.asterix.om.base.AInterval;
 import edu.uci.ics.asterix.om.base.AMutableDuration;
@@ -53,6 +55,8 @@ public class AIntervalStartFromDateTimeConstructorDescriptor extends AbstractSca
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final static byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
     private final static byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
+    private final static byte SER_DAY_TIME_DURATION_TYPE_TAG = ATypeTag.DAYTIMEDURATION.serialize();
+    private final static byte SER_YEAR_MONTH_DURATION_TYPE_TAG = ATypeTag.YEARMONTHDURATION.serialize();
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -135,6 +139,16 @@ public class AIntervalStartFromDateTimeConstructorDescriptor extends AbstractSca
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart,
                                         ADurationSerializerDeserializer.getYearMonth(argOut1.getByteArray(), 1),
                                         ADurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1), false);
+                            } else if (argOut1.getByteArray()[0] == SER_YEAR_MONTH_DURATION_TYPE_TAG) {
+                                intervalEnd = DurationArithmeticOperations
+                                        .addDuration(
+                                                intervalStart,
+                                                AYearMonthDurationSerializerDeserializer.getYearMonth(
+                                                        argOut1.getByteArray(), 1), 0, false);
+                            } else if (argOut1.getByteArray()[0] == SER_DAY_TIME_DURATION_TYPE_TAG) {
+                                intervalEnd = DurationArithmeticOperations.addDuration(intervalStart, 0,
+                                        ADayTimeDurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1),
+                                        false);
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
 
                                 // duration

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
index d4168e1..2e52e9c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromTimeConstructorDescriptor.java
@@ -17,6 +17,7 @@ package edu.uci.ics.asterix.runtime.evaluators.constructors;
 import java.io.DataOutput;
 import java.io.IOException;
 
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADayTimeDurationSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
 import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
 import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -53,6 +54,7 @@ public class AIntervalStartFromTimeConstructorDescriptor extends AbstractScalarF
     private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
     private final static byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
     private final static byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
+    private final static byte SER_DAY_TIME_DURATION_TYPE_TAG = ATypeTag.DAYTIMEDURATION.serialize();
 
     public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
         public IFunctionDescriptor createFunctionDescriptor() {
@@ -132,6 +134,12 @@ public class AIntervalStartFromTimeConstructorDescriptor extends AbstractScalarF
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart, 0,
                                         ADurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1), false);
 
+                            } else if (argOut1.getByteArray()[0] == SER_DAY_TIME_DURATION_TYPE_TAG) {
+
+                                intervalEnd = DurationArithmeticOperations.addDuration(intervalStart, 0,
+                                        ADayTimeDurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1),
+                                        false);
+
                             } else if (argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
                                 // duration
 
@@ -149,7 +157,7 @@ public class AIntervalStartFromTimeConstructorDescriptor extends AbstractScalarF
                                 intervalEnd = DurationArithmeticOperations.addDuration(intervalStart, 0,
                                         aDuration.getMilliseconds(), false);
                             } else {
-                                throw new AlgebricksException("Wrong format for interval constructor from dates.");
+                                throw new AlgebricksException("Wrong format for interval constructor from time.");
                             }
 
                             if (intervalEnd > GregorianCalendarSystem.CHRONON_OF_DAY) {

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
index a5afc65..e21d7d8 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractQuadStringStringEval.java
@@ -85,23 +85,20 @@ public abstract class AbstractQuadStringStringEval implements ICopyEvaluator {
         eval3.evaluate(tuple);
 
         try {
-            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG || array1.getByteArray()[0] == SER_NULL_TYPE_TAG
+                    || array2.getByteArray()[0] == SER_NULL_TYPE_TAG || array3.getByteArray()[0] == SER_NULL_TYPE_TAG) {
                 nullSerde.serialize(ANull.NULL, dout);
                 return;
-            } else if (array0.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                if ((array1.getByteArray()[0] != SER_STRING_TYPE_TAG && array1.getByteArray()[0] != SER_NULL_TYPE_TAG)
-                        || (array2.getByteArray()[0] != SER_STRING_TYPE_TAG && array2.getByteArray()[0] != SER_NULL_TYPE_TAG)
-                        || (array3.getByteArray()[0] != SER_STRING_TYPE_TAG && array3.getByteArray()[0] != SER_NULL_TYPE_TAG)) {
-                    throw new AlgebricksException(funcID.getName()
-                            + ": expects input type (STRING/NULL, STRING/NULL, STRING/NULL, STRING/NULL), but got ("
-                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array0.getByteArray()[0]) + ", "
-                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array1.getByteArray()[0]) + ", "
-                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array2.getByteArray()[0]) + ", "
-                            + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array3.getByteArray()[0]) + ".");
-                }
-
-            } else {
-                throw new AlgebricksException("Expects String or NULL Type.");
+            } else if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG
+                    || array1.getByteArray()[0] != SER_STRING_TYPE_TAG
+                    || array2.getByteArray()[0] != SER_STRING_TYPE_TAG
+                    || array3.getByteArray()[0] != SER_STRING_TYPE_TAG) {
+                throw new AlgebricksException(funcID.getName()
+                        + ": expects input type (STRING/NULL, STRING/NULL, STRING/NULL, STRING/NULL), but got ("
+                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array0.getByteArray()[0]) + ", "
+                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array1.getByteArray()[0]) + ", "
+                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array2.getByteArray()[0]) + ", "
+                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array3.getByteArray()[0]) + ".");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
index aabbcb0..4bd068f 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/AbstractTripleStringStringEval.java
@@ -76,22 +76,18 @@ public abstract class AbstractTripleStringStringEval implements ICopyEvaluator {
         eval2.evaluate(tuple);
 
         try {
-            // type-check: (string?, string, string)
-
-            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG) {
-                if (array1.getByteArray()[0] == SER_STRING_TYPE_TAG && array2.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                    nullSerde.serialize(ANull.NULL, dout);
-                    return;
-                }
-            }
-
-            if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG || array1.getByteArray()[0] != SER_STRING_TYPE_TAG
+            if (array0.getByteArray()[0] == SER_NULL_TYPE_TAG || array1.getByteArray()[0] == SER_NULL_TYPE_TAG
+                    || array2.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                nullSerde.serialize(ANull.NULL, dout);
+                return;
+            } else if (array0.getByteArray()[0] != SER_STRING_TYPE_TAG
+                    || array1.getByteArray()[0] != SER_STRING_TYPE_TAG
                     || array2.getByteArray()[0] != SER_STRING_TYPE_TAG) {
                 throw new AlgebricksException(funcID.getName()
-                        + ": expects input type (STRING/NULL, STRING, STRING), but got ("
+                        + ": expects input type (STRING/NULL, STRING/NULL, STRING/NULL), but got ("
                         + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array0.getByteArray()[0]) + ", "
                         + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array1.getByteArray()[0]) + ", "
-                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array2.getByteArray()[0]) + ").");
+                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(array2.getByteArray()[0]) + ".");
             }
         } catch (HyracksDataException e) {
             throw new AlgebricksException(e);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
index cfaed70..4e468d5 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/StringReplaceDescriptor.java
@@ -122,8 +122,9 @@ public class StringReplaceDescriptor extends AbstractScalarFunctionDynamicDescri
                                 astrReplace = (AString) stringSerde.deserialize(di);
                                 replace = astrReplace.getStringValue();
                             }
-                            if (newPattern)
+                            if (newPattern) {
                                 pattern = Pattern.compile(strPattern);
+                            }
                             carSeq.reset(array0, 1);
                             if (newPattern) {
                                 matcher = pattern.matcher(carSeq);

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromIntervalDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromIntervalDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromIntervalDescriptor.java
new file mode 100644
index 0000000..45b7b32
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DurationFromIntervalDescriptor.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ * 
+ *     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 edu.uci.ics.asterix.runtime.evaluators.functions.temporal;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ADayTimeDuration;
+import edu.uci.ics.asterix.om.base.AMutableDayTimeDuration;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class DurationFromIntervalDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    public final static FunctionIdentifier FID = AsterixBuiltinFunctions.DURATION_FROM_INTERVAL;
+
+    // allowed input types
+    private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+    private final static byte SER_INTERVAL_TYPE_TAG = ATypeTag.INTERVAL.serialize();
+
+    public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new DurationFromIntervalDescriptor();
+        }
+
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        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 argOut = new ArrayBackedValueStorage();
+                    private ICopyEvaluator eval = args[0].createEvaluator(argOut);
+
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+
+                    @SuppressWarnings("unchecked")
+                    private ISerializerDeserializer<ADayTimeDuration> dayTimeDurationSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ADAYTIMEDURATION);
+
+                    private AMutableDayTimeDuration aDayTimeDuration = new AMutableDayTimeDuration(0);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut.reset();
+                        eval.evaluate(tuple);
+
+                        try {
+                            if (argOut.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                                nullSerde.serialize(ANull.NULL, out);
+                                return;
+                            } else if (argOut.getByteArray()[0] != SER_INTERVAL_TYPE_TAG) {
+                                throw new AlgebricksException(FID.getName()
+                                        + ": expects INTERVAL/NULL as the input but got "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut.getByteArray()[0]));
+                            }
+                            long chrononStart = AIntervalSerializerDeserializer.getIntervalStart(argOut.getByteArray(),
+                                    1);
+                            long chrononEnd = AIntervalSerializerDeserializer.getIntervalEnd(argOut.getByteArray(), 1);
+                            byte intervalTypeTag = AIntervalSerializerDeserializer.getIntervalTimeType(
+                                    argOut.getByteArray(), 1);
+
+                            if (intervalTypeTag == ATypeTag.DATE.serialize()) {
+                                chrononStart *= GregorianCalendarSystem.CHRONON_OF_DAY;
+                                chrononEnd *= GregorianCalendarSystem.CHRONON_OF_DAY;
+                            }
+
+                            aDayTimeDuration.setMilliseconds(chrononEnd - chrononStart);
+                            dayTimeDurationSerde.serialize(aDayTimeDuration, out);
+
+                        } catch (HyracksDataException hex) {
+                            throw new AlgebricksException(hex);
+                        }
+                    }
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return FID;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/GetOverlappingIntervalDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/GetOverlappingIntervalDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/GetOverlappingIntervalDescriptor.java
new file mode 100644
index 0000000..2cf60ca
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/GetOverlappingIntervalDescriptor.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ * 
+ *     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 edu.uci.ics.asterix.runtime.evaluators.functions.temporal;
+
+import java.io.DataOutput;
+
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AInterval;
+import edu.uci.ics.asterix.om.base.AMutableInterval;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class GetOverlappingIntervalDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+
+    private static final byte SER_INTERVAL_TYPE_TAG = ATypeTag.INTERVAL.serialize();
+    private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new GetOverlappingIntervalDescriptor();
+        }
+    };
+
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        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 final AMutableInterval aInterval = new AMutableInterval(0, 0, (byte) -1);
+
+                    @SuppressWarnings("unchecked")
+                    private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+                    @SuppressWarnings("unchecked")
+                    private final ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINTERVAL);
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut0.reset();
+                        eval0.evaluate(tuple);
+                        argOut1.reset();
+                        eval1.evaluate(tuple);
+
+                        try {
+                            if (argOut0.getByteArray()[0] == SER_NULL_TYPE_TAG
+                                    || argOut1.getByteArray()[0] == SER_NULL_TYPE_TAG) {
+                                nullSerde.serialize(ANull.NULL, out);
+                            } else if (argOut0.getByteArray()[0] == SER_INTERVAL_TYPE_TAG
+                                    && argOut0.getByteArray()[0] == argOut1.getByteArray()[0]) {
+                                byte type0 = AIntervalSerializerDeserializer.getIntervalTimeType(
+                                        argOut0.getByteArray(), 1);
+                                byte type1 = AIntervalSerializerDeserializer.getIntervalTimeType(
+                                        argOut1.getByteArray(), 1);
+                                if (type0 != type1) {
+                                    throw new AlgebricksException(
+                                            getIdentifier().getName()
+                                                    + ": expecting two (nullable) interval values with the same internal time type but got interval of "
+                                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(type0)
+                                                    + " and interval of "
+                                                    + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(type1));
+                                }
+
+                                long start0 = AIntervalSerializerDeserializer.getIntervalStart(argOut0.getByteArray(),
+                                        1);
+                                long end0 = AIntervalSerializerDeserializer.getIntervalEnd(argOut0.getByteArray(), 1);
+
+                                long start1 = AIntervalSerializerDeserializer.getIntervalStart(argOut1.getByteArray(),
+                                        1);
+                                long end1 = AIntervalSerializerDeserializer.getIntervalEnd(argOut1.getByteArray(), 1);
+
+                                if (IntervalLogic.overlap(start0, end0, start1, end1)
+                                        || IntervalLogic.overlappedBy(start0, end0, start1, end1)
+                                        || IntervalLogic.covers(start0, end0, start1, end1)
+                                        || IntervalLogic.coveredBy(start0, end0, start1, end1)) {
+                                    aInterval.setValue(Math.max(start0, start1), Math.min(end0, end1), type0);
+                                    intervalSerde.serialize(aInterval, out);
+                                } else {
+                                    nullSerde.serialize(ANull.NULL, out);
+                                }
+                            } else {
+                                throw new AlgebricksException(getIdentifier().getName()
+                                        + ": expecting two (nullable) interval values but got "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0])
+                                        + " and "
+                                        + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[1]));
+                            }
+                        } catch (HyracksDataException hex) {
+                            throw new AlgebricksException(hex);
+                        }
+                    }
+
+                };
+            }
+        };
+    }
+
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return AsterixBuiltinFunctions.GET_OVERLAPPING_INTERVAL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/IntervalLogic.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/IntervalLogic.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/IntervalLogic.java
index 021de2d..b746ccd 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/IntervalLogic.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/IntervalLogic.java
@@ -91,7 +91,7 @@ public class IntervalLogic {
      * @return
      */
     public static <T extends Comparable<T>> boolean overlap(T s1, T e1, T s2, T e2) {
-        return s1.compareTo(e2) < 0 && s2.compareTo(e1) < 0;
+        return (s2.compareTo(s1) >= 0 && s2.compareTo(e1) < 0) || (e2.compareTo(e1) <= 0 && e2.compareTo(s1) > 0);
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapBinsDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapBinsDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapBinsDescriptor.java
new file mode 100644
index 0000000..e24feed
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapBinsDescriptor.java
@@ -0,0 +1,338 @@
+/*
+ * Copyright 2009-2013 by The Regents of the University of California
+ * Licensed 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 from
+ * 
+ *     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 edu.uci.ics.asterix.runtime.evaluators.functions.temporal;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import edu.uci.ics.asterix.builders.OrderedListBuilder;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADateTimeSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADayTimeDurationSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AIntervalSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ATimeSerializerDeserializer;
+import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AYearMonthDurationSerializerDeserializer;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AInterval;
+import edu.uci.ics.asterix.om.base.AMutableInterval;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.temporal.DurationArithmeticOperations;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.functions.AsterixBuiltinFunctions;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.AOrderedListType;
+import edu.uci.ics.asterix.om.types.ATypeTag;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.EnumDeserializer;
+import edu.uci.ics.asterix.runtime.evaluators.base.AbstractScalarFunctionDynamicDescriptor;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory;
+import edu.uci.ics.hyracks.api.dataflow.value.ISerializerDeserializer;
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.data.std.api.IDataOutputProvider;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class OverlapBinsDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+    private static final long serialVersionUID = 1L;
+    public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+        @Override
+        public IFunctionDescriptor createFunctionDescriptor() {
+            return new OverlapBinsDescriptor();
+        }
+    };
+
+    @Override
+    public ICopyEvaluatorFactory createEvaluatorFactory(final ICopyEvaluatorFactory[] args) throws AlgebricksException {
+        return new ICopyEvaluatorFactory() {
+
+            private static final long serialVersionUID = 1L;
+
+            @Override
+            public ICopyEvaluator createEvaluator(final IDataOutputProvider output) throws AlgebricksException {
+                return new ICopyEvaluator() {
+
+                    private final DataOutput out = output.getDataOutput();
+
+                    private final ArrayBackedValueStorage argOut0 = new ArrayBackedValueStorage();
+                    private final ArrayBackedValueStorage argOut1 = new ArrayBackedValueStorage();
+                    private final ArrayBackedValueStorage argOut2 = new ArrayBackedValueStorage();
+
+                    private final ICopyEvaluator eval0 = args[0].createEvaluator(argOut0);
+                    private final ICopyEvaluator eval1 = args[1].createEvaluator(argOut1);
+                    private final ICopyEvaluator eval2 = args[2].createEvaluator(argOut2);
+
+                    // for output
+                    private OrderedListBuilder listBuilder = new OrderedListBuilder();
+                    private ArrayBackedValueStorage listStorage = new ArrayBackedValueStorage();
+                    protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINTERVAL, null);
+
+                    private final AMutableInterval aInterval = new AMutableInterval(0, 0, (byte) -1);
+
+                    @SuppressWarnings("unchecked")
+                    private final ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.ANULL);
+                    @SuppressWarnings("unchecked")
+                    private final ISerializerDeserializer<AInterval> intervalSerde = AqlSerializerDeserializerProvider.INSTANCE
+                            .getSerializerDeserializer(BuiltinType.AINTERVAL);
+
+                    private final GregorianCalendarSystem GREG_CAL = GregorianCalendarSystem.getInstance();
+
+                    @Override
+                    public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+                        argOut0.reset();
+                        eval0.evaluate(tuple);
+
+                        ATypeTag type0 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0]);
+
+                        long intervalStart = 0, intervalEnd = 0;
+                        byte intervalTypeTag;
+
+                        if (type0 == ATypeTag.INTERVAL) {
+                            intervalStart = AIntervalSerializerDeserializer.getIntervalStart(argOut0.getByteArray(), 1);
+                            intervalEnd = AIntervalSerializerDeserializer.getIntervalEnd(argOut0.getByteArray(), 1);
+                            intervalTypeTag = AIntervalSerializerDeserializer.getIntervalTimeType(
+                                    argOut0.getByteArray(), 1);
+                        } else if (type0 == ATypeTag.NULL) {
+                            try {
+                                nullSerde.serialize(ANull.NULL, out);
+                            } catch (HyracksDataException e) {
+                                throw new AlgebricksException(e);
+                            }
+                            return;
+                        } else {
+                            throw new AlgebricksException(getIdentifier().getName()
+                                    + ": the first argument should be INTERVAL/NULL but got " + type0);
+                        }
+
+                        // get the anchor instance time
+                        argOut1.reset();
+                        eval1.evaluate(tuple);
+
+                        ATypeTag type1 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut1.getByteArray()[0]);
+
+                        if (intervalTypeTag != type1.serialize()) {
+                            if (intervalTypeTag != ATypeTag.NULL.serialize() && type1 != ATypeTag.NULL)
+                                throw new AlgebricksException(getIdentifier().getName()
+                                        + ": expecting compatible type to " + type0 + "(" + intervalTypeTag
+                                        + ") for the second argument but got " + type1);
+                        }
+
+                        long anchorTime = 0;
+                        switch (type1) {
+                            case DATE:
+                                anchorTime = ADateSerializerDeserializer.getChronon(argOut1.getByteArray(), 1)
+                                        * GregorianCalendarSystem.CHRONON_OF_DAY;
+                                break;
+                            case TIME:
+                                anchorTime = ATimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
+                                break;
+                            case DATETIME:
+                                anchorTime = ADateTimeSerializerDeserializer.getChronon(argOut1.getByteArray(), 1);
+                                break;
+                            case NULL:
+                                try {
+                                    nullSerde.serialize(ANull.NULL, out);
+                                } catch (HyracksDataException e) {
+                                    throw new AlgebricksException(e);
+                                }
+                                return;
+                            default:
+                                throw new AlgebricksException(getIdentifier().getName()
+                                        + ": expecting compatible type to " + type0 + "(" + intervalTypeTag
+                                        + ") for the second argument but got " + type1);
+                        }
+
+                        argOut2.reset();
+                        eval2.evaluate(tuple);
+
+                        ATypeTag type2 = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut2.getByteArray()[0]);
+
+                        int yearMonth = 0;
+                        long dayTime = 0;
+                        long firstBinIndex;
+                        switch (type2) {
+                            case YEARMONTHDURATION:
+                                yearMonth = AYearMonthDurationSerializerDeserializer.getYearMonth(
+                                        argOut2.getByteArray(), 1);
+
+                                int yearStart = GREG_CAL.getYear(anchorTime);
+                                int monthStart = GREG_CAL.getMonthOfYear(anchorTime, yearStart);
+                                int yearToBin = GREG_CAL.getYear(intervalStart);
+                                int monthToBin = GREG_CAL.getMonthOfYear(intervalStart, yearToBin);
+
+                                int totalMonths = (yearToBin - yearStart) * 12 + (monthToBin - monthStart);
+
+                                firstBinIndex = totalMonths / yearMonth
+                                        + ((totalMonths < 0 && totalMonths % yearMonth != 0) ? -1 : 0);
+
+                                if (firstBinIndex > Integer.MAX_VALUE) {
+                                    throw new AlgebricksException(getIdentifier().getName()
+                                            + ": Overflowing time value to be binned!");
+                                }
+
+                                if (firstBinIndex < Integer.MIN_VALUE) {
+                                    throw new AlgebricksException(getIdentifier().getName()
+                                            + ": Underflowing time value to be binned!");
+                                }
+                                break;
+
+                            case DAYTIMEDURATION:
+                                dayTime = ADayTimeDurationSerializerDeserializer.getDayTime(argOut2.getByteArray(), 1);
+
+                                long totalChronon = intervalStart - anchorTime;
+
+                                firstBinIndex = totalChronon / dayTime
+                                        + ((totalChronon < 0 && totalChronon % dayTime != 0) ? -1 : 0);
+                                break;
+
+                            case NULL:
+                                try {
+                                    nullSerde.serialize(ANull.NULL, out);
+                                } catch (HyracksDataException e) {
+                                    throw new AlgebricksException(e);
+                                }
+                                return;
+
+                            default:
+                                throw new AlgebricksException(
+                                        getIdentifier().getName()
+                                                + ": expecting YEARMONTHDURATION/DAYTIMEDURATION for the thrid argument but got "
+                                                + type2);
+                        }
+
+                        long binStartChronon, binEndChronon;
+                        int binOffset;
+
+                        listBuilder.reset(intListType);
+
+                        try {
+                            if (intervalTypeTag == ATypeTag.DATE.serialize()) {
+
+                                binOffset = 0;
+
+                                do {
+                                    binStartChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                            * (int) (firstBinIndex + binOffset), dayTime * (firstBinIndex + binOffset),
+                                            false);
+                                    binEndChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                            * ((int) (firstBinIndex + binOffset) + 1), dayTime
+                                            * ((firstBinIndex + binOffset) + 1), false);
+                                    binStartChronon = binStartChronon
+                                            / GregorianCalendarSystem.CHRONON_OF_DAY
+                                            + ((binStartChronon < 0 && binStartChronon
+                                                    % GregorianCalendarSystem.CHRONON_OF_DAY != 0) ? -1 : 0);
+                                    binEndChronon = binEndChronon
+                                            / GregorianCalendarSystem.CHRONON_OF_DAY
+                                            + ((binEndChronon < 0 && binEndChronon
+                                                    % GregorianCalendarSystem.CHRONON_OF_DAY != 0) ? -1 : 0);
+                                    aInterval.setValue(binStartChronon, binEndChronon, intervalTypeTag);
+                                    listStorage.reset();
+                                    intervalSerde.serialize(aInterval, listStorage.getDataOutput());
+                                    listBuilder.addItem(listStorage);
+                                    binOffset++;
+                                } while (binEndChronon < intervalEnd);
+
+                            } else if (intervalTypeTag == ATypeTag.TIME.serialize()) {
+                                if (yearMonth != 0) {
+                                    throw new AlgebricksException(getIdentifier().getName()
+                                            + ": cannot create year-month bin for a time value");
+                                }
+
+                                binOffset = 0;
+
+                                binStartChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                        * (int) (firstBinIndex + binOffset), dayTime * (firstBinIndex + binOffset),
+                                        true);
+                                binEndChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                        * ((int) (firstBinIndex + binOffset) + 1), dayTime
+                                        * ((firstBinIndex + binOffset) + 1), true);
+
+                                if (binStartChronon < 0 || binStartChronon >= GregorianCalendarSystem.CHRONON_OF_DAY) {
+                                    // avoid the case where a time bin is before 00:00:00 or no early than 24:00:00
+                                    throw new AlgebricksException(
+                                            getIdentifier().getName()
+                                                    + ": reaches a bin with the end earlier than the start; probably the window is beyond the time scope. Maybe use DATETIME?");
+                                }
+
+                                while (!((binStartChronon < intervalStart && binEndChronon <= intervalStart) || (binStartChronon >= intervalEnd && binEndChronon > intervalEnd))) {
+
+                                    aInterval.setValue(binStartChronon, binEndChronon, intervalTypeTag);
+                                    listStorage.reset();
+                                    intervalSerde.serialize(aInterval, listStorage.getDataOutput());
+                                    listBuilder.addItem(listStorage);
+                                    binOffset++;
+                                    binStartChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                            * (int) (firstBinIndex + binOffset), dayTime * (firstBinIndex + binOffset),
+                                            true);
+                                    binEndChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                            * ((int) (firstBinIndex + binOffset) + 1), dayTime
+                                            * ((firstBinIndex + binOffset) + 1), true);
+
+                                    if (binStartChronon == GregorianCalendarSystem.CHRONON_OF_DAY) {
+                                        break;
+                                    }
+
+                                    if (binEndChronon < binStartChronon) {
+                                        throw new AlgebricksException(
+                                                getIdentifier().getName()
+                                                        + ": reaches a bin with the end earlier than the start; probably the window is beyond the time scope. Maybe use DATETIME?");
+                                    }
+                                }
+                            } else if (intervalTypeTag == ATypeTag.DATETIME.serialize()) {
+                                binOffset = 0;
+                                do {
+                                    binStartChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                            * (int) (firstBinIndex + binOffset), dayTime * (firstBinIndex + binOffset),
+                                            false);
+                                    binEndChronon = DurationArithmeticOperations.addDuration(anchorTime, yearMonth
+                                            * ((int) (firstBinIndex + binOffset) + 1), dayTime
+                                            * ((firstBinIndex + binOffset) + 1), false);
+                                    aInterval.setValue(binStartChronon, binEndChronon, intervalTypeTag);
+                                    listStorage.reset();
+                                    intervalSerde.serialize(aInterval, listStorage.getDataOutput());
+                                    listBuilder.addItem(listStorage);
+                                    binOffset++;
+                                } while (binEndChronon < intervalEnd);
+                            } else {
+                                throw new AlgebricksException(getIdentifier().getName()
+                                        + ": the first argument should be DATE/TIME/DATETIME/NULL but got " + type0);
+                            }
+
+                            listBuilder.write(out, true);
+                        } catch (IOException e1) {
+                            throw new AlgebricksException(e1.getMessage());
+                        }
+
+                    }
+                };
+            }
+        };
+    }
+
+    /* (non-Javadoc)
+     * @see edu.uci.ics.asterix.om.functions.AbstractFunctionDescriptor#getIdentifier()
+     */
+    @Override
+    public FunctionIdentifier getIdentifier() {
+        return AsterixBuiltinFunctions.OVERLAP_BINS;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapDescriptor.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapDescriptor.java
index 927cea1..bc9c980 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/OverlapDescriptor.java
@@ -22,7 +22,7 @@ import edu.uci.ics.hyracks.algebricks.core.algebra.functions.FunctionIdentifier;
 public class OverlapDescriptor extends AbstractIntervalLogicFuncDescriptor {
 
     private final static long serialVersionUID = 1L;
-    public final static FunctionIdentifier FID = AsterixBuiltinFunctions.OVERLAP;
+    public final static FunctionIdentifier FID = AsterixBuiltinFunctions.INTERVAL_OVERLAPPING;
 
     public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
 

http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/4a9a7d99/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
----------------------------------------------------------------------
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
index 8fda408..3871aef 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/formats/NonTaggedDataFormat.java
@@ -120,7 +120,13 @@ import edu.uci.ics.asterix.runtime.evaluators.accessors.PointYCoordinateAccessor
 import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalDayAccessor;
 import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalHourAccessor;
 import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalEndAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalEndDateAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalEndDatetimeAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalEndTimeAccessor;
 import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalStartAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalStartDateAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalStartDatetimeAccessor;
+import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalIntervalStartTimeAccessor;
 import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalMillisecondAccessor;
 import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalMinuteAccessor;
 import edu.uci.ics.asterix.runtime.evaluators.accessors.TemporalMonthAccessor;
@@ -271,9 +277,11 @@ import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DatetimeFromUni
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DayOfWeekDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DayTimeDurationComparatorDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DurationEqualDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DurationFromIntervalDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DurationFromMillisecondsDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DurationFromMonthsDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.GetDayTimeDurationDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.GetOverlappingIntervalDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.GetYearMonthDurationDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.IntervalAfterDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.IntervalBeforeDescriptor;
@@ -290,6 +298,7 @@ import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.IntervalStarted
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.IntervalStartsDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.MillisecondsFromDayTimeDurationDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.MonthsFromYearMonthDurationDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.OverlapBinsDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.OverlapDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.ParseDateDescriptor;
 import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.ParseDateTimeDescriptor;
@@ -603,6 +612,12 @@ public class NonTaggedDataFormat implements IDataFormat {
         temp.add(TemporalMillisecondAccessor.FACTORY);
         temp.add(TemporalIntervalStartAccessor.FACTORY);
         temp.add(TemporalIntervalEndAccessor.FACTORY);
+        temp.add(TemporalIntervalStartDateAccessor.FACTORY);
+        temp.add(TemporalIntervalEndDateAccessor.FACTORY);
+        temp.add(TemporalIntervalStartTimeAccessor.FACTORY);
+        temp.add(TemporalIntervalEndTimeAccessor.FACTORY);
+        temp.add(TemporalIntervalStartDatetimeAccessor.FACTORY);
+        temp.add(TemporalIntervalEndDatetimeAccessor.FACTORY);
 
         // Temporal functions
         temp.add(DateFromUnixTimeInDaysDescriptor.FACTORY);
@@ -644,6 +659,7 @@ public class NonTaggedDataFormat implements IDataFormat {
         temp.add(GetYearMonthDurationDescriptor.FACTORY);
         temp.add(GetDayTimeDurationDescriptor.FACTORY);
         temp.add(IntervalBinDescriptor.FACTORY);
+        temp.add(OverlapBinsDescriptor.FACTORY);
         temp.add(DayOfWeekDescriptor.FACTORY);
         temp.add(ParseDateDescriptor.FACTORY);
         temp.add(ParseTimeDescriptor.FACTORY);
@@ -651,6 +667,8 @@ public class NonTaggedDataFormat implements IDataFormat {
         temp.add(PrintDateDescriptor.FACTORY);
         temp.add(PrintTimeDescriptor.FACTORY);
         temp.add(PrintDateTimeDescriptor.FACTORY);
+        temp.add(GetOverlappingIntervalDescriptor.FACTORY);
+        temp.add(DurationFromIntervalDescriptor.FACTORY);
 
         // Interval constructor
         temp.add(AIntervalFromDateConstructorDescriptor.FACTORY);
@@ -1056,12 +1074,13 @@ public class NonTaggedDataFormat implements IDataFormat {
 
     @Override
     public ITupleParserFactory createTupleParser(ARecordType recType, IParseFileSplitsDecl decl) {
-        return createTupleParser(recType, decl.isDelimitedFileFormat(), decl.getDelimChar(), decl.getQuote(), decl.getHasHeader());
+        return createTupleParser(recType, decl.isDelimitedFileFormat(), decl.getDelimChar(), decl.getQuote(),
+                decl.getHasHeader());
     }
 
     @Override
     public ITupleParserFactory createTupleParser(ARecordType recType, boolean delimitedFormat, char delimiter,
-                                                 char quote, boolean hasHeader) {
+            char quote, boolean hasHeader) {
         if (delimitedFormat) {
             int n = recType.getFieldTypes().length;
             IValueParserFactory[] fieldParserFactories = new IValueParserFactory[n];


Mime
View raw message