incubator-vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject svn commit: r1381431 [1/2] - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/
Date Wed, 05 Sep 2012 22:46:17 GMT
Author: prestonc
Date: Wed Sep  5 22:46:16 2012
New Revision: 1381431

URL: http://svn.apache.org/viewvc?rev=1381431&view=rev
Log:
Added a layer of abstraction for the DateTime and Duration functions.

Added:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDateTimeScalarEvaluatorFactory.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDurationScalarEvaluatorFactory.java   (with props)
Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDaysFromDurationScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDateTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDurationScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDateTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDurationScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthsFromDurationScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDateTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDurationScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnYearFromDateScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnYearFromDateTimeScalarEvaluatorFactory.java
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnYearsFromDurationScalarEvaluatorFactory.java

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDateTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDateTimeScalarEvaluatorFactory.java?rev=1381431&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDateTimeScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDateTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -0,0 +1,98 @@
+package org.apache.vxquery.runtime.functions.datetime;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.api.ITimezone;
+import org.apache.vxquery.datamodel.util.DateTime;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+
+public abstract class AbstractValueFromDateTimeScalarEvaluatorFactory extends
+        AbstractTaggedValueArgumentScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public AbstractValueFromDateTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
+        final DataOutput dOutInner = abvsInner.getDataOutput();
+
+        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+            @Override
+            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+                TaggedValuePointable tvp1 = args[0];
+                if (tvp1.getTag() != getInputTag()) {
+                    throw new SystemException(ErrorCode.FORG0006);
+                }
+
+                try {
+                    abvsInner.reset();
+                    switch (getReturnTag()) {
+                        case ValueTag.XS_INTEGER_TAG:
+                            dOutInner.write(ValueTag.XS_INTEGER_TAG);
+                            dOutInner.writeLong(getInteger(tvp1));
+                            break;
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            dOutInner.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
+                            dOutInner.writeLong(getInteger(tvp1));
+                            break;
+                        case ValueTag.XS_DECIMAL_TAG:
+                            long value = getInteger(tvp1);
+                            long decimalPlace = 3;
+
+                            // Normalize to decimal.
+                            if (value % 1000 == 0) {
+                                value = value / 1000;
+                                decimalPlace = 0;
+                            } else if (value % 100 == 0) {
+                                value = value / 100;
+                                decimalPlace = 1;
+                            } else if (value % 10 == 0) {
+                                value = value / 10;
+                                decimalPlace = 2;
+                            }
+
+                            dOutInner.write(ValueTag.XS_DECIMAL_TAG);
+                            dOutInner.write((byte) decimalPlace);
+                            dOutInner.writeLong(value);
+                            break;
+                    }
+
+                    result.set(abvsInner);
+                } catch (IOException e) {
+                    throw new SystemException(ErrorCode.SYSE0001, e);
+                }
+            }
+        };
+    }
+
+    protected abstract int getInputTag();
+
+    protected int getReturnTag() {
+        return ValueTag.XS_INTEGER_TAG;
+    }
+
+    protected abstract long getInteger(TaggedValuePointable tvp);
+
+    protected long getTimezone(ITimezone timezonep) {
+        return timezonep.getTimezoneHour() * DateTime.CHRONON_OF_HOUR + timezonep.getTimezoneMinute()
+                * DateTime.CHRONON_OF_MINUTE;
+    }
+
+}

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDateTimeScalarEvaluatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDurationScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDurationScalarEvaluatorFactory.java?rev=1381431&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDurationScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDurationScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -0,0 +1,107 @@
+package org.apache.vxquery.runtime.functions.datetime;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
+import org.apache.vxquery.datamodel.values.ValueTag;
+import org.apache.vxquery.exceptions.ErrorCode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
+import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
+
+import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
+import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
+import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
+import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
+import edu.uci.ics.hyracks.data.std.api.IPointable;
+import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
+import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+
+public abstract class AbstractValueFromDurationScalarEvaluatorFactory extends
+        AbstractTaggedValueArgumentScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public AbstractValueFromDurationScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        final XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
+        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
+        final IntegerPointable intp = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
+        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
+        final DataOutput dOutInner = abvsInner.getDataOutput();
+
+        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+            @Override
+            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+                TaggedValuePointable tvp1 = args[0];
+                long value;
+                long YMDuration = 0, DTDuration = 0;
+
+                switch (tvp1.getTag()) {
+                    case ValueTag.XS_DURATION_TAG:
+                        tvp1.getValue(durationp);
+                        YMDuration = durationp.getYearMonth();
+                        DTDuration = durationp.getDayTime();
+                        break;
+                    case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                        tvp1.getValue(longp);
+                        DTDuration = longp.getLong();
+                        break;
+                    case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                        YMDuration = intp.getInteger();
+                        break;
+                    default:
+                        throw new SystemException(ErrorCode.FORG0006);
+                }
+
+                value = convertDuration(YMDuration, DTDuration);
+
+                try {
+                    abvsInner.reset();
+                    switch (getReturnTag()) {
+                        case ValueTag.XS_INTEGER_TAG:
+                            dOutInner.write(ValueTag.XS_INTEGER_TAG);
+                            dOutInner.writeLong(value);
+                            break;
+                        case ValueTag.XS_DECIMAL_TAG:
+                            long decimalPlace = 3;
+
+                            // Normalize to decimal.
+                            if (value % 1000 == 0) {
+                                value = value / 1000;
+                                decimalPlace = 0;
+                            } else if (value % 100 == 0) {
+                                value = value / 100;
+                                decimalPlace = 1;
+                            } else if (value % 10 == 0) {
+                                value = value / 10;
+                                decimalPlace = 2;
+                            }
+
+                            dOutInner.write(ValueTag.XS_DECIMAL_TAG);
+                            dOutInner.write((byte) decimalPlace);
+                            dOutInner.writeLong(value);
+                            break;
+                    }
+
+                    result.set(abvsInner);
+                } catch (IOException e) {
+                    throw new SystemException(ErrorCode.SYSE0001, e);
+                }
+            }
+        };
+    }
+
+    protected int getReturnTag() {
+        return ValueTag.XS_INTEGER_TAG;
+    }
+
+    protected abstract long convertDuration(long YMDuration, long DTDuration);
+}

