incubator-vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject svn commit: r1381373 - in /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery: functions/ runtime/functions/comparison/ runtime/functions/sequence/
Date Wed, 05 Sep 2012 21:15:19 GMT
Author: prestonc
Date: Wed Sep  5 21:15:19 2012
New Revision: 1381373

URL: http://svn.apache.org/viewvc?rev=1381373&view=rev
Log:
VXQUERY-75 Added FnIndexOf and FnInsertBefore.

Added:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnIndexOfScalarEvaluatorFactory.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnInsertBeforeScalarEvaluatorFactory.java   (with props)
Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/AbstractValueComparisonScalarEvaluatorFactory.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml?rev=1381373&r1=1381372&r2=1381373&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml Wed Sep  5 21:15:19 2012
@@ -429,6 +429,7 @@
         <param name="seqParam" type="xs:anyAtomicType*"/>
         <param name="srcParam" type="xs:anyAtomicType"/>
         <return type="xs:integer*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.FnIndexOfScalarEvaluatorFactory"/>
     </function>
 
     <!-- fn:index-of($seqParam  as xs:anyAtomicType*, $srchParam as xs:anyAtomicType, $collation as xs:string)  as xs:integer* -->
@@ -437,6 +438,7 @@
         <param name="srcParam" type="xs:anyAtomicType"/>
         <param name="collation" type="xs:string"/>
         <return type="xs:integer*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.FnIndexOfScalarEvaluatorFactory"/>
     </function>
 
     <!-- fn:insert-before($target  as item()*, $position as xs:integer, $inserts as item()*)  as item()* -->
