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/05 02:36:20 UTC

svn commit: r1380945 - in /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery: functions/ runtime/functions/sequence/

Author: prestonc
Date: Wed Sep  5 00:36:19 2012
New Revision: 1380945

URL: http://svn.apache.org/viewvc?rev=1380945&view=rev
Log:
VXQUERY-75 Added FnRemove, FnSubsequence and FnUnordered.

Added:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnRemoveScalarEvaluatorFactory.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java   (with props)
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnUnorderedScalarEvaluatorFactory.java   (with props)
Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-functions.xml

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=1380945&r1=1380944&r2=1380945&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 00:36:19 2012
@@ -702,6 +702,7 @@
         <param name="target" type="item()*"/>
         <param name="position" type="xs:integer"/>
         <return type="item()*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.FnRemoveScalarEvaluatorFactory"/>
     </function>
 
     <!-- fn:replace($input  as xs:string?, $pattern as xs:string, $replacement as xs:string)  as xs:string -->
@@ -865,6 +866,7 @@
         <param name="sourceSeq" type="item()*"/>
         <param name="startingLoc" type="xs:double"/>
         <return type="item()*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.FnSubsequenceScalarEvaluatorFactory"/>
     </function>
 
     <!-- fn:subsequence($sourceSeq  as item()*, $startingLoc as xs:double, $length as xs:double)  as item()* -->
@@ -873,6 +875,7 @@
         <param name="startingLoc" type="xs:double"/>
         <param name="length" type="xs:double"/>
         <return type="item()*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.FnSubsequenceScalarEvaluatorFactory"/>
     </function>
 
     <!-- fn:substring($sourceString  as xs:string?, $startingLoc as xs:double)  as xs:string -->