Propchange: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/AbstractValueFromDurationScalarEvaluatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,27 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnDayFromDateScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnDayFromDateScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
 
     public FnDayFromDateScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATE_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(datep.getDay());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATE_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datep);
+        return datep.getDay();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDayFromDateTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,27 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnDayFromDateTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnDayFromDateTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
 
     public FnDayFromDateTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATETIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datetimep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(datetimep.getDay());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATETIME_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datetimep);
+        return datetimep.getDay();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDaysFromDurationScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDaysFromDurationScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDaysFromDurationScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnDaysFromDurationScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,26 +1,11 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
 import org.apache.vxquery.datamodel.util.DateTime;
-import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnDaysFromDurationScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public abstract class FnDaysFromDurationScalarEvaluatorFactory extends
+        AbstractValueFromDurationScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
 
     public FnDaysFromDurationScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
@@ -28,41 +13,8 @@ public class FnDaysFromDurationScalarEva
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
-        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                long value;
-                if (tvp1.getTag() == ValueTag.XS_DURATION_TAG) {
-                    tvp1.getValue(durationp);
-                    value = durationp.getDayTime();
-                } else if (tvp1.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
-                    tvp1.getValue(longp);
-                    value = longp.getLong();
-                } else if (tvp1.getTag() == ValueTag.XS_YEAR_MONTH_DURATION_TAG) {
-                    value = 0;
-                } else {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-
-                value = value / DateTime.CHRONON_OF_DAY;
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected long convertDuration(long YMDuration, long DTDuration) {
+        return (DTDuration / DateTime.CHRONON_OF_DAY);
     }
+
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDateTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDateTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDateTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDateTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,27 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnHoursFromDateTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnHoursFromDateTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
 
     public FnHoursFromDateTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATETIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datetimep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(datetimep.getHour());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATETIME_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datetimep);
+        return datetimep.getHour();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDurationScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDurationScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDurationScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromDurationScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,26 +1,10 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
 import org.apache.vxquery.datamodel.util.DateTime;
