added current time/date/datetime functions; added duration support for all temporal accessors.
git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_temporal_functionality@1064 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/temp/accessors.aql b/asterix-app/src/test/resources/runtimets/queries/temp/accessors.aql
index dbf16ba..9cc9f8d 100644
--- a/asterix-app/src/test/resources/runtimets/queries/temp/accessors.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/temp/accessors.aql
@@ -17,5 +17,6 @@
let $c5 := datetime("19371229T20030628")
let $c6 := time("12:23:34.930+07:00")
let $c7 := string("-0003-01-09T23:12:12.39-07:00")
+let $c8 := duration("P3Y73M632DT49H743M3948.94S")
-return {"year1": year($c1), "year2": year($c2), "year3": year($c3), "year4": year($c4), "year5": year($c5), "year6": year($c7), "month1": month($c1), "month2": month($c2), "month3": month($c3), "month4": month($c4), "month5": month($c5), "day1": day($c1), "day2": day($c2), "day3": day($c3), "day4": day($c4), "day5": day($c5), "hour1": hour($c2), "hour2": hour($c5), "hour3": hour($c6), "min1": minute($c2), "min2": minute($c5), "min3": minute($c6), "second1": second($c2), "second2": second($c5), "second3": second($c6), "ms1": millisecond($c2), "ms2": millisecond($c5), "ms3": millisecond($c6)}
+return {"year1": year($c1), "year2": year($c2), "year3": year($c3), "year4": year($c4), "year5": year($c5), "year6": year($c7), "year7": year($c8), "month1": month($c1), "month2": month($c2), "month3": month($c3), "month4": month($c4), "month5": month($c5), "month6": month($c8), "day1": day($c1), "day2": day($c2), "day3": day($c3), "day4": day($c4), "day5": day($c5), "day6": day($c8), "hour1": hour($c2), "hour2": hour($c5), "hour3": hour($c6), "hour4": hour($c8), "min1": minute($c2), "min2": minute($c5), "min3": minute($c6), "min4": minute($c8), "second1": second($c2), "second2": second($c5), "second3": second($c6), "second4": second($c8), "ms1": millisecond($c2), "ms2": millisecond($c5), "ms3": millisecond($c6), "ms4": millisecond($c8)}
diff --git a/asterix-app/src/test/resources/runtimets/queries/temp/time_functions.aql b/asterix-app/src/test/resources/runtimets/queries/temp/time_functions.aql
index 1589cb1..4ce2ec4 100644
--- a/asterix-app/src/test/resources/runtimets/queries/temp/time_functions.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/temp/time_functions.aql
@@ -21,5 +21,8 @@
let $t5 := add_time_duration($t2, $dr2)
let $dr3 := subtract_time($t5, $t2)
let $dr4 := subtract_time($t4, $t1)
+let $ct := current_time()
+let $cd := current_date()
+let $cdt := current_datetime()
return { "time1" : $t1, "time2" : $t2, "time3" : $t3, "time4" : $t4, "time5" : $t5, "duration1" : $dr3, "duration2" : $dr4 }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/temp/accessors.adm b/asterix-app/src/test/resources/runtimets/results/temp/accessors.adm
index 635c8c0..4f36f91 100644
--- a/asterix-app/src/test/resources/runtimets/results/temp/accessors.adm
+++ b/asterix-app/src/test/resources/runtimets/results/temp/accessors.adm
@@ -1 +1 @@
-{ "year1": 2010, "year2": 1987, "year3": -1987, "year4": 928, "year5": 1937, "year6": -3, "month1": 10, "month2": 11, "month3": 11, "month4": 3, "month5": 12, "day1": 30, "day2": 19, "day3": 19, "day4": 29, "day5": 29, "hour1": 23, "hour2": 20, "hour3": 5, "min1": 49, "min2": 3, "min3": 23, "second1": 23, "second2": 6, "second3": 34, "ms1": 938, "ms2": 280, "ms3": 930 }
\ No newline at end of file
+{ "year1": 2010, "year2": 1987, "year3": -1987, "year4": 928, "year5": 1937, "year6": -3, "year7": 9, "month1": 10, "month2": 11, "month3": 11, "month4": 3, "month5": 12, "month6": 1, "day1": 30, "day2": 19, "day3": 19, "day4": 29, "day5": 29, "day6": 634, "hour1": 23, "hour2": 20, "hour3": 5, "hour4": 14, "min1": 49, "min2": 3, "min3": 23, "min4": 28, "second1": 23, "second2": 6, "second3": 34, "second4": 48, "ms1": 938, "ms2": 280, "ms3": 930, "ms4": 94 }
\ No newline at end of file
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java
index a59b9ac..061d372 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/printers/ADurationPrinter.java
@@ -12,7 +12,6 @@
public class ADurationPrinter implements IPrinter {
- private static final long serialVersionUID = 1L;
public static final ADurationPrinter INSTANCE = new ADurationPrinter();
private static final GregorianCalendarSystem gCalInstance = GregorianCalendarSystem.getInstance();
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
index ffcf5ee..7c87dfa 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/AIntervalSerializerDeserializer.java
@@ -17,7 +17,6 @@
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
-import java.util.regex.Pattern;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
import edu.uci.ics.asterix.om.base.AInterval;
@@ -43,8 +42,6 @@
private static final String errorMessage = "This can not be an instance of interval";
- private static final Pattern COMMA_PATTERN = Pattern.compile(",");
-
private AIntervalSerializerDeserializer() {
}
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 4dafa62..2017164 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
@@ -12,6 +12,8 @@
import edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.ABooleanTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.ACircleTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.ADateTimeTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.ADateTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.ADoubleTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.AFloatTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.AInt32TypeComputer;
@@ -21,6 +23,7 @@
import edu.uci.ics.asterix.om.typecomputer.impl.APolygonTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.ARectangleTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.AStringTypeComputer;
+import edu.uci.ics.asterix.om.typecomputer.impl.ATimeTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.BinaryBooleanOrNullFunctionTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.BinaryStringBoolOrNullTypeComputer;
import edu.uci.ics.asterix.om.typecomputer.impl.BinaryStringStringOrNullTypeComputer;
@@ -394,6 +397,12 @@
"interval_ends", 2);
public final static FunctionIdentifier INTERVAL_ENDED_BY = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"interval_ended_by", 2);
+ public final static FunctionIdentifier CURRENT_TIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+ "current_time", 0);
+ public final static FunctionIdentifier CURRENT_DATE = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+ "current_date", 0);
+ public final static FunctionIdentifier CURRENT_DATETIME = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+ "current_datetime", 0);
// spatial
public final static FunctionIdentifier CREATE_POINT = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
@@ -766,6 +775,9 @@
add(INTERVAL_COVERED_BY, OptionalABooleanTypeComputer.INSTANCE);
add(INTERVAL_ENDS, OptionalABooleanTypeComputer.INSTANCE);
add(INTERVAL_ENDED_BY, OptionalABooleanTypeComputer.INSTANCE);
+ add(CURRENT_DATE, ADateTypeComputer.INSTANCE);
+ add(CURRENT_TIME, ATimeTypeComputer.INSTANCE);
+ add(CURRENT_DATETIME, ADateTimeTypeComputer.INSTANCE);
// interval constructors
add(INTERVAL_CONSTRUCTOR_DATE, OptionalAIntervalTypeComputer.INSTANCE);
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ADateTimeTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ADateTimeTypeComputer.java
new file mode 100644
index 0000000..c7a51da
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ADateTimeTypeComputer.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009-2011 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 edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+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 ADateTimeTypeComputer implements IResultTypeComputer {
+
+ public static final ADateTimeTypeComputer INSTANCE = new ADateTimeTypeComputer();
+
+ private ADateTimeTypeComputer() {
+ }
+
+ @Override
+ public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+ IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+ return BuiltinType.ADATETIME;
+ }
+
+}
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ATimeTypeComputer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ATimeTypeComputer.java
new file mode 100644
index 0000000..55e1bc4
--- /dev/null
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/om/typecomputer/impl/ATimeTypeComputer.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2009-2011 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 edu.uci.ics.asterix.om.typecomputer.base.IResultTypeComputer;
+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 ATimeTypeComputer implements IResultTypeComputer {
+
+ public static final ATimeTypeComputer INSTANCE = new ATimeTypeComputer();
+
+ private ATimeTypeComputer() {
+ }
+
+ @Override
+ public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+ IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
+ return BuiltinType.ATIME;
+ }
+
+}
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 a9de2fa..05391de 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
@@ -18,6 +18,7 @@
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;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -48,6 +49,7 @@
// allowed input types
private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+ private static final byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -95,6 +97,14 @@
byte[] bytes = argOut.getByteArray();
try {
+
+ if (bytes[0] == SER_DURATION_TYPE_TAG) {
+ aMutableInt32.setValue(calSystem.getDurationDay(ADurationSerializerDeserializer
+ .getDayTime(bytes, 1)));
+ intSerde.serialize(aMutableInt32, out);
+ return;
+ }
+
long chrononTimeInMs = 0;
if (bytes[0] == SER_DATE_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, 1)
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 ac65679..eba012f 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
@@ -18,6 +18,7 @@
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;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -48,6 +49,7 @@
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+ private static final byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -96,6 +98,14 @@
byte[] bytes = argOut.getByteArray();
try {
+
+ if (bytes[0] == SER_DURATION_TYPE_TAG) {
+ aMutableInt32.setValue(calSystem.getDurationHour(ADurationSerializerDeserializer
+ .getDayTime(bytes, 1)));
+ intSerde.serialize(aMutableInt32, out);
+ return;
+ }
+
long chrononTimeInMs = 0;
if (bytes[0] == SER_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, 1);
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 dcd0704..ecc1a35 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
@@ -18,6 +18,7 @@
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;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -48,6 +49,7 @@
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+ private static final byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -96,6 +98,14 @@
byte[] bytes = argOut.getByteArray();
try {
+
+ if (bytes[0] == SER_DURATION_TYPE_TAG) {
+ aMutableInt32.setValue(calSystem.getDurationMillisecond(ADurationSerializerDeserializer
+ .getDayTime(bytes, 1)));
+ intSerde.serialize(aMutableInt32, out);
+ return;
+ }
+
long chrononTimeInMs = 0;
if (bytes[0] == SER_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, 1);
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 e1c399e..f436016 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
@@ -18,6 +18,7 @@
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;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -48,6 +49,7 @@
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+ private static final byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -96,6 +98,14 @@
byte[] bytes = argOut.getByteArray();
try {
+
+ if (bytes[0] == SER_DURATION_TYPE_TAG) {
+ aMutableInt32.setValue(calSystem.getDurationMinute(ADurationSerializerDeserializer
+ .getDayTime(bytes, 1)));
+ intSerde.serialize(aMutableInt32, out);
+ return;
+ }
+
long chrononTimeInMs = 0;
if (bytes[0] == SER_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, 1);
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 682f0a0..fb68f7d 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
@@ -18,6 +18,7 @@
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;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -48,6 +49,7 @@
// allowed input types
private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+ private static final byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -96,6 +98,14 @@
byte[] bytes = argOut.getByteArray();
try {
+
+ if (bytes[0] == SER_DURATION_TYPE_TAG) {
+ aMutableInt32.setValue(calSystem.getDurationMonth(ADurationSerializerDeserializer
+ .getYearMonth(bytes, 1)));
+ intSerde.serialize(aMutableInt32, out);
+ return;
+ }
+
long chrononTimeInMs = 0;
if (bytes[0] == SER_DATE_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, 1)
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 d2dc590..3b9ee95 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
@@ -18,6 +18,7 @@
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;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -48,6 +49,7 @@
// allowed input types
private static final byte SER_TIME_TYPE_TAG = ATypeTag.TIME.serialize();
private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
+ private static final byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -96,6 +98,14 @@
byte[] bytes = argOut.getByteArray();
try {
+
+ if (bytes[0] == SER_DURATION_TYPE_TAG) {
+ aMutableInt32.setValue(calSystem.getDurationSecond(ADurationSerializerDeserializer
+ .getDayTime(bytes, 1)));
+ intSerde.serialize(aMutableInt32, out);
+ return;
+ }
+
long chrononTimeInMs = 0;
if (bytes[0] == SER_TIME_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, 1);
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 d0c4fc0..41dacfd 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
@@ -18,6 +18,7 @@
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;
import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
@@ -49,7 +50,8 @@
// allowed input types
private static final byte SER_DATE_TYPE_TAG = ATypeTag.DATE.serialize();
private static final byte SER_DATETIME_TYPE_TAG = ATypeTag.DATETIME.serialize();
- private final static byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
+ private static final byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
+ private static final byte SER_STRING_TYPE_TAG = ATypeTag.STRING.serialize();
private static final byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
public static final IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
@@ -94,6 +96,14 @@
byte[] bytes = argOut.getByteArray();
try {
+
+ if (bytes[0] == SER_DURATION_TYPE_TAG) {
+ aMutableInt32.setValue(calSystem.getDurationYear(ADurationSerializerDeserializer
+ .getYearMonth(bytes, 1)));
+ intSerde.serialize(aMutableInt32, out);
+ return;
+ }
+
long chrononTimeInMs = 0;
if (bytes[0] == SER_DATE_TYPE_TAG) {
chrononTimeInMs = AInt32SerializerDeserializer.getInt(bytes, 1)
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentDateDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentDateDescriptor.java
new file mode 100644
index 0000000..3dd0909
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentDateDescriptor.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2009-2011 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.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ADate;
+import edu.uci.ics.asterix.om.base.AMutableDate;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+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.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class CurrentDateDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "current_date",
+ 0);
+
+ public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new CurrentDateDescriptor();
+ }
+ };
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(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();
+
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ADate> dateSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADATE);
+ private AMutableDate aDate = new AMutableDate(0);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ try {
+ int dateChronon = (int) (System.currentTimeMillis() / GregorianCalendarSystem.CHRONON_OF_DAY);
+ aDate.setValue(dateChronon);
+ dateSerde.serialize(aDate, out);
+ } catch (HyracksDataException hex) {
+ throw new AlgebricksException(hex);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentDateTimeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentDateTimeDescriptor.java
new file mode 100644
index 0000000..e573bdb
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentDateTimeDescriptor.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2009-2011 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.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.ADateTime;
+import edu.uci.ics.asterix.om.base.AMutableDateTime;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+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.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class CurrentDateTimeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ private final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
+ "current_datetime", 0);
+
+ public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new CurrentDateTimeDescriptor();
+ }
+ };
+
+ private CurrentDateTimeDescriptor() {
+ }
+
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(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();
+
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ADateTime> datetimeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ADATETIME);
+ private AMutableDateTime aDateTime = new AMutableDateTime(0);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ try {
+ aDateTime.setValue(System.currentTimeMillis());
+ datetimeSerde.serialize(aDateTime, out);
+ } catch (HyracksDataException hex) {
+ throw new AlgebricksException(hex);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see edu.uci.ics.asterix.om.functions.IFunctionDescriptor#getIdentifier()
+ */
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentTimeDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentTimeDescriptor.java
new file mode 100644
index 0000000..30fff45
--- /dev/null
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/CurrentTimeDescriptor.java
@@ -0,0 +1,93 @@
+/*
+ * Copyright 2009-2011 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.common.functions.FunctionConstants;
+import edu.uci.ics.asterix.formats.nontagged.AqlSerializerDeserializerProvider;
+import edu.uci.ics.asterix.om.base.AMutableTime;
+import edu.uci.ics.asterix.om.base.ATime;
+import edu.uci.ics.asterix.om.base.temporal.GregorianCalendarSystem;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptor;
+import edu.uci.ics.asterix.om.functions.IFunctionDescriptorFactory;
+import edu.uci.ics.asterix.om.types.BuiltinType;
+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.dataflow.common.data.accessors.IFrameTupleReference;
+
+public class CurrentTimeDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+
+ private static final long serialVersionUID = 1L;
+ public final static FunctionIdentifier FID = new FunctionIdentifier(FunctionConstants.ASTERIX_NS, "current_time", 0);
+
+ public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new CurrentTimeDescriptor();
+ }
+ };
+
+ /* (non-Javadoc)
+ * @see edu.uci.ics.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(edu.uci.ics.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
+ */
+ @Override
+ public ICopyEvaluatorFactory createEvaluatorFactory(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();
+
+ @SuppressWarnings("unchecked")
+ private ISerializerDeserializer<ATime> timeSerde = AqlSerializerDeserializerProvider.INSTANCE
+ .getSerializerDeserializer(BuiltinType.ATIME);
+ private AMutableTime aTime = new AMutableTime(0);
+
+ @Override
+ public void evaluate(IFrameTupleReference tuple) throws AlgebricksException {
+ try {
+ int timeChronon = (int) (System.currentTimeMillis() % GregorianCalendarSystem.CHRONON_OF_DAY);
+ aTime.setValue(timeChronon);
+ timeSerde.serialize(aTime, out);
+ } catch (HyracksDataException hex) {
+ throw new AlgebricksException(hex);
+ }
+ }
+ };
+ }
+ };
+ }
+
+ /* (non-Javadoc)
+ * @see edu.uci.ics.asterix.om.functions.IFunctionDescriptor#getIdentifier()
+ */
+ @Override
+ public FunctionIdentifier getIdentifier() {
+ return FID;
+ }
+
+}
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 0f49a54..5e24b39 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
@@ -175,6 +175,9 @@
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.AdjustTimeForTimeZoneDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.CalendarDuartionFromDateDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.CalendarDurationFromDateTimeDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.CurrentDateDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.CurrentDateTimeDescriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.CurrentTimeDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DateFromDatetimeDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DateFromUnixTimeInDaysDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DatetimeFromDateAndTimeDescriptor;
@@ -452,6 +455,9 @@
temp.add(IntervalCoveredByDescriptor.FACTORY);
temp.add(IntervalEndsDecriptor.FACTORY);
temp.add(IntervalEndedByDescriptor.FACTORY);
+ temp.add(CurrentDateDescriptor.FACTORY);
+ temp.add(CurrentTimeDescriptor.FACTORY);
+ temp.add(CurrentDateTimeDescriptor.FACTORY);
// Interval constructor
temp.add(AIntervalFromDateConstructorDescriptor.FACTORY);