You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/09/26 00:46:13 UTC
svn commit: r1390201 -
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/PromoteScalarEvaluatorFactory.java
Author: prestonc
Date: Tue Sep 25 22:46:13 2012
New Revision: 1390201
URL: http://svn.apache.org/viewvc?rev=1390201&view=rev
Log:
Preliminary fn:promote functionality.
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/PromoteScalarEvaluatorFactory.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/PromoteScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/PromoteScalarEvaluatorFactory.java?rev=1390201&r1=1390200&r2=1390201&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/PromoteScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/type/PromoteScalarEvaluatorFactory.java Tue Sep 25 22:46:13 2012
@@ -16,7 +16,18 @@
*/
package org.apache.vxquery.runtime.functions.type;
+import java.io.DataOutput;
+
import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+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.cast.AbstractCastToOperation;
+import org.apache.vxquery.runtime.functions.cast.CastToDoubleOperation;
+import org.apache.vxquery.runtime.functions.cast.CastToFloatOperation;
+import org.apache.vxquery.runtime.functions.cast.CastToStringOperation;
+import org.apache.vxquery.runtime.functions.util.FunctionHelper;
+import org.apache.vxquery.types.BuiltinTypeRegistry;
import org.apache.vxquery.types.SequenceType;
import edu.uci.ics.hyracks.algebricks.common.exceptions.AlgebricksException;
@@ -24,6 +35,7 @@ import edu.uci.ics.hyracks.algebricks.ru
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 PromoteScalarEvaluatorFactory extends AbstractTypeScalarEvaluatorFactory {
private static final long serialVersionUID = 1L;
@@ -36,14 +48,154 @@ public class PromoteScalarEvaluatorFacto
protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
throws AlgebricksException {
return new AbstractTypeScalarEvaluator(args, ctx) {
+ final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+ final DataOutput dOut = abvs.getDataOutput();
+ final FunctionHelper.TypedPointables tp = new FunctionHelper.TypedPointables();
+ AbstractCastToOperation aOp = new CastToStringOperation();
+ int castToTag = 0;
+
@Override
- protected void evaluate(TaggedValuePointable tvp, IPointable result) {
- result.set(tvp);
+ protected void evaluate(TaggedValuePointable tvp, IPointable result) throws SystemException {
+ abvs.reset();
+ int tid = tvp.getTag();
+ if (castToTag == -1 || castToTag == 0) {
+ // No change.
+ result.set(tvp);
+ } else if (castToTag > 0) {
+ try {
+ switch (tid) {
+ case ValueTag.XS_ANY_URI_TAG:
+ tvp.getValue(tp.utf8sp);
+ aOp.convertAnyURI(tp.utf8sp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_BYTE_TAG:
+ tvp.getValue(tp.bytep);
+ aOp.convertByte(tp.bytep, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_DECIMAL_TAG:
+ tvp.getValue(tp.decp);
+ aOp.convertDecimal(tp.decp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_DOUBLE_TAG:
+ tvp.getValue(tp.doublep);
+ aOp.convertDouble(tp.doublep, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_FLOAT_TAG:
+ tvp.getValue(tp.floatp);
+ aOp.convertFloat(tp.floatp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_INT_TAG:
+ tvp.getValue(tp.intp);
+ aOp.convertInt(tp.intp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_INTEGER_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertInteger(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_LONG_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertLong(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertNegativeInteger(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertNonNegativeInteger(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertNonPositiveInteger(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_POSITIVE_INTEGER_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertPositiveInteger(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_SHORT_TAG:
+ tvp.getValue(tp.shortp);
+ aOp.convertShort(tp.shortp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_STRING_TAG:
+ tvp.getValue(tp.utf8sp);
+ aOp.convertString(tp.utf8sp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_UNSIGNED_BYTE_TAG:
+ tvp.getValue(tp.shortp);
+ aOp.convertUnsignedByte(tp.shortp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_UNSIGNED_INT_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertUnsignedInt(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_UNSIGNED_LONG_TAG:
+ tvp.getValue(tp.longp);
+ aOp.convertUnsignedLong(tp.longp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ case ValueTag.XS_UNSIGNED_SHORT_TAG:
+ tvp.getValue(tp.intp);
+ aOp.convertUnsignedShort(tp.intp, dOut);
+ result.set(abvs.getByteArray(), abvs.getStartOffset(), abvs.getLength());
+ return;
+
+ }
+ } catch (SystemException se) {
+ throw se;
+ } catch (Exception e) {
+ throw new SystemException(ErrorCode.SYSE0001, e);
+ }
+ throw new SystemException(ErrorCode.XPTY0004);
+ }
}
@Override
protected void setSequenceType(SequenceType sType) {
-
+ if (sType.getItemType() == BuiltinTypeRegistry.XS_DOUBLE) {
+ castToTag = ValueTag.XS_DOUBLE_TAG;
+ aOp = new CastToDoubleOperation();
+ } else if (sType.getItemType() == BuiltinTypeRegistry.XS_FLOAT) {
+ castToTag = ValueTag.XS_FLOAT_TAG;
+ aOp = new CastToFloatOperation();
+ } else if (sType.getItemType() == BuiltinTypeRegistry.XS_STRING) {
+ castToTag = ValueTag.XS_STRING_TAG;
+ aOp = new CastToStringOperation();
+ } else {
+ castToTag = -1;
+ }
}
};
}