-import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnHoursFromDurationScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnHoursFromDurationScalarEvaluatorFactory extends AbstractValueFromDurationScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
 
     public FnHoursFromDurationScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
@@ -28,41 +12,8 @@ public class FnHoursFromDurationScalarEv
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
-        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                long value;
-                if (tvp1.getTag() == ValueTag.XS_DURATION_TAG) {
-                    tvp1.getValue(durationp);
-                    value = durationp.getDayTime();
-                } else if (tvp1.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
-                    tvp1.getValue(longp);
-                    value = longp.getLong();
-                } else if (tvp1.getTag() == ValueTag.XS_YEAR_MONTH_DURATION_TAG) {
-                    value = 0;
-                } else {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-
-                value = (value % DateTime.CHRONON_OF_DAY) / DateTime.CHRONON_OF_HOUR;
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected long convertDuration(long YMDuration, long DTDuration) {
+        return ((DTDuration % DateTime.CHRONON_OF_DAY) / DateTime.CHRONON_OF_HOUR);
     }
+
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnHoursFromTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,27 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnHoursFromTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnHoursFromTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
 
     public FnHoursFromTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_TIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(timep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(timep.getHour());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_TIME_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(timep);
+        return timep.getHour();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDateTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDateTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDateTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDateTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,28 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnMinutesFromDateTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnMinutesFromDateTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
 
     public FnMinutesFromDateTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATETIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datetimep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(datetimep.getMinute());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATETIME_TAG;
     }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datetimep);
+        return datetimep.getMinute();
+    }
+
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDurationScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDurationScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDurationScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromDurationScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,26 +1,10 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
 import org.apache.vxquery.datamodel.util.DateTime;
-import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnMinutesFromDurationScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnMinutesFromDurationScalarEvaluatorFactory extends AbstractValueFromDurationScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
 
     public FnMinutesFromDurationScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
@@ -28,41 +12,8 @@ public class FnMinutesFromDurationScalar
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
-        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                long value;
-                if (tvp1.getTag() == ValueTag.XS_DURATION_TAG) {
-                    tvp1.getValue(durationp);
-                    value = durationp.getDayTime();
-                } else if (tvp1.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
-                    tvp1.getValue(longp);
-                    value = longp.getLong();
-                } else if (tvp1.getTag() == ValueTag.XS_YEAR_MONTH_DURATION_TAG) {
-                    value = 0;
-                } else {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-
-                value = ((value % DateTime.CHRONON_OF_DAY) % DateTime.CHRONON_OF_HOUR) / DateTime.CHRONON_OF_MINUTE;
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected long convertDuration(long YMDuration, long DTDuration) {
+        return (((DTDuration % DateTime.CHRONON_OF_DAY) % DateTime.CHRONON_OF_HOUR) / DateTime.CHRONON_OF_MINUTE);
     }
+
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMinutesFromTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,27 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnMinutesFromTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnMinutesFromTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
 
     public FnMinutesFromTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_TIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(timep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(timep.getMinute());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_TIME_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(timep);
+        return timep.getMinute();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,27 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnMonthFromDateScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnMonthFromDateScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
 
     public FnMonthFromDateScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATE_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(datep.getMonth());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATE_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datep);
+        return datep.getMonth();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthFromDateTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,55 +1,27 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnMonthFromDateTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnMonthFromDateTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
 
     public FnMonthFromDateTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATETIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datetimep);
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(datetimep.getMonth());
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATETIME_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datetimep);
+        return datetimep.getMonth();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthsFromDurationScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthsFromDurationScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthsFromDurationScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnMonthsFromDurationScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,25 +1,8 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
-import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
-
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.primitive.IntegerPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnMonthsFromDurationScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnMonthsFromDurationScalarEvaluatorFactory extends AbstractValueFromDurationScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
 
     public FnMonthsFromDurationScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