@@ -1000,6 +1003,7 @@
     <function name="fn:unordered">
         <param name="sourceSeq" type="item()*"/>
         <return type="item()*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.FnUnorderedScalarEvaluatorFactory"/>
     </function>
 
     <!-- fn:upper-case($arg  as xs:string?) as  xs:string -->

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnRemoveScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnRemoveScalarEvaluatorFactory.java?rev=1380945&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnRemoveScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnRemoveScalarEvaluatorFactory.java Wed Sep  5 00:36:19 2012
@@ -0,0 +1,79 @@
+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 FnRemoveScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public FnRemoveScalarEvaluatorFactory(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 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];
+                    if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                        tvp1.getValue(seq);
+                        int seqLen = seq.getEntryCount();
+                        if (longp.getLong() < 1 || longp.getLong() > seqLen) {
+                            // Position is outside the sequence. Return target.
+                            result.set(tvp1);
+                            return;
+                        } else {
+                            for (int j = 0; j < seqLen; ++j) {
+                                if (longp.getLong() != j + 1) {
+                                    seq.getEntry(j, p);
+                                    sb.addItem(p);
+                                }
+                            }
+                        }
+                    } else if (longp.getLong() != 1) {
+                        // Position does not match the item. Return target.
+                        result.set(tvp1);
+                        return;
+                    }
+                    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/FnRemoveScalarEvaluatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java?rev=1380945&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnSubsequenceScalarEvaluatorFactory.java Wed Sep  5 00:36:19 2012
@@ -0,0 +1,130 @@
+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.accessors.atomic.XSDecimalPointable;
+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.numeric.FnRoundOperation;
+
+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.DoublePointable;
+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 FnSubsequenceScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public FnSubsequenceScalarEvaluatorFactory(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 VoidPointable p = (VoidPointable) VoidPointable.FACTORY.createPointable();
+        final DoublePointable doublep = (DoublePointable) DoublePointable.FACTORY.createPointable();
+        final LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
+        final XSDecimalPointable decp = (XSDecimalPointable) XSDecimalPointable.FACTORY.createPointable();
+        final ArrayBackedValueStorage abvsRound = new ArrayBackedValueStorage();
+        final FnRoundOperation round = new FnRoundOperation();
+        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+            @Override
+            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+                try {
+                    long startingLoc;
+                    TaggedValuePointable tvp2 = args[1];
+                    // XQuery Specification calls for double value. Integer and Decimal are allowed to cut down
+                    // on casting.
+                    if (tvp2.getTag() == ValueTag.XS_DOUBLE_TAG) {
+                        tvp2.getValue(doublep);
+                        abvsRound.reset();
+                        round.operateDouble(doublep, abvsRound.getDataOutput());
+                        doublep.set(abvsRound.getByteArray(), abvsRound.getStartOffset() + 1,
+                                DoublePointable.TYPE_TRAITS.getFixedLength());
+                        startingLoc = doublep.longValue();
+                    } else if (tvp2.getTag() == ValueTag.XS_INTEGER_TAG) {
+                        tvp2.getValue(longp);
+                        startingLoc = longp.longValue();
+                    } else if (tvp2.getTag() == ValueTag.XS_DECIMAL_TAG) {
+                        tvp2.getValue(decp);
+                        startingLoc = decp.longValue();
+                    } else {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    if (startingLoc < 1) {
+                        startingLoc = 1;
+                    }
+
+                    // Get length.
+                    long endingLoc = Long.MAX_VALUE;
+                    if (args.length > 2) {
+                        TaggedValuePointable tvp3 = args[2];
+                        // XQuery Specification calls for double value. Integer and Decimal are allowed to cut down
+                        // on casting.
+                        if (tvp3.getTag() == ValueTag.XS_DOUBLE_TAG) {
+                            tvp3.getValue(doublep);
+                            abvsRound.reset();
+                            round.operateDouble(doublep, abvsRound.getDataOutput());
+                            doublep.set(abvsRound.getByteArray(), abvsRound.getStartOffset() + 1,
+                                    DoublePointable.TYPE_TRAITS.getFixedLength());
+                            endingLoc = startingLoc + doublep.longValue();
+                        } else if (tvp3.getTag() == ValueTag.XS_INTEGER_TAG) {
+                            tvp3.getValue(longp);
+                            endingLoc = startingLoc + longp.longValue();
+                        } else if (tvp3.getTag() == ValueTag.XS_DECIMAL_TAG) {
+                            tvp3.getValue(decp);
+                            endingLoc = startingLoc + decp.longValue();
+                        } else {
+                            throw new SystemException(ErrorCode.FORG0006);
+                        }
+                    }
+
+                    abvs.reset();
+                    sb.reset(abvs);
+                    TaggedValuePointable tvp1 = args[0];
+                    if (tvp1.getTag() == ValueTag.SEQUENCE_TAG) {
+                        tvp1.getValue(seq);
+                        int seqLen = seq.getEntryCount();
+                        if (endingLoc < startingLoc) {
+                            // Empty sequence.
+                        } else if (startingLoc == 1 && endingLoc > seqLen) {
+                            // Includes whole sequence.
+                            result.set(tvp1);
+                            return;
+                        } else {
+                            for (int j = 0; j < seqLen; ++j) {
+                                if (startingLoc <= j + 1 && j + 1 < endingLoc) {
+                                    seq.getEntry(j, p);
+                                    sb.addItem(p);
+                                }
+                            }
+                        }
+                    } else if (startingLoc == 1 && endingLoc > 1) {
+                        // Includes item.
+                        result.set(tvp1);
+                        return;
+                    }
+                    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/FnSubsequenceScalarEvaluatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnUnorderedScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnUnorderedScalarEvaluatorFactory.java?rev=1380945&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnUnorderedScalarEvaluatorFactory.java (added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/FnUnorderedScalarEvaluatorFactory.java Wed Sep  5 00:36:19 2012
@@ -0,0 +1,31 @@
+package org.apache.vxquery.runtime.functions.sequence;
+
+import org.apache.vxquery.datamodel.accessors.TaggedValuePointable;
+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;
+
+public class FnUnorderedScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory {
+    private static final long serialVersionUID = 1L;
+
+    public FnUnorderedScalarEvaluatorFactory(IScalarEvaluatorFactory[] args) {
+        super(args);
+    }
+
+    @Override
+    protected IScalarEvaluator createEvaluator(IHyracksTaskContext ctx, IScalarEvaluator[] args)
+            throws AlgebricksException {
+        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+            @Override
+            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws SystemException {
+                result.set(args[0]);
+            }
+        };
+    }
+}
\ No newline at end of file

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