Added interval start and end time accessors, with test cases; minor fix for the other temporal accessors.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_lsm_stabilization_interval_leftover@1666 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.1.ddl.aql
new file mode 100644
index 0000000..e6a3879
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.1.ddl.aql
@@ -0,0 +1,2 @@
+drop dataverse test if exists;
+create dataverse test;
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.3.query.aql
new file mode 100644
index 0000000..b703377
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval/accessors_interval.3.query.aql
@@ -0,0 +1,7 @@
+use dataverse test;
+
+let $interval1 := interval-from-date(date("2010-10-30"), "2013-04-01")
+let $interval2 := interval-from-time("08:09:10.234Z", time("203040567+0800"))
+let $interval3 := interval-from-datetime("2009-09-01T00:00:00.000+08:00", datetime-from-date-time(date("2013-04-04"), time("00:00:00.000+08:00")))
+
+return {"start1": get-interval-start($interval1), "end1": get-interval-end($interval1), "start2": get-interval-start($interval2), "end2": get-interval-end($interval2), "start3": get-interval-start($interval3), "end3": get-interval-end($interval3) }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.1.ddl.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.1.ddl.aql
new file mode 100644
index 0000000..e6a3879
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.1.ddl.aql
@@ -0,0 +1,2 @@
+drop dataverse test if exists;
+create dataverse test;
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.2.update.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.2.update.aql
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.2.update.aql
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.3.query.aql
new file mode 100644
index 0000000..98bead8
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/accessors_interval_null/accessors_interval_null.3.query.aql
@@ -0,0 +1,3 @@
+use dataverse test;
+
+{"start-null-interval": get-interval-start(null), "end-null-interval": get-interval-end(null) }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/temporal/accessors_interval/accessors_interval.1.adm b/asterix-app/src/test/resources/runtimets/results/temporal/accessors_interval/accessors_interval.1.adm
new file mode 100644
index 0000000..df34c86
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/temporal/accessors_interval/accessors_interval.1.adm
@@ -0,0 +1 @@
+{ "start1": date("2010-10-30"), "end1": date("2013-04-01"), "start2": time("08:09:10.234Z"), "end2": time("12:30:40.567Z"), "start3": datetime("2009-08-31T16:00:00.000Z"), "end3": datetime("2013-04-04T16:00:00.000Z") }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/temporal/accessors_interval_null/accessors_interval_null.1.adm b/asterix-app/src/test/resources/runtimets/results/temporal/accessors_interval_null/accessors_interval_null.1.adm
new file mode 100644
index 0000000..7a50c5f
--- /dev/null
+++ b/asterix-app/src/test/resources/runtimets/results/temporal/accessors_interval_null/accessors_interval_null.1.adm
@@ -0,0 +1 @@
+{ "start-null-interval": null, "end-null-interval": null }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/testsuite.xml b/asterix-app/src/test/resources/runtimets/testsuite.xml
index b730b41..655e17f 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -4125,11 +4125,21 @@
</test-case>
</test-group>
<test-group name="temporal">
- <test-case FilePath="temporal">
- <compilation-unit name="accessors">
+ <test-case FilePath="temporal">
+ <compilation-unit name="accessors">
<output-dir compare="Text">accessors</output-dir>
</compilation-unit>
- </test-case>
+ </test-case>
+ <test-case FilePath="temporal">
+ <compilation-unit name="accessors_interval">
+ <output-dir compare="Text">accessors_interval</output-dir>
+ </compilation-unit>
+ </test-case>
+ <test-case FilePath="temporal">
+ <compilation-unit name="accessors_interval_null">
+ <output-dir compare="Text">accessors_interval_null</output-dir>
+ </compilation-unit>
+ </test-case>
<test-case FilePath="temporal">
<compilation-unit name="adjust_timezone">
<output-dir compare="Text">adjust_timezone</output-dir>
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
index 24649d9..fa3179a 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/functions/AsterixBuiltinFunctions.java
@@ -61,6 +61,7 @@
import edu.uci.ics.asterix.om.typecomputer.impl.OptionalAPolygonTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.OptionalARectangleTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.OptionalAStringTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.OptionalATemporalInstanceTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.OptionalATimeTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListConstructorResultType;
import edu.uci.ics.asterix.om.typecomputer.impl.OrderedListOfAInt32TypeComputer;
@@ -459,6 +460,10 @@
"second", 1);
public static final FunctionIdentifier ACCESSOR_TEMPORAL_MILLISEC = new FunctionIdentifier(
FunctionConstants.ASTERIX_NS, "millisecond", 1);
+ public static final FunctionIdentifier ACCESSOR_TEMPORAL_INTERVAL_START = new FunctionIdentifier(
+ FunctionConstants.ASTERIX_NS, "get-interval-start", 1);
+ public static final FunctionIdentifier ACCESSOR_TEMPORAL_INTERVAL_END = new FunctionIdentifier(
+ FunctionConstants.ASTERIX_NS, "get-interval-end", 1);
// Temporal functions
public static final FunctionIdentifier DATE_FROM_UNIX_TIME_IN_DAYS = new FunctionIdentifier(
@@ -774,6 +779,8 @@
add(ACCESSOR_TEMPORAL_MIN, OptionalAInt32TypeComputer.INSTANCE);
add(ACCESSOR_TEMPORAL_SEC, OptionalAInt32TypeComputer.INSTANCE);
add(ACCESSOR_TEMPORAL_MILLISEC, OptionalAInt32TypeComputer.INSTANCE);
+ add(ACCESSOR_TEMPORAL_INTERVAL_START, OptionalATemporalInstanceTypeComputer.INSTANCE);
+ add(ACCESSOR_TEMPORAL_INTERVAL_END, OptionalATemporalInstanceTypeComputer.INSTANCE);
// temporal functions
add(DATE_FROM_UNIX_TIME_IN_DAYS, OptionalADateTypeComputer.INSTANCE);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalATemporalInstanceTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalATemporalInstanceTypeComputer.java
new file mode 100644
index 0000000..eda385f
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/OptionalATemporalInstanceTypeComputer.java
@@ -0,0 +1,50 @@
+/*
+ * 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.om.typecomputer.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+import edu.uci.ics.asterix.om.types.AUnionType;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+import edu.uci.ics.asterix.om.types.IAType;
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression;
+import edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
+import edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+
+public class OptionalATemporalInstanceTypeComputer implements IResultTypeComputer {
+
+ public static final OptionalATemporalInstanceTypeComputer INSTANCE = new OptionalATemporalInstanceTypeComputer();
+
+ private OptionalATemporalInstanceTypeComputer() {
+ }
+
+ /* (non-Javadoc)
+ * @see edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer#computeType(edu.uci.ics.hyracks.algebricks.core.algebra.base.ILogicalExpression, edu.uci.ics.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment, edu.uci.ics.hyracks.algebricks.core.algebra.metadata.IMetadataProvider)
+ */
+ @Override
+ public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+ IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+ List<IAType> unionList = new ArrayList<IAType>();
+ unionList.add(BuiltinType.ANULL);
+ unionList.add(BuiltinType.ADATE);
+ unionList.add(BuiltinType.ATIME);
+ unionList.add(BuiltinType.ADATETIME);
+ return new AUnionType(unionList, "OptionalTemporalInstance");
+ }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java
index 05391de..6b7a9d2 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalDayAccessor.java
@@ -17,7 +17,6 @@
import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
@@ -26,6 +25,7 @@
import edu.uci.ics.asterix.om.base.AMutableInt32;
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;
@@ -44,7 +44,7 @@
private static final long serialVersionUID = 1L;
- private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "day", 1);
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_DAY;
// allowed input types
private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java
index eba012f..38e83db 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalHourAccessor.java
@@ -17,7 +17,6 @@
import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
@@ -26,6 +25,7 @@
import edu.uci.ics.asterix.om.base.AMutableInt32;
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;
@@ -44,7 +44,7 @@
private static final long serialVersionUID = 1L;
- private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "hour", 1);
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_HOUR;
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalIntervalEndAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalIntervalEndAccessor.java
new file mode 100644
index 0000000..e8ea6d5
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalIntervalEndAccessor.java
@@ -0,0 +1,142 @@
+/*
+ * 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.accessors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+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.ADate;
+import edu.uci.ics.asterix.om.base.ADateTime;
+import edu.uci.ics.asterix.om.base.AMutableDate;
+import edu.uci.ics.asterix.om.base.AMutableDateTime;
+import edu.uci.ics.asterix.om.base.AMutableTime;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.ATime;
+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.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 TemporalIntervalEndAccessor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_INTERVAL_END;
+
+ private static final byte SER_INTERVAL_TYPE_TAG = ATypeTag.INTERVAL.serialize();
+ private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
+ private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
+ private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new TemporalIntervalEndAccessor();
+ }
+ };
+
+ 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);
+
+ // possible output
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ADate> dateSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADATE);
+ private AMutableDate aDate = new AMutableDate(0);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ADateTime> datetimeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADATETIME);
+ private AMutableDateTime aDateTime = new AMutableDateTime(0);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ATime> timeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ATIME);
+ private AMutableTime aTime = new AMutableTime(0);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ argOut.reset();
+ eval.evaluate(tuple);
+ byte[] bytes = argOut.getByteArray();
+
+ try {
+ if (bytes[0] == SER_NULL_TYPE_TAG) {
+ nullSerde.serialize(ANull.NULL, out);
+ return;
+ } else if (bytes[0] == SER_INTERVAL_TYPE_TAG) {
+ byte timeType = AIntervalSerializerDeserializer.getIntervalTimeType(bytes, 1);
+ long endTime = AIntervalSerializerDeserializer.getIntervalEnd(bytes, 1);
+ if (timeType == SER_DATE_TYPE_TAG) {
+ aDate.setValue((int) (endTime));
+ dateSerde.serialize(aDate, out);
+ } else if (timeType == SER_TIME_TYPE_TAG) {
+ aTime.setValue((int) (endTime));
+ timeSerde.serialize(aTime, out);
+ } else if (timeType == SER_DATETIME_TYPE_TAG) {
+ aDateTime.setValue(endTime);
+ datetimeSerde.serialize(aDateTime, out);
+ }
+ } else {
+ throw new AlgebricksException(FID.getName() + ": expects NULL/INTERVAL, but got "
+ + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[0]));
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see edu.uci.ics.asterix.om.functions.AbstractFunctionDescriptor#getIdentifier()
+ */
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalIntervalStartAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalIntervalStartAccessor.java
new file mode 100644
index 0000000..ef76934
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalIntervalStartAccessor.java
@@ -0,0 +1,142 @@
+/*
+ * 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.accessors;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+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.ADate;
+import edu.uci.ics.asterix.om.base.ADateTime;
+import edu.uci.ics.asterix.om.base.AMutableDate;
+import edu.uci.ics.asterix.om.base.AMutableDateTime;
+import edu.uci.ics.asterix.om.base.AMutableTime;
+import edu.uci.ics.asterix.om.base.ANull;
+import edu.uci.ics.asterix.om.base.ATime;
+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.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 TemporalIntervalStartAccessor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_INTERVAL_START;
+
+ private static final byte SER_INTERVAL_TYPE_TAG = ATypeTag.INTERVAL.serialize();
+ private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
+
+ private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
+ private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
+ private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+
+ public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new TemporalIntervalStartAccessor();
+ }
+ };
+
+ 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);
+
+ // possible output
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ADate> dateSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADATE);
+ private AMutableDate aDate = new AMutableDate(0);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ADateTime> datetimeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADATETIME);
+ private AMutableDateTime aDateTime = new AMutableDateTime(0);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ATime> timeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ATIME);
+ private AMutableTime aTime = new AMutableTime(0);
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ANull> nullSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ANULL);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ argOut.reset();
+ eval.evaluate(tuple);
+ byte[] bytes = argOut.getByteArray();
+
+ try {
+ if (bytes[0] == SER_NULL_TYPE_TAG) {
+ nullSerde.serialize(ANull.NULL, out);
+ return;
+ } else if (bytes[0] == SER_INTERVAL_TYPE_TAG) {
+ byte timeType = AIntervalSerializerDeserializer.getIntervalTimeType(bytes, 1);
+ long startTime = AIntervalSerializerDeserializer.getIntervalStart(bytes, 1);
+ if (timeType == SER_DATE_TYPE_TAG) {
+ aDate.setValue((int) (startTime));
+ dateSerde.serialize(aDate, out);
+ } else if (timeType == SER_TIME_TYPE_TAG) {
+ aTime.setValue((int) (startTime));
+ timeSerde.serialize(aTime, out);
+ } else if (timeType == SER_DATETIME_TYPE_TAG) {
+ aDateTime.setValue(startTime);
+ datetimeSerde.serialize(aDateTime, out);
+ }
+ } else {
+ throw new AlgebricksException(FID.getName() + ": expects NULL/INTERVAL, but got "
+ + EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(bytes[0]));
+ }
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see edu.uci.ics.asterix.om.functions.AbstractFunctionDescriptor#getIdentifier()
+ */
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java
index ecc1a35..0d6e99b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMillisecondAccessor.java
@@ -17,7 +17,6 @@
import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
@@ -26,6 +25,7 @@
import edu.uci.ics.asterix.om.base.AMutableInt32;
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;
@@ -44,7 +44,7 @@
private static final long serialVersionUID = 1L;
- private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "millisecond", 1);
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_MILLISEC;
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java
index f436016..b61c843 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMinuteAccessor.java
@@ -17,7 +17,6 @@
import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
@@ -26,6 +25,7 @@
import edu.uci.ics.asterix.om.base.AMutableInt32;
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;
@@ -44,7 +44,7 @@
private static final long serialVersionUID = 1L;
- private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "minute", 1);
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_MIN;
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java
index fb68f7d..b18afe3 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalMonthAccessor.java
@@ -17,7 +17,6 @@
import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
@@ -26,6 +25,7 @@
import edu.uci.ics.asterix.om.base.AMutableInt32;
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;
@@ -44,7 +44,7 @@
private static final long serialVersionUID = 1L;
- private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "month", 1);
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_MONTH;
// allowed input types
private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java
index 3b9ee95..8a2f240 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalSecondAccessor.java
@@ -17,7 +17,6 @@
import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
@@ -26,6 +25,7 @@
import edu.uci.ics.asterix.om.base.AMutableInt32;
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;
@@ -44,7 +44,7 @@
private static final long serialVersionUID = 1L;
- private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "second", 1);
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_SEC;
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java
index 41dacfd..a940500 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/accessors/TemporalYearAccessor.java
@@ -17,7 +17,6 @@
import java.io.DataOutput;
import java.io.IOException;
-import edu.uci.ics.asterix.common.functions.FunctionConstants;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.ADurationSerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt32SerializerDeserializer;
import edu.uci.ics.asterix.dataflow.data.nontagged.serde.AInt64SerializerDeserializer;
@@ -26,6 +25,7 @@
import edu.uci.ics.asterix.om.base.AMutableInt32;
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;
@@ -45,7 +45,7 @@
private static final long serialVersionUID = 1L;
- private static final FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "year", 1);
+ private static final FunctionIdentifier FID = AsterixBuiltinFunctions.ACCESSOR_TEMPORAL_YEAR;
// allowed input types
private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
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 f12ea91..a61208d 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
@@ -69,6 +69,8 @@
import edu.uci.ics.asterix.runtime.aggregates.stream.NonEmptyStreamAggregateDescriptor;
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.TemporalIntervalStartAccessor;
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;
@@ -464,6 +466,8 @@
temp.add(TemporalMinuteAccessor.FACTORY);
temp.add(TemporalSecondAccessor.FACTORY);
temp.add(TemporalMillisecondAccessor.FACTORY);
+ temp.add(TemporalIntervalStartAccessor.FACTORY);
+ temp.add(TemporalIntervalEndAccessor.FACTORY);
// Temporal functions
temp.add(DateFromUnixTimeInDaysDescriptor.FACTORY);