@@ -27,39 +10,8 @@ public class FnMonthsFromDurationScalarE
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
-        final IntegerPointable intp = (IntegerPointable) IntegerPointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                long value;
-                if (tvp1.getTag() == ValueTag.XS_DURATION_TAG) {
-                    tvp1.getValue(durationp);
-                    value = durationp.getYearMonth() % 12;
-                } else if (tvp1.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
-                    value = 0;
-                } else if (tvp1.getTag() == ValueTag.XS_YEAR_MONTH_DURATION_TAG) {
-                    tvp1.getValue(intp);
-                    value = intp.getInteger() % 12;
-                } else {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_INTEGER_TAG);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected long convertDuration(long YMDuration, long DTDuration) {
+        return (YMDuration % 12);
     }
+
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDateTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDateTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDateTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDateTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,70 +1,32 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnSecondsFromDateTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnSecondsFromDateTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
 
     public FnSecondsFromDateTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATETIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datetimep);
-                long value = datetimep.getMilliSecond();
-                long decimalPlace = 3; 
-                
-                // Normalize to decimal.
-                if (value % 1000 == 0) {
-                    value = value / 1000;
-                    decimalPlace = 0;
-                } else if (value % 100 == 0) {
-                    value = value / 100;
-                    decimalPlace = 1;
-                } else if (value % 10 == 0 ) {
-                    value = value / 10;
-                    decimalPlace = 2;
-                }
-                
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_DECIMAL_TAG);
-                    dOutInner.write((byte) decimalPlace);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATETIME_TAG;
+    }
+
+    @Override
+    protected int getReturnTag() {
+        return ValueTag.XS_DECIMAL_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datetimep);
+        return datetimep.getMilliSecond();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDurationScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDurationScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDurationScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromDurationScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,26 +1,11 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
-import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
-import org.apache.vxquery.datamodel.accessors.atomic.XSDurationPointable;
 import org.apache.vxquery.datamodel.util.DateTime;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.primitive.LongPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnSecondsFromDurationScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnSecondsFromDurationScalarEvaluatorFactory extends AbstractValueFromDurationScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
 
     public FnSecondsFromDurationScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
@@ -28,55 +13,13 @@ public class FnSecondsFromDurationScalar
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDurationPointable durationp = (XSDurationPointable) XSDurationPointable.FACTORY.createPointable();
-        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                long value;
-                if (tvp1.getTag() == ValueTag.XS_DURATION_TAG) {
-                    tvp1.getValue(durationp);
-                    value = durationp.getDayTime();
-                } else if (tvp1.getTag() == ValueTag.XS_DAY_TIME_DURATION_TAG) {
-                    tvp1.getValue(longp);
-                    value = longp.getLong();
-                } else if (tvp1.getTag() == ValueTag.XS_YEAR_MONTH_DURATION_TAG) {
-                    value = 0;
-                } else {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-
-                value = ((value % DateTime.CHRONON_OF_DAY) % DateTime.CHRONON_OF_HOUR) % DateTime.CHRONON_OF_MINUTE;
-                long decimalPlace = 3;
-
-                // Normalize to decimal.
-                if (value % 1000 == 0) {
-                    value = value / 1000;
-                    decimalPlace = 0;
-                } else if (value % 100 == 0) {
-                    value = value / 100;
-                    decimalPlace = 1;
-                } else if (value % 10 == 0) {
-                    value = value / 10;
-                    decimalPlace = 2;
-                }
-
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_DECIMAL_TAG);
-                    dOutInner.write((byte) decimalPlace);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected long convertDuration(long YMDuration, long DTDuration) {
+        return (((DTDuration % DateTime.CHRONON_OF_DAY) % DateTime.CHRONON_OF_HOUR) % DateTime.CHRONON_OF_MINUTE);
     }
+
+    @Override
+    protected int getReturnTag() {
+        return ValueTag.XS_DECIMAL_TAG;
+    }
+
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnSecondsFromTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,70 +1,32 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSTimePointable;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnSecondsFromTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnSecondsFromTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
 
     public FnSecondsFromTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSTimePointable timep = (XSTimePointable) XSTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_TIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(timep);