@@ -445,6 +447,7 @@
         <param name="position" type="xs:integer"/>
         <param name="inserts" type="item()*"/>
         <return type="item()*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.FnInsertBeforeScalarEvaluatorFactory"/>
     </function>
 
     <!-- fn:iri-to-uri($iri  as xs:string?) as  xs:string -->

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/AbstractValueComparisonScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/AbstractValueComparisonScalarEvaluatorFactory.java?rev=1381373&r1=1381372&r2=1381373&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/AbstractValueComparisonScalarEvaluatorFactory.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/comparison/AbstractValueComparisonScalarEvaluatorFactory.java Wed Sep  5 21:15:19 2012
@@ -53,6 +53,14 @@ import edu.uci.ics.hyracks.data.std.util
 public abstract class AbstractValueComparisonScalarEvaluatorFactory extends
         AbstractTaggedValueArgumentScalarEvaluatorFactory {
     private static final long serialVersionUID = 1L;
+    private static final ArrayBackedValueStorage abvsInteger1 = new ArrayBackedValueStorage();
+    private static final DataOutput dOutInteger1 = abvsInteger1.getDataOutput();
+    private static final ArrayBackedValueStorage abvsInteger2 = new ArrayBackedValueStorage();
+    private static final DataOutput dOutInteger2 = abvsInteger2.getDataOutput();
+    private static final TypedPointables tp1 = new TypedPointables();
+    private static final TypedPointables tp2 = new TypedPointables();
+    private static final LongPointable longp1 = (LongPointable) LongPointable.FACTORY.createPointable();
+    private static final LongPointable longp2 = (LongPointable) LongPointable.FACTORY.createPointable();
 
     public AbstractValueComparisonScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
         super(args);
@@ -61,471 +69,476 @@ public abstract class AbstractValueCompa
     @Override
     protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
             throws AlgebricksException {
+        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+        final DataOutput dOut = abvs.getDataOutput();
         final AbstractValueComparisonOperation aOp = createValueComparisonOperation();
-        final ArrayBackedValueStorage abvsInteger1 = new ArrayBackedValueStorage();
-        final DataOutput dOutInteger1 = abvsInteger1.getDataOutput();
-        final ArrayBackedValueStorage abvsInteger2 = new ArrayBackedValueStorage();
-        final DataOutput dOutInteger2 = abvsInteger2.getDataOutput();
-        final TypedPointables tp1 = new TypedPointables();
-        final TypedPointables tp2 = new TypedPointables();
         final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
-        final LongPointable longp1 = (LongPointable) LongPointable.FACTORY.createPointable();
-        final LongPointable longp2 = (LongPointable) LongPointable.FACTORY.createPointable();
-
+        
         return new AbstractTaggedValueArgumentScalarEvaluator(args) {
             @Override
             protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
-                boolean booleanResult = false;
                 TaggedValuePointable tvp1 = args[0];
                 TaggedValuePointable tvp2 = args[1];
-                int tid1 = getBaseTypeForComparisons(tvp1.getTag());
-                int tid2 = getBaseTypeForComparisons(tvp2.getTag());
-                if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
-                    // TODO Convert to double
-                    tid1 = ValueTag.XS_DOUBLE_TAG;
-                    throw new UnsupportedOperationException();
-                }
-                if (tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
-                    // TODO Convert to double
-                    tid2 = ValueTag.XS_DOUBLE_TAG;
-                    throw new UnsupportedOperationException();
-                }
+                boolean booleanResult = compareTaggedValues(aOp, tvp1, tvp2, dCtx);
+
                 try {
-                    switch (tvp1.getTag()) {
+                    abvs.reset();
+                    dOut.write(ValueTag.XS_BOOLEAN_TAG);
+                    dOut.write(booleanResult ? 1 : 0);
+                    result.set(abvs);
+                } catch (Exception e) {
+                    throw new SystemException(ErrorCode.SYSE0001, e);
+                }
+            }
+
+        };
+    }
+
+    public static boolean compareTaggedValues(AbstractValueComparisonOperation aOp, TaggedValuePointable tvp1, TaggedValuePointable tvp2, DynamicContext dCtx) throws SystemException {
+        boolean booleanResult = false;
+        int tid1 = getBaseTypeForComparisons(tvp1.getTag());
+        int tid2 = getBaseTypeForComparisons(tvp2.getTag());
+        if (tid1 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
+            // TODO Convert to double
+            tid1 = ValueTag.XS_DOUBLE_TAG;
+            throw new UnsupportedOperationException();
+        }
+        if (tid2 == ValueTag.XS_UNTYPED_ATOMIC_TAG) {
+            // TODO Convert to double
+            tid2 = ValueTag.XS_DOUBLE_TAG;
+            throw new UnsupportedOperationException();
+        }
+        try {
+            switch (tvp1.getTag()) {
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                    abvsInteger1.reset();
+                    getIntegerPointable(tp1, tvp1, dOutInteger1);
+                    longp1.set(abvsInteger1.getByteArray(), abvsInteger1.getStartOffset() + 1,
+                            LongPointable.TYPE_TRAITS.getFixedLength());
+            }
+            switch (tvp2.getTag()) {
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_LONG_TAG:
+                case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+                case ValueTag.XS_UNSIGNED_LONG_TAG:
+                case ValueTag.XS_POSITIVE_INTEGER_TAG:
+                case ValueTag.XS_INT_TAG:
+                case ValueTag.XS_UNSIGNED_INT_TAG:
+                case ValueTag.XS_SHORT_TAG:
+                case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                case ValueTag.XS_BYTE_TAG:
+                case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                    abvsInteger2.reset();
+                    getIntegerPointable(tp2, tvp2, dOutInteger2);
+                    longp2.set(abvsInteger2.getByteArray(), abvsInteger2.getStartOffset() + 1,
+                            LongPointable.TYPE_TRAITS.getFixedLength());
+            }
+            switch (tid1) {
+                case ValueTag.XS_DECIMAL_TAG:
+                    tvp1.getValue(tp1.decp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateDecimalDecimal(tp1.decp, tp2.decp);
+                            break;
+
+                        case ValueTag.XS_INTEGER_TAG:
+                            booleanResult = aOp.operateDecimalInteger(tp1.decp, longp2);
+                            break;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateDecimalFloat(tp1.decp, tp2.floatp);
+                            break;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            tvp2.getValue(tp2.doublep);
+                            booleanResult = aOp.operateDecimalDouble(tp1.decp, tp2.doublep);
+                            break;
+                    }
+                    break;
+
+                case ValueTag.XS_INTEGER_TAG:
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateIntegerDecimal(longp1, tp2.decp);
+                            break;
+
                         case ValueTag.XS_INTEGER_TAG:
-                        case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-                        case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-                        case ValueTag.XS_LONG_TAG:
-                        case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-                        case ValueTag.XS_UNSIGNED_LONG_TAG:
-                        case ValueTag.XS_POSITIVE_INTEGER_TAG:
-                        case ValueTag.XS_INT_TAG:
-                        case ValueTag.XS_UNSIGNED_INT_TAG:
-                        case ValueTag.XS_SHORT_TAG:
-                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                        case ValueTag.XS_BYTE_TAG:
-                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                            abvsInteger1.reset();
-                            getIntegerPointable(tp1, tvp1, dOutInteger1);
-                            longp1.set(abvsInteger1.getByteArray(), abvsInteger1.getStartOffset() + 1,
-                                    LongPointable.TYPE_TRAITS.getFixedLength());
+                            booleanResult = aOp.operateIntegerInteger(longp1, longp2);
+                            break;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateIntegerFloat(longp1, tp2.floatp);
+                            break;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            tvp2.getValue(tp2.doublep);
+                            booleanResult = aOp.operateIntegerDouble(longp1, tp2.doublep);
+                            break;
                     }
-                    switch (tvp2.getTag()) {
+                    break;
+
+                case ValueTag.XS_FLOAT_TAG:
+                    tvp1.getValue(tp1.floatp);
+                    switch (tid2) {
+                        case ValueTag.XS_DECIMAL_TAG:
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateFloatDecimal(tp1.floatp, tp2.decp);
+                            break;
+
                         case ValueTag.XS_INTEGER_TAG:
-                        case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-                        case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-                        case ValueTag.XS_LONG_TAG:
-                        case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-                        case ValueTag.XS_UNSIGNED_LONG_TAG:
-                        case ValueTag.XS_POSITIVE_INTEGER_TAG:
-                        case ValueTag.XS_INT_TAG:
-                        case ValueTag.XS_UNSIGNED_INT_TAG:
-                        case ValueTag.XS_SHORT_TAG:
-                        case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                        case ValueTag.XS_BYTE_TAG:
-                        case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                            abvsInteger2.reset();
-                            getIntegerPointable(tp2, tvp2, dOutInteger2);
-                            longp2.set(abvsInteger2.getByteArray(), abvsInteger2.getStartOffset() + 1,
-                                    LongPointable.TYPE_TRAITS.getFixedLength());
+                            booleanResult = aOp.operateFloatInteger(tp1.floatp, longp2);
+                            break;
+
+                        case ValueTag.XS_FLOAT_TAG:
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateFloatFloat(tp1.floatp, tp2.floatp);
+                            break;
+
+                        case ValueTag.XS_DOUBLE_TAG:
+                            tvp2.getValue(tp2.doublep);
+                            booleanResult = aOp.operateFloatDouble(tp1.floatp, tp2.doublep);
+                            break;
                     }
-                    switch (tid1) {
+                    break;
+
+                case ValueTag.XS_DOUBLE_TAG:
+                    tvp1.getValue(tp1.doublep);
+                    switch (tid2) {
                         case ValueTag.XS_DECIMAL_TAG:
-                            tvp1.getValue(tp1.decp);
-                            switch (tid2) {
-                                case ValueTag.XS_DECIMAL_TAG:
-                                    tvp2.getValue(tp2.decp);
-                                    booleanResult = aOp.operateDecimalDecimal(tp1.decp, tp2.decp);
-                                    break;
-
-                                case ValueTag.XS_INTEGER_TAG:
-                                    booleanResult = aOp.operateDecimalInteger(tp1.decp, longp2);
-                                    break;
-
-                                case ValueTag.XS_FLOAT_TAG:
-                                    tvp2.getValue(tp2.floatp);
-                                    booleanResult = aOp.operateDecimalFloat(tp1.decp, tp2.floatp);
-                                    break;
-
-                                case ValueTag.XS_DOUBLE_TAG:
-                                    tvp2.getValue(tp2.doublep);
-                                    booleanResult = aOp.operateDecimalDouble(tp1.decp, tp2.doublep);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.decp);
+                            booleanResult = aOp.operateDoubleDecimal(tp1.doublep, tp2.decp);
                             break;
 
                         case ValueTag.XS_INTEGER_TAG:
-                            switch (tid2) {
-                                case ValueTag.XS_DECIMAL_TAG:
-                                    tvp2.getValue(tp2.decp);
-                                    booleanResult = aOp.operateIntegerDecimal(longp1, tp2.decp);
-                                    break;
-
-                                case ValueTag.XS_INTEGER_TAG:
-                                    booleanResult = aOp.operateIntegerInteger(longp1, longp2);
-                                    break;
-
-                                case ValueTag.XS_FLOAT_TAG:
-                                    tvp2.getValue(tp2.floatp);
-                                    booleanResult = aOp.operateIntegerFloat(longp1, tp2.floatp);
-                                    break;
-
-                                case ValueTag.XS_DOUBLE_TAG:
-                                    tvp2.getValue(tp2.doublep);
-                                    booleanResult = aOp.operateIntegerDouble(longp1, tp2.doublep);
-                                    break;
-                            }
+                            booleanResult = aOp.operateDoubleInteger(tp1.doublep, longp2);
                             break;
 
                         case ValueTag.XS_FLOAT_TAG:
-                            tvp1.getValue(tp1.floatp);
-                            switch (tid2) {
-                                case ValueTag.XS_DECIMAL_TAG:
-                                    tvp2.getValue(tp2.decp);
-                                    booleanResult = aOp.operateFloatDecimal(tp1.floatp, tp2.decp);
-                                    break;
-
-                                case ValueTag.XS_INTEGER_TAG:
-                                    booleanResult = aOp.operateFloatInteger(tp1.floatp, longp2);
-                                    break;
-
-                                case ValueTag.XS_FLOAT_TAG:
-                                    tvp2.getValue(tp2.floatp);
-                                    booleanResult = aOp.operateFloatFloat(tp1.floatp, tp2.floatp);
-                                    break;
-
-                                case ValueTag.XS_DOUBLE_TAG:
-                                    tvp2.getValue(tp2.doublep);
-                                    booleanResult = aOp.operateFloatDouble(tp1.floatp, tp2.doublep);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.floatp);
+                            booleanResult = aOp.operateDoubleFloat(tp1.doublep, tp2.floatp);
                             break;
 
                         case ValueTag.XS_DOUBLE_TAG:
-                            tvp1.getValue(tp1.doublep);
-                            switch (tid2) {
-                                case ValueTag.XS_DECIMAL_TAG:
-                                    tvp2.getValue(tp2.decp);
-                                    booleanResult = aOp.operateDoubleDecimal(tp1.doublep, tp2.decp);
-                                    break;
-
-                                case ValueTag.XS_INTEGER_TAG:
-                                    booleanResult = aOp.operateDoubleInteger(tp1.doublep, longp2);
-                                    break;
-
-                                case ValueTag.XS_FLOAT_TAG:
-                                    tvp2.getValue(tp2.floatp);
-                                    booleanResult = aOp.operateDoubleFloat(tp1.doublep, tp2.floatp);
-                                    break;
-
-                                case ValueTag.XS_DOUBLE_TAG:
-                                    tvp2.getValue(tp2.doublep);
-                                    booleanResult = aOp.operateDoubleDouble(tp1.doublep, tp2.doublep);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.doublep);
+                            booleanResult = aOp.operateDoubleDouble(tp1.doublep, tp2.doublep);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_BOOLEAN_TAG:
+                    tvp1.getValue(tp1.boolp);
+                    switch (tid2) {
                         case ValueTag.XS_BOOLEAN_TAG:
-                            tvp1.getValue(tp1.boolp);
-                            switch (tid2) {
-                                case ValueTag.XS_BOOLEAN_TAG:
-                                    tvp2.getValue(tp2.boolp);
-                                    booleanResult = aOp.operateBooleanBoolean(tp1.boolp, tp2.boolp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.boolp);
+                            booleanResult = aOp.operateBooleanBoolean(tp1.boolp, tp2.boolp);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_STRING_TAG:
+                    tvp1.getValue(tp1.utf8sp);
+                    switch (tid2) {
                         case ValueTag.XS_STRING_TAG:
-                            tvp1.getValue(tp1.utf8sp);
-                            switch (tid2) {
-                                case ValueTag.XS_STRING_TAG:
-                                    tvp2.getValue(tp2.utf8sp);
-                                    booleanResult = aOp.operateStringString(tp1.utf8sp, tp2.utf8sp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.utf8sp);
+                            booleanResult = aOp.operateStringString(tp1.utf8sp, tp2.utf8sp);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_DATE_TAG:
+                    tvp1.getValue(tp1.datep);
+                    switch (tid2) {
                         case ValueTag.XS_DATE_TAG:
-                            tvp1.getValue(tp1.datep);
-                            switch (tid2) {
-                                case ValueTag.XS_DATE_TAG:
-                                    tvp2.getValue(tp2.datep);
-                                    booleanResult = aOp.operateDateDate(tp1.datep, tp2.datep, dCtx);
-                                    break;
-                                default:
-                                    // Cross comparisons between DateTime, Date and Time are not supported.
-                                    throw new SystemException(ErrorCode.XPTY0004);
-                            }
+                            tvp2.getValue(tp2.datep);
+                            booleanResult = aOp.operateDateDate(tp1.datep, tp2.datep, dCtx);
                             break;
+                        default:
+                            // Cross comparisons between DateTime, Date and Time are not supported.
+                            throw new SystemException(ErrorCode.XPTY0004);
+                    }
+                    break;
 
+                case ValueTag.XS_DATETIME_TAG:
+                    tvp1.getValue(tp1.datetimep);
+                    switch (tid2) {
                         case ValueTag.XS_DATETIME_TAG:
-                            tvp1.getValue(tp1.datetimep);
-                            switch (tid2) {
-                                case ValueTag.XS_DATETIME_TAG:
-                                    tvp2.getValue(tp2.datetimep);
-                                    booleanResult = aOp.operateDatetimeDatetime(tp1.datetimep, tp2.datetimep, dCtx);
-                                    break;
-                                default:
-                                    // Cross comparisons between DateTime, Date and Time are not supported.
-                                    throw new SystemException(ErrorCode.XPTY0004);
-                            }
+                            tvp2.getValue(tp2.datetimep);
+                            booleanResult = aOp.operateDatetimeDatetime(tp1.datetimep, tp2.datetimep, dCtx);
                             break;
+                        default:
+                            // Cross comparisons between DateTime, Date and Time are not supported.
+                            throw new SystemException(ErrorCode.XPTY0004);
+                    }
+                    break;
 
+                case ValueTag.XS_TIME_TAG:
+                    tvp1.getValue(tp1.timep);
+                    switch (tid2) {
                         case ValueTag.XS_TIME_TAG:
-                            tvp1.getValue(tp1.timep);
-                            switch (tid2) {
-                                case ValueTag.XS_TIME_TAG:
-                                    tvp2.getValue(tp2.timep);
-                                    booleanResult = aOp.operateTimeTime(tp1.timep, tp2.timep, dCtx);
-                                    break;
-                                default:
-                                    // Cross comparisons between DateTime, Date and Time are not supported.
-                                    throw new SystemException(ErrorCode.XPTY0004);
-                            }
+                            tvp2.getValue(tp2.timep);
+                            booleanResult = aOp.operateTimeTime(tp1.timep, tp2.timep, dCtx);
                             break;
+                        default:
+                            // Cross comparisons between DateTime, Date and Time are not supported.
+                            throw new SystemException(ErrorCode.XPTY0004);
+                    }
+                    break;
 
+                case ValueTag.XS_DURATION_TAG:
+                    tvp1.getValue(tp1.durationp);
+                    switch (tid2) {
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            booleanResult = aOp.operateDurationDTDuration(tp1.durationp, tp2.longp);
+                            break;
                         case ValueTag.XS_DURATION_TAG:
-                            tvp1.getValue(tp1.durationp);
-                            switch (tid2) {
-                                case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                                    tvp2.getValue(tp2.longp);
-                                    booleanResult = aOp.operateDurationDTDuration(tp1.durationp, tp2.longp);
-                                    break;
-                                case ValueTag.XS_DURATION_TAG:
-                                    tvp2.getValue(tp2.durationp);
-                                    booleanResult = aOp.operateDurationDuration(tp1.durationp, tp2.durationp);
-                                    break;
-                                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                                    tvp2.getValue(tp2.intp);
-                                    booleanResult = aOp.operateDurationYMDuration(tp1.durationp, tp2.intp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.durationp);
+                            booleanResult = aOp.operateDurationDuration(tp1.durationp, tp2.durationp);
+                            break;
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            booleanResult = aOp.operateDurationYMDuration(tp1.durationp, tp2.intp);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                    tvp1.getValue(tp1.longp);
+                    switch (tid2) {
                         case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                            tvp1.getValue(tp1.longp);
-                            switch (tid2) {
-                                case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                                    tvp2.getValue(tp2.longp);
-                                    booleanResult = aOp.operateDTDurationDTDuration(tp1.longp, tp2.longp);
-                                    break;
-                                case ValueTag.XS_DURATION_TAG:
-                                    tvp2.getValue(tp2.durationp);
-                                    booleanResult = aOp.operateDTDurationDuration(tp1.longp, tp2.durationp);
-                                    break;
-                                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                                    tvp2.getValue(tp2.intp);
-                                    booleanResult = aOp.operateDTDurationYMDuration(tp1.longp, tp2.intp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.longp);
+                            booleanResult = aOp.operateDTDurationDTDuration(tp1.longp, tp2.longp);
+                            break;
+                        case ValueTag.XS_DURATION_TAG:
+                            tvp2.getValue(tp2.durationp);
+                            booleanResult = aOp.operateDTDurationDuration(tp1.longp, tp2.durationp);
                             break;
+                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                            tvp2.getValue(tp2.intp);
+                            booleanResult = aOp.operateDTDurationYMDuration(tp1.longp, tp2.intp);
+                            break;
+                    }
+                    break;
 
+                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                    tvp1.getValue(tp1.intp);
+                    switch (tid2) {
+                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                            tvp2.getValue(tp2.longp);
+                            booleanResult = aOp.operateYMDurationDTDuration(tp1.intp, tp2.longp);
+                            break;
+                        case ValueTag.XS_DURATION_TAG:
+                            tvp2.getValue(tp2.durationp);
+                            booleanResult = aOp.operateYMDurationDuration(tp1.intp, tp2.durationp);
+                            break;
                         case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                            tvp1.getValue(tp1.intp);
-                            switch (tid2) {
-                                case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                                    tvp2.getValue(tp2.longp);
-                                    booleanResult = aOp.operateYMDurationDTDuration(tp1.intp, tp2.longp);
-                                    break;
-                                case ValueTag.XS_DURATION_TAG:
-                                    tvp2.getValue(tp2.durationp);
-                                    booleanResult = aOp.operateYMDurationDuration(tp1.intp, tp2.durationp);
-                                    break;
-                                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                                    tvp2.getValue(tp2.intp);
-                                    booleanResult = aOp.operateYMDurationYMDuration(tp1.intp, tp2.intp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.intp);
+                            booleanResult = aOp.operateYMDurationYMDuration(tp1.intp, tp2.intp);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_G_DAY_TAG:
+                    tvp1.getValue(tp1.datep);
+                    switch (tid2) {
                         case ValueTag.XS_G_DAY_TAG:
-                            tvp1.getValue(tp1.datep);
-                            switch (tid2) {
-                                case ValueTag.XS_G_DAY_TAG:
-                                    tvp2.getValue(tp2.datep);
-                                    booleanResult = aOp.operateGDayGDay(tp1.datep, tp2.datep, dCtx);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.datep);
+                            booleanResult = aOp.operateGDayGDay(tp1.datep, tp2.datep, dCtx);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_G_MONTH_DAY_TAG:
+                    tvp1.getValue(tp1.datep);
+                    switch (tid2) {
                         case ValueTag.XS_G_MONTH_DAY_TAG:
-                            tvp1.getValue(tp1.datep);
-                            switch (tid2) {
-                                case ValueTag.XS_G_MONTH_DAY_TAG:
-                                    tvp2.getValue(tp2.datep);
-                                    booleanResult = aOp.operateGMonthDayGMonthDay(tp1.datep, tp2.datep, dCtx);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.datep);
+                            booleanResult = aOp.operateGMonthDayGMonthDay(tp1.datep, tp2.datep, dCtx);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_G_MONTH_TAG:
+                    tvp1.getValue(tp1.datep);
+                    switch (tid2) {
                         case ValueTag.XS_G_MONTH_TAG:
-                            tvp1.getValue(tp1.datep);
-                            switch (tid2) {
-                                case ValueTag.XS_G_MONTH_TAG:
-                                    tvp2.getValue(tp2.datep);
-                                    booleanResult = aOp.operateGMonthGMonth(tp1.datep, tp2.datep, dCtx);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.datep);
+                            booleanResult = aOp.operateGMonthGMonth(tp1.datep, tp2.datep, dCtx);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_G_YEAR_MONTH_TAG:
+                    tvp1.getValue(tp1.datep);
+                    switch (tid2) {
                         case ValueTag.XS_G_YEAR_MONTH_TAG:
-                            tvp1.getValue(tp1.datep);
-                            switch (tid2) {
-                                case ValueTag.XS_G_YEAR_MONTH_TAG:
-                                    tvp2.getValue(tp2.datep);
-                                    booleanResult = aOp.operateGYearMonthGYearMonth(tp1.datep, tp2.datep, dCtx);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.datep);
+                            booleanResult = aOp.operateGYearMonthGYearMonth(tp1.datep, tp2.datep, dCtx);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_G_YEAR_TAG:
+                    tvp1.getValue(tp1.datep);
+                    switch (tid2) {
                         case ValueTag.XS_G_YEAR_TAG:
-                            tvp1.getValue(tp1.datep);
-                            switch (tid2) {
-                                case ValueTag.XS_G_YEAR_TAG:
-                                    tvp2.getValue(tp2.datep);
-                                    booleanResult = aOp.operateGYearGYear(tp1.datep, tp2.datep, dCtx);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.datep);
+                            booleanResult = aOp.operateGYearGYear(tp1.datep, tp2.datep, dCtx);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_HEX_BINARY_TAG:
+                    tvp1.getValue(tp1.binaryp);
+                    switch (tid2) {
                         case ValueTag.XS_HEX_BINARY_TAG:
-                            tvp1.getValue(tp1.binaryp);
-                            switch (tid2) {
-                                case ValueTag.XS_HEX_BINARY_TAG:
-                                    tvp2.getValue(tp2.binaryp);
-                                    booleanResult = aOp.operateHexBinaryHexBinary(tp1.binaryp, tp2.binaryp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.binaryp);
+                            booleanResult = aOp.operateHexBinaryHexBinary(tp1.binaryp, tp2.binaryp);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_BASE64_BINARY_TAG:
+                    tvp1.getValue(tp1.binaryp);
+                    switch (tid2) {
                         case ValueTag.XS_BASE64_BINARY_TAG:
-                            tvp1.getValue(tp1.binaryp);
-                            switch (tid2) {
-                                case ValueTag.XS_BASE64_BINARY_TAG:
-                                    tvp2.getValue(tp2.binaryp);
-                                    booleanResult = aOp.operateBase64BinaryBase64Binary(tp1.binaryp, tp2.binaryp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.binaryp);
+                            booleanResult = aOp.operateBase64BinaryBase64Binary(tp1.binaryp, tp2.binaryp);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_ANY_URI_TAG:
+                    tvp1.getValue(tp1.utf8sp);
+                    switch (tid2) {
                         case ValueTag.XS_ANY_URI_TAG:
-                            tvp1.getValue(tp1.utf8sp);
-                            switch (tid2) {
-                                case ValueTag.XS_ANY_URI_TAG:
-                                    tvp2.getValue(tp2.utf8sp);
-                                    booleanResult = aOp.operateAnyURIAnyURI(tp1.utf8sp, tp2.utf8sp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.utf8sp);
+                            booleanResult = aOp.operateAnyURIAnyURI(tp1.utf8sp, tp2.utf8sp);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_QNAME_TAG:
+                    tvp1.getValue(tp1.qnamep);
+                    switch (tid2) {
                         case ValueTag.XS_QNAME_TAG:
-                            tvp1.getValue(tp1.qnamep);
-                            switch (tid2) {
-                                case ValueTag.XS_QNAME_TAG:
-                                    tvp2.getValue(tp2.qnamep);
-                                    booleanResult = aOp.operateQNameQName(tp1.qnamep, tp2.qnamep);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.qnamep);
+                            booleanResult = aOp.operateQNameQName(tp1.qnamep, tp2.qnamep);
                             break;
+                    }
+                    break;
 
+                case ValueTag.XS_NOTATION_TAG:
+                    tvp1.getValue(tp1.utf8sp);
+                    switch (tid2) {
                         case ValueTag.XS_NOTATION_TAG:
-                            tvp1.getValue(tp1.utf8sp);
-                            switch (tid2) {
-                                case ValueTag.XS_NOTATION_TAG:
-                                    tvp2.getValue(tp2.utf8sp);
-                                    booleanResult = aOp.operateNotationNotation(tp1.utf8sp, tp2.utf8sp);
-                                    break;
-                            }
+                            tvp2.getValue(tp2.utf8sp);
+                            booleanResult = aOp.operateNotationNotation(tp1.utf8sp, tp2.utf8sp);
                             break;
                     }
-
-                    byte[] byteResult = new byte[2];
-                    byteResult[0] = ValueTag.XS_BOOLEAN_TAG;
-                    byteResult[1] = (byte) (booleanResult ? 1 : 0);
-                    result.set(byteResult, 0, 2);
-                } catch (SystemException se) {
-                    throw se;
-                } catch (Exception e) {
-                    throw new SystemException(ErrorCode.SYSE0001, e);
-                }
+                    break;
             }
+            return booleanResult;
 
-            private void getIntegerPointable(TypedPointables tp, TaggedValuePointable tvp, DataOutput dOut)
-                    throws SystemException, IOException {
-                long value;
-                switch (tvp.getTag()) {
-                    case ValueTag.XS_INTEGER_TAG:
-                    case ValueTag.XS_LONG_TAG:
-                    case ValueTag.XS_NEGATIVE_INTEGER_TAG:
-                    case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
-                    case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
-                    case ValueTag.XS_POSITIVE_INTEGER_TAG:
-                    case ValueTag.XS_UNSIGNED_INT_TAG:
-                    case ValueTag.XS_UNSIGNED_LONG_TAG:
-                        tvp.getValue(tp.longp);
-                        value = tp.longp.longValue();
-                        break;
-
-                    case ValueTag.XS_INT_TAG:
-                    case ValueTag.XS_UNSIGNED_SHORT_TAG:
-                        tvp.getValue(tp.intp);
-                        value = tp.intp.longValue();
-                        break;
-
-                    case ValueTag.XS_SHORT_TAG:
-                    case ValueTag.XS_UNSIGNED_BYTE_TAG:
-                        tvp.getValue(tp.shortp);
-                        value = tp.shortp.longValue();
-                        break;
-
-                    case ValueTag.XS_BYTE_TAG:
-                        tvp.getValue(tp.bytep);
-                        value = tp.bytep.longValue();
-                        break;
+        } catch (SystemException se) {
+            throw se;
+        } catch (Exception e) {
+            throw new SystemException(ErrorCode.SYSE0001, e);
+        }
+    }
 
-                    default:
-                        value = 0;
-                }
-                dOut.write(ValueTag.XS_INTEGER_TAG);
-                dOut.writeLong(value);
-            }
+    private static void getIntegerPointable(TypedPointables tp, TaggedValuePointable tvp, DataOutput dOut)
+            throws SystemException, IOException {
+        long value;
+        switch (tvp.getTag()) {
+            case ValueTag.XS_INTEGER_TAG:
+            case ValueTag.XS_LONG_TAG:
+            case ValueTag.XS_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_NON_NEGATIVE_INTEGER_TAG:
+            case ValueTag.XS_POSITIVE_INTEGER_TAG:
+            case ValueTag.XS_UNSIGNED_INT_TAG:
+            case ValueTag.XS_UNSIGNED_LONG_TAG:
+                tvp.getValue(tp.longp);
+                value = tp.longp.longValue();
+                break;
+
+            case ValueTag.XS_INT_TAG:
+            case ValueTag.XS_UNSIGNED_SHORT_TAG:
+                tvp.getValue(tp.intp);
+                value = tp.intp.longValue();
+                break;
+
+            case ValueTag.XS_SHORT_TAG:
+            case ValueTag.XS_UNSIGNED_BYTE_TAG:
+                tvp.getValue(tp.shortp);
+                value = tp.shortp.longValue();
+                break;
+
+            case ValueTag.XS_BYTE_TAG:
+                tvp.getValue(tp.bytep);
+                value = tp.bytep.longValue();
+                break;
+
+            default:
+                value = 0;
+        }
+        dOut.write(ValueTag.XS_INTEGER_TAG);
+        dOut.writeLong(value);
+    }
 
-            private int getBaseTypeForComparisons(int tid) throws SystemException {
-                while (true) {
-                    switch (tid) {
-                        case ValueTag.XS_ANY_URI_TAG:
-                        case ValueTag.XS_BASE64_BINARY_TAG:
-                        case ValueTag.XS_BOOLEAN_TAG:
-                        case ValueTag.XS_DATE_TAG:
-                        case ValueTag.XS_DATETIME_TAG:
-                        case ValueTag.XS_DAY_TIME_DURATION_TAG:
-                        case ValueTag.XS_DECIMAL_TAG:
-                        case ValueTag.XS_DOUBLE_TAG:
-                        case ValueTag.XS_DURATION_TAG:
-                        case ValueTag.XS_FLOAT_TAG:
-                        case ValueTag.XS_HEX_BINARY_TAG:
-                        case ValueTag.XS_INTEGER_TAG:
-                        case ValueTag.XS_G_DAY_TAG:
-                        case ValueTag.XS_G_MONTH_DAY_TAG:
-                        case ValueTag.XS_G_MONTH_TAG:
-                        case ValueTag.XS_G_YEAR_MONTH_TAG:
-                        case ValueTag.XS_G_YEAR_TAG:
-                        case ValueTag.XS_QNAME_TAG:
-                        case ValueTag.XS_STRING_TAG:
-                        case ValueTag.XS_TIME_TAG:
-                        case ValueTag.XS_UNTYPED_ATOMIC_TAG:
-                        case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
-                            return tid;
+    private static int getBaseTypeForComparisons(int tid) throws SystemException {
+        while (true) {
+            switch (tid) {
+                case ValueTag.XS_ANY_URI_TAG:
+                case ValueTag.XS_BASE64_BINARY_TAG:
+                case ValueTag.XS_BOOLEAN_TAG:
+                case ValueTag.XS_DATE_TAG:
+                case ValueTag.XS_DATETIME_TAG:
+                case ValueTag.XS_DAY_TIME_DURATION_TAG:
+                case ValueTag.XS_DECIMAL_TAG:
+                case ValueTag.XS_DOUBLE_TAG:
+                case ValueTag.XS_DURATION_TAG:
+                case ValueTag.XS_FLOAT_TAG:
+                case ValueTag.XS_HEX_BINARY_TAG:
+                case ValueTag.XS_INTEGER_TAG:
+                case ValueTag.XS_G_DAY_TAG:
+                case ValueTag.XS_G_MONTH_DAY_TAG:
+                case ValueTag.XS_G_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_MONTH_TAG:
+                case ValueTag.XS_G_YEAR_TAG:
+                case ValueTag.XS_QNAME_TAG:
+                case ValueTag.XS_STRING_TAG:
+                case ValueTag.XS_TIME_TAG:
+                case ValueTag.XS_UNTYPED_ATOMIC_TAG:
+                case ValueTag.XS_YEAR_MONTH_DURATION_TAG:
+                    return tid;
 
-                        case ValueTag.XS_ANY_ATOMIC_TAG:
-                            throw new SystemException(ErrorCode.XPTY0004);
+                case ValueTag.XS_ANY_ATOMIC_TAG:
+                    throw new SystemException(ErrorCode.XPTY0004);
 
-                        default:
-                            tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
-                    }
-                }
+                default:
+                    tid = BuiltinTypeRegistry.INSTANCE.getSchemaTypeById(tid).getBaseType().getTypeId();
             }
-        };
+        }
     }
 
     private static class TypedPointables {

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnIndexOfScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnIndexOfScalarEvaluatorFactory.java?rev=1381373&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnIndexOfScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnIndexOfScalarEvaluatorFactory.java Wed Sep  5 21:15:19 2012
@@ -0,0 +1,85 @@
+package org.apache.vxquery.runtime.functions.sequence;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+import org.apache.vxquery.context.DynamicContext;
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
+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 org.apache.vxquery.runtime.functions.comparison.AbstractValueComparisonOperation;
+import org.apache.vxquery.runtime.functions.comparison.AbstractValueComparisonScalarEvaluatorFactory;
+import org.apache.vxquery.runtime.functions.comparison.ValueEqComparisonOperation;
+
+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.VoidPointable;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+
+public class FnIndexOfScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public FnIndexOfScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+        final ArrayBackedValueStorage abvsInner = new ArrayBackedValueStorage();
+        final DataOutput dOutInner = abvsInner.getDataOutput();
+        final SequenceBuilder sb = new SequenceBuilder();
+        final SequencePointable seq = new SequencePointable();
+        final DynamicContext dCtx = (DynamicContext) ctx.getJobletContext().getGlobalJobData();
+        final AbstractValueComparisonOperation aOp = new ValueEqComparisonOperation();
+        final TaggedValuePointable tvp = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();
+        final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
+
+        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+            @Override
+            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+                try {
+                    abvs.reset();
+                    sb.reset(abvs);
+                    TaggedValuePointable tvp1 = args[0];
+                    TaggedValuePointable tvp2 = args[1];
+
+                    if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                        tvp1.getValue(seq);
+                        int seqLen = seq.getEntryCount();
+                        for (int j = 0; j < seqLen; ++j) {
+                            seq.getEntry(j, p);
+                            tvp.set(p.getByteArray(), p.getStartOffset(), p.getLength());
+                            if (AbstractValueComparisonScalarEvaluatorFactory.compareTaggedValues(aOp, tvp, tvp2, dCtx)) {
+                                abvsInner.reset();
+                                dOutInner.write(ValueTag.XS_INTEGER_TAG);
+                                dOutInner.writeLong(j + 1);
+                                sb.addItem(abvsInner);
+                            }
+                        }
+                    } else {
+                        if (AbstractValueComparisonScalarEvaluatorFactory.compareTaggedValues(aOp, tvp1, tvp2, dCtx)) {
+                            abvsInner.reset();
+                            dOutInner.write(ValueTag.XS_INTEGER_TAG);
+                            dOutInner.writeLong(1);
+                            sb.addItem(abvsInner);
+                        }
+                    }
+                    sb.finish();
+                    result.set(abvs);
+                } catch (IOException e) {
+                    throw new SystemException(ErrorCode.SYSE0001);
+                }
+            }
+        };
+    }
+}
\ No newline at end of file

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

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnInsertBeforeScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnInsertBeforeScalarEvaluatorFactory.java?rev=1381373&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnInsertBeforeScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnInsertBeforeScalarEvaluatorFactory.java Wed Sep  5 21:15:19 2012
@@ -0,0 +1,106 @@
+package org.apache.vxquery.runtime.functions.sequence;
+
+import java.io.IOException;
+
+import org.apache.vxquery.datamodel.accessors.SequencePointable;
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+import org.apache.vxquery.datamodel.builders.sequence.SequenceBuilder;
+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.primitive.VoidPointable;
+import edu.uci.ics.hyracks.data.std.util.ArrayBackedValueStorage;
+
+public class FnInsertBeforeScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public FnInsertBeforeScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
+        final SequenceBuilder sb = new SequenceBuilder();
+        final SequencePointable seq = new SequencePointable();
+        final SequencePointable seq2 = new SequencePointable();
+        final VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
+        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
+        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+            @Override
+            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+                try {
+                    TaggedValuePointable tvp2 = args[1];
+                    if (tvp2.getTag() != ValueTag.XS_INTEGER_TAG) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(longp);
+
+                    abvs.reset();
+                    sb.reset(abvs);
+                    TaggedValuePointable tvp1 = args[0];
+                    TaggedValuePointable tvp3 = args[2];
+                    if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                        tvp1.getValue(seq);
+                        int seqLen = seq.getEntryCount();
+                        if (longp.getLong() < 1) {
+                            // Add to the beginning.
+                            addArgumentToSequence(tvp3);
+                        }
+                        if (seqLen > 0) {
+                            for (int j = 0; j < seqLen; ++j) {
+                                if (longp.getLong() == j + 1) {
+                                    addArgumentToSequence(tvp3);
+                                }
+                                seq.getEntry(j, p);
+                                sb.addItem(p);
+                            }
+                        }
+                        if (longp.getLong() > seqLen) {
+                            // Add to the end.
+                            addArgumentToSequence(tvp3);
+                        }
+
+                    } else {
+                        if (longp.getLong() <= 1) {
+                            addArgumentToSequence(tvp3);
+                            sb.addItem(tvp1);
+                        } else {
+                            sb.addItem(tvp1);
+                            addArgumentToSequence(tvp3);
+                        }
+                    }
+                    sb.finish();
+                    result.set(abvs);
+                } catch (IOException e) {
+                    throw new SystemException(ErrorCode.SYSE0001);
+                }
+            }
+
+            private void addArgumentToSequence(TaggedValuePointable tvp) throws IOException {
+                if (tvp.getTag() == ValueTag.SEQUENCE_TAG) {
+                    tvp.getValue(seq2);
+                    int seqLen = seq2.getEntryCount();
+                    if (seqLen > 0) {
+                        for (int j = 0; j < seqLen; ++j) {
+                            seq2.getEntry(j, p);
+                            sb.addItem(p);
+                        }
+                    }
+                } else {
+                    sb.addItem(tvp);
+                }
+            }
+        };
+    }
+}
\ No newline at end of file

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



Mime
View raw message