addressed Sattam's review comments; added the entry for the test case in
the test suite (missed for committing in previous revision); added
duration-less-than functions based on the greater-than implementations.
diff --git a/asterix-app/src/test/resources/runtimets/queries/temporal/duration_comps/duration_comps.3.query.aql b/asterix-app/src/test/resources/runtimets/queries/temporal/duration_comps/duration_comps.3.query.aql
index 3683b3c..77fcc4f 100644
--- a/asterix-app/src/test/resources/runtimets/queries/temporal/duration_comps/duration_comps.3.query.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/temporal/duration_comps/duration_comps.3.query.aql
@@ -8,4 +8,4 @@
let $dr6 := duration-from-months(months-of-year-month-duration($dr3))
let $dr7 := duration-from-ms(ms-of-day-time-duration($dr1))
-return { "yearMonthComp" : year-month-duration-greater($dr4, $dr3), "dayTimeComp" : day-time-duration-greater($dr2, $dr1), "equal1": duration-equal($dr2, $dr5), "equal2": duration-equal($dr1, $dr5), "equal3": duration-equal($dr6, $dr3), "equal4": duration-equal($dr7, $dr1) }
\ No newline at end of file
+return { "yearMonthGreaterComp" : year-month-duration-greater-than($dr4, $dr3), "dayTimeGreaterComp" : day-time-duration-greater-than($dr2, $dr1), "yearMonthLessComp" : year-month-duration-less-than($dr4, $dr3), "dayTimeLessComp" : day-time-duration-less-than($dr2, $dr1), "equal1": duration-equal($dr2, $dr5), "equal2": duration-equal($dr1, $dr5), "equal3": duration-equal($dr6, $dr3), "equal4": duration-equal($dr7, $dr1) }
\ No newline at end of file
diff --git a/asterix-app/src/test/resources/runtimets/results/temporal/duration_comps/duration_comps.1.adm b/asterix-app/src/test/resources/runtimets/results/temporal/duration_comps/duration_comps.1.adm
index 9693453..26b32fc 100644
--- a/asterix-app/src/test/resources/runtimets/results/temporal/duration_comps/duration_comps.1.adm
+++ b/asterix-app/src/test/resources/runtimets/results/temporal/duration_comps/duration_comps.1.adm
@@ -1 +1 @@
-{ "yearMonthComp": true, "dayTimeComp": true, "equal1": true, "equal2": false, "equal3": true, "equal4": true }
\ No newline at end of file
+{ "yearMonthGreaterComp": true, "dayTimeGreaterComp": true, "yearMonthLessComp": false, "dayTimeLessComp": false, "equal1": true, "equal2": false, "equal3": true, "equal4": true }
\ 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 17ec2bb..dd29a7b 100644
--- a/asterix-app/src/test/resources/runtimets/testsuite.xml
+++ b/asterix-app/src/test/resources/runtimets/testsuite.xml
@@ -4205,6 +4205,11 @@
<output-dir compare="Text">interval</output-dir>
</compilation-unit>
</test-case>
+ <test-case FilePath="temporal">
+ <compilation-unit name="duration_comps">
+ <output-dir compare="Text">duration_comps</output-dir>
+ </compilation-unit>
+ </test-case>
</test-group>
<test-group name="leftouterjoin">
<test-case FilePath="leftouterjoin">
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 2166511..3cad3be 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
@@ -416,10 +416,14 @@
"current-datetime", 0);
public final static FunctionIdentifier DURATION_EQUAL = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"duration-equal", 2);
- public final static FunctionIdentifier YEAR_MONTH_DURATION_GREATER = new FunctionIdentifier(
- FunctionConstants.ASTERIX_NS, "year-month-duration-greater", 2);
- public final static FunctionIdentifier DAY_TIME_DURATION_GREATER = new FunctionIdentifier(
- FunctionConstants.ASTERIX_NS, "day-time-duration-greater", 2);
+ public final static FunctionIdentifier YEAR_MONTH_DURATION_GREATER_THAN = new FunctionIdentifier(
+ FunctionConstants.ASTERIX_NS, "year-month-duration-greater-than", 2);
+ public final static FunctionIdentifier YEAR_MONTH_DURATION_LESS_THAN = new FunctionIdentifier(
+ FunctionConstants.ASTERIX_NS, "year-month-duration-less-than", 2);
+ public final static FunctionIdentifier DAY_TIME_DURATION_GREATER_THAN = new FunctionIdentifier(
+ FunctionConstants.ASTERIX_NS, "day-time-duration-greater-than", 2);
+ public final static FunctionIdentifier DAY_TIME_DURATION_LESS_THAN = new FunctionIdentifier(
+ FunctionConstants.ASTERIX_NS, "day-time-duration-less-than", 2);
public final static FunctionIdentifier DURATION_FROM_MONTHS = new FunctionIdentifier(FunctionConstants.ASTERIX_NS,
"duration-from-months", 1);
public final static FunctionIdentifier MONTHS_OF_YEAR_MONTH_DURATION = new FunctionIdentifier(
@@ -829,6 +833,15 @@
add(CURRENT_DATE, ADateTypeComputer.INSTANCE);
add(CURRENT_TIME, ATimeTypeComputer.INSTANCE);
add(CURRENT_DATETIME, ADateTimeTypeComputer.INSTANCE);
+ add(DAY_TIME_DURATION_GREATER_THAN, OptionalABooleanTypeComputer.INSTANCE);
+ add(DAY_TIME_DURATION_LESS_THAN, OptionalABooleanTypeComputer.INSTANCE);
+ add(YEAR_MONTH_DURATION_GREATER_THAN, OptionalABooleanTypeComputer.INSTANCE);
+ add(YEAR_MONTH_DURATION_LESS_THAN, OptionalABooleanTypeComputer.INSTANCE);
+ add(DURATION_EQUAL, OptionalABooleanTypeComputer.INSTANCE);
+ add(DURATION_FROM_MONTHS, OptionalADurationTypeComputer.INSTANCE);
+ add(DURATION_FROM_MILLISECONDS, OptionalADurationTypeComputer.INSTANCE);
+ add(MONTHS_OF_YEAR_MONTH_DURATION, OptionalAInt32TypeComputer.INSTANCE);
+ add(MILLISECONDS_OF_DAY_TIME_DURATION, OptionalAInt64TypeComputer.INSTANCE);
// interval constructors
add(INTERVAL_CONSTRUCTOR_DATE, OptionalAIntervalTypeComputer.INSTANCE);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayTimeDurationGreaterDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayTimeDurationComparatorDescriptor.java
similarity index 81%
rename from asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayTimeDurationGreaterDescriptor.java
rename to asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayTimeDurationComparatorDescriptor.java
index 18578c9..bb83016 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayTimeDurationGreaterDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/DayTimeDurationComparatorDescriptor.java
@@ -37,20 +37,35 @@
import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-public class DayTimeDurationGreaterDescriptor extends AbstractScalarFunctionDynamicDescriptor {
+public class DayTimeDurationComparatorDescriptor extends AbstractScalarFunctionDynamicDescriptor {
private final static long serialVersionUID = 1L;
- public final static FunctionIdentifier FID = AsterixBuiltinFunctions.DAY_TIME_DURATION_GREATER;
+ public final static FunctionIdentifier GREATER_THAN_FID = AsterixBuiltinFunctions.DAY_TIME_DURATION_GREATER_THAN;
+ public final static FunctionIdentifier LESS_THAN_FID = AsterixBuiltinFunctions.DAY_TIME_DURATION_LESS_THAN;
// allowed input types
private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
private final static byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
- public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ private final boolean isGreaterThan;
+
+ private DayTimeDurationComparatorDescriptor(boolean isGreaterThan) {
+ this.isGreaterThan = isGreaterThan;
+ }
+
+ public final static IFunctionDescriptorFactory GREATER_THAN_FACTORY = new IFunctionDescriptorFactory() {
@Override
public IFunctionDescriptor createFunctionDescriptor() {
- return new DayTimeDurationGreaterDescriptor();
+ return new DayTimeDurationComparatorDescriptor(true);
+ }
+ };
+
+ public final static IFunctionDescriptorFactory LESS_THAN_FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new DayTimeDurationComparatorDescriptor(false);
}
};
@@ -94,7 +109,7 @@
if (argOut0.getByteArray()[0] != SER_DURATION_TYPE_TAG
|| argOut1.getByteArray()[0] != SER_DURATION_TYPE_TAG) {
- throw new AlgebricksException(FID.getName()
+ throw new AlgebricksException(getIdentifier().getName()
+ ": expects type NULL/DURATION, NULL/DURATION but got "
+ EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0])
+ " and "
@@ -103,15 +118,15 @@
if ((ADurationSerializerDeserializer.getYearMonth(argOut0.getByteArray(), 1) != 0)
|| (ADurationSerializerDeserializer.getYearMonth(argOut1.getByteArray(), 1) != 0)) {
- throw new AlgebricksException(FID.getName()
+ throw new AlgebricksException(getIdentifier().getName()
+ ": only year-month durations are allowed.");
}
if (ADurationSerializerDeserializer.getDayTime(argOut0.getByteArray(), 1) > ADurationSerializerDeserializer
.getDayTime(argOut1.getByteArray(), 1)) {
- boolSerde.serialize(ABoolean.TRUE, out);
+ boolSerde.serialize(isGreaterThan ? ABoolean.TRUE : ABoolean.FALSE, out);
} else {
- boolSerde.serialize(ABoolean.FALSE, out);
+ boolSerde.serialize(isGreaterThan ? ABoolean.FALSE : ABoolean.TRUE, out);
}
} catch (HyracksDataException hex) {
@@ -128,7 +143,7 @@
*/
@Override
public FunctionIdentifier getIdentifier() {
- return FID;
+ return isGreaterThan ? GREATER_THAN_FID : LESS_THAN_FID;
}
}
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/YearMonthDurationGreaterDecriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/YearMonthDurationComparatorDecriptor.java
similarity index 81%
rename from asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/YearMonthDurationGreaterDecriptor.java
rename to asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/YearMonthDurationComparatorDecriptor.java
index 090005c..22ab96c 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/YearMonthDurationGreaterDecriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/temporal/YearMonthDurationComparatorDecriptor.java
@@ -37,20 +37,35 @@
import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
import edu.uci.ics.hyracks.dataflow.common.data.accessors.IFrameTupleReference;
-public class YearMonthDurationGreaterDecriptor extends AbstractScalarFunctionDynamicDescriptor {
+public class YearMonthDurationComparatorDecriptor extends AbstractScalarFunctionDynamicDescriptor {
private final static long serialVersionUID = 1L;
- public final static FunctionIdentifier FID = AsterixBuiltinFunctions.YEAR_MONTH_DURATION_GREATER;
+ public final static FunctionIdentifier GREATER_THAN_FID = AsterixBuiltinFunctions.YEAR_MONTH_DURATION_GREATER_THAN;
+ public final static FunctionIdentifier LESS_THAN_FID = AsterixBuiltinFunctions.YEAR_MONTH_DURATION_LESS_THAN;
// allowed input types
private final static byte SER_NULL_TYPE_TAG = ATypeTag.NULL.serialize();
private final static byte SER_DURATION_TYPE_TAG = ATypeTag.DURATION.serialize();
+
+ private final boolean isGreaterThan;
- public final static IFunctionDescriptorFactory FACTORY = new IFunctionDescriptorFactory() {
+ private YearMonthDurationComparatorDecriptor(boolean isGreaterThan) {
+ this.isGreaterThan = isGreaterThan;
+ }
+
+ public final static IFunctionDescriptorFactory GREATER_THAN_FACTORY = new IFunctionDescriptorFactory() {
@Override
public IFunctionDescriptor createFunctionDescriptor() {
- return new YearMonthDurationGreaterDecriptor();
+ return new YearMonthDurationComparatorDecriptor(true);
+ }
+ };
+
+ public final static IFunctionDescriptorFactory LESS_THAN_FACTORY = new IFunctionDescriptorFactory() {
+
+ @Override
+ public IFunctionDescriptor createFunctionDescriptor() {
+ return new YearMonthDurationComparatorDecriptor(false);
}
};
@@ -94,7 +109,7 @@
if (argOut0.getByteArray()[0] != SER_DURATION_TYPE_TAG
|| argOut1.getByteArray()[0] != SER_DURATION_TYPE_TAG) {
- throw new AlgebricksException(FID.getName()
+ throw new AlgebricksException(getIdentifier().getName()
+ ": expects type NULL/DURATION, NULL/DURATION but got "
+ EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argOut0.getByteArray()[0])
+ " and "
@@ -103,15 +118,15 @@
if ((ADurationSerializerDeserializer.getDayTime(argOut0.getByteArray(), 1) != 0)
|| (ADurationSerializerDeserializer.getDayTime(argOut1.getByteArray(), 1) != 0)) {
- throw new AlgebricksException(FID.getName()
+ throw new AlgebricksException(getIdentifier().getName()
+ ": only year-month durations are allowed.");
}
if (ADurationSerializerDeserializer.getYearMonth(argOut0.getByteArray(), 1) > ADurationSerializerDeserializer
.getYearMonth(argOut1.getByteArray(), 1)) {
- boolSerde.serialize(ABoolean.TRUE, out);
+ boolSerde.serialize(isGreaterThan ? ABoolean.TRUE : ABoolean.FALSE, out);
} else {
- boolSerde.serialize(ABoolean.FALSE, out);
+ boolSerde.serialize(isGreaterThan ? ABoolean.FALSE : ABoolean.TRUE, out);
}
} catch (HyracksDataException hex) {
@@ -128,7 +143,7 @@
*/
@Override
public FunctionIdentifier getIdentifier() {
- return FID;
+ return isGreaterThan ? GREATER_THAN_FID : LESS_THAN_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 dec1a83..84142be 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
@@ -203,7 +203,7 @@
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DateFromUnixTimeInDaysDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DatetimeFromDateAndTimeDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DatetimeFromUnixTimeInMsDescriptor;
-import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DayTimeDurationGreaterDescriptor;
+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.DurationFromMillisecondsDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.DurationFromMonthsDescriptor;
@@ -227,7 +227,7 @@
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.SubtractTimeDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.TimeFromDatetimeDescriptor;
import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.TimeFromUnixTimeInMsDescriptor;
-import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.YearMonthDurationGreaterDecriptor;
+import edu.uci.ics.asterix.runtime.evaluators.functions.temporal.YearMonthDurationComparatorDecriptor;
import edu.uci.ics.asterix.runtime.operators.file.AdmSchemafullRecordParserFactory;
import edu.uci.ics.asterix.runtime.operators.file.NtDelimitedDataTupleParserFactory;
import edu.uci.ics.asterix.runtime.runningaggregates.std.TidRunningAggregateDescriptor;
@@ -511,8 +511,10 @@
temp.add(CurrentDateTimeDescriptor.FACTORY);
temp.add(DurationFromMillisecondsDescriptor.FACTORY);
temp.add(DurationFromMonthsDescriptor.FACTORY);
- temp.add(YearMonthDurationGreaterDecriptor.FACTORY);
- temp.add(DayTimeDurationGreaterDescriptor.FACTORY);
+ temp.add(YearMonthDurationComparatorDecriptor.GREATER_THAN_FACTORY);
+ temp.add(YearMonthDurationComparatorDecriptor.LESS_THAN_FACTORY);
+ temp.add(DayTimeDurationComparatorDescriptor.GREATER_THAN_FACTORY);
+ temp.add(DayTimeDurationComparatorDescriptor.LESS_THAN_FACTORY);
temp.add(MonthsOfYearMonthDurationDescriptor.FACTORY);
temp.add(MillisecondsOfDayTimeDurationDescriptor.FACTORY);
temp.add(DurationEqualDescriptor.FACTORY);