-                long value = timep.getMilliSecond();
-                long decimalPlace = 3; 
-                
-                // Normalize to decimal.
-                if (value % 1000 == 0) {
-                    value = value / 1000;
-                    decimalPlace = 0;
-                } else if (value % 100 == 0) {
-                    value = value / 100;
-                    decimalPlace = 1;
-                } else if (value % 10 == 0 ) {
-                    value = value / 10;
-                    decimalPlace = 2;
-                }
-                
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_DECIMAL_TAG);
-                    dOutInner.write((byte) decimalPlace);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_TIME_TAG;
+    }
+
+    @Override
+    protected int getReturnTag() {
+        return ValueTag.XS_DECIMAL_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(timep);
+        return timep.getMilliSecond();
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,58 +1,32 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDatePointable;
-import org.apache.vxquery.datamodel.util.DateTime;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnTimezoneFromDateScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnTimezoneFromDateScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
 
     public FnTimezoneFromDateScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDatePointable datep = (XSDatePointable) XSDatePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATE_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datep);
-
-                long value = datep.getTimezoneHour() * DateTime.CHRONON_OF_HOUR + datep.getTimezoneMinute()
-                        * DateTime.CHRONON_OF_MINUTE;
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATE_TAG;
+    }
+
+    @Override
+    protected int getReturnTag() {
+        return ValueTag.XS_DAY_TIME_DURATION_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datep);
+        return getTimezone(datep);
     }
 }

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateTimeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateTimeScalarEvaluatorFactory.java?rev=1381431&r1=1381430&r2=1381431&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateTimeScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/datetime/FnTimezoneFromDateTimeScalarEvaluatorFactory.java Wed Sep  5 22:46:16 2012
@@ -1,58 +1,32 @@
 package org.apache.vxquery.runtime.functions.datetime;
 
-import java.io.DataOutput;
-import java.io.IOException;
-
 import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
 import org.apache.vxquery.datamodel.accessors.atomic.XSDateTimePointable;
-import org.apache.vxquery.datamodel.util.DateTime;
 import org.apache.vxquery.datamodel.values.ValueTag;
-import org.apache.vxquery.exceptions.ErrorCode;
-import org.apache.vxquery.exceptions.SystemException;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluator;
-import org.apache.vxquery.runtime.functions.base.AbstractTaggedValueArgumentScalarEvaluatorFactory;
 
-import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
-import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluator;
 import edu.uci.ics.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory;
-import edu.uci.ics.hyracks.api.context.IHyracksTaskContext;
-import edu.uci.ics.hyracks.data.std.api.IPointable;
-import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
 
-public class FnTimezoneFromDateTimeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+public class FnTimezoneFromDateTimeScalarEvaluatorFactory extends AbstractValueFromDateTimeScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
 
     public FnTimezoneFromDateTimeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
     }
 
     @Override
-    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
-            throws AlgebricksException {
-        final XSDateTimePointable datetimep = (XSDateTimePointable) XSDateTimePointable.FACTORY.createPointable();
-        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
-        final DataOutput dOutInner = abvsInner.getDataOutput();
-
-        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
-            @Override
-            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                TaggedValuePointable tvp1 = args[0];
-                if (tvp1.getTag() != ValueTag.XS_DATETIME_TAG) {
-                    throw new SystemException(ErrorCode.FORG0006);
-                }
-                tvp1.getValue(datetimep);
-
-                long value = datetimep.getTimezoneHour() * DateTime.CHRONON_OF_HOUR + datetimep.getTimezoneMinute()
-                        * DateTime.CHRONON_OF_MINUTE;
-                try {
-                    abvsInner.reset();
-                    dOutInner.write(ValueTag.XS_DAY_TIME_DURATION_TAG);
-                    dOutInner.writeLong(value);
-                    result.set(abvsInner);
-                } catch (IOException e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
-            }
-        };
+    protected int getInputTag() {
+        return ValueTag.XS_DATETIME_TAG;
+    }
+
+    @Override
+    protected int getReturnTag() {
+        return ValueTag.XS_DAY_TIME_DURATION_TAG;
+    }
+
+    @Override
+    protected long getInteger(TaggedValuePointable tvp) {
+        tvp.getValue(datetimep);
+        return getTimezone(datetimep);
     }
 }



Mime
View raw message