incubator-vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prest...@apache.org
Subject svn commit: r1383671 - in /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery: functions/builtin-operators.xml runtime/functions/sequence/OpToScalarEvaluatorFactory.java
Date Tue, 11 Sep 2012 23:39:57 GMT
Author: prestonc
Date: Tue Sep 11 23:39:57 2012
New Revision: 1383671

URL: http://svn.apache.org/viewvc?rev=1383671&view=rev
Log:
Added Op:To.

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

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml?rev=1383671&r1=1383670&r2=1383671&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
(original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
Tue Sep 11 23:39:57 2012
@@ -471,6 +471,7 @@
         <param name="firstval" type="xs:integer"/>
         <param name="lastval" type="xs:integer"/>
         <return type="xs:integer*"/>
+        <runtime type="scalar" class="org.apache.vxquery.runtime.functions.sequence.OpToScalarEvaluatorFactory"/>
     </operator>
 
     <!-- op:union($parameter1  as node()*, $parameter2 as node()*)  as node()* -->

Added: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/OpToScalarEvaluatorFactory.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/OpToScalarEvaluatorFactory.java?rev=1383671&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/OpToScalarEvaluatorFactory.java
(added)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/sequence/OpToScalarEvaluatorFactory.java
Tue Sep 11 23:39:57 2012
@@ -0,0 +1,78 @@
+package org.apache.vxquery.runtime.functions.sequence;
+
+import java.io.DataOutput;
+import java.io.IOException;
+
+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.datamodel.values.XDMConstants;
+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 OpToScalarEvaluatorFactory extends AbstractTaggedValueArgumentScalarEvaluatorFactory
{
+    private static final long serialVersionUID = 1L;
+
+    public OpToScalarEvaluatorFactory(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 LongPointable longp = (LongPointable) LongPointable.FACTORY.createPointable();
+
+        return new AbstractTaggedValueArgumentScalarEvaluator(args) {
+            @Override
+            protected void evaluate(TaggedValuePointable[] args, IPointable result) throws
SystemException {
+                try {
+                    TaggedValuePointable tvp1 = args[0];
+                    if (tvp1.getTag() != ValueTag.XS_INTEGER_TAG) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp1.getValue(longp);
+                    long start = longp.getLong();
+
+                    TaggedValuePointable tvp2 = args[1];
+                    if (tvp2.getTag() != ValueTag.XS_INTEGER_TAG) {
+                        throw new SystemException(ErrorCode.FORG0006);
+                    }
+                    tvp2.getValue(longp);
+                    long end = longp.getLong();
+
+                    abvs.reset();
+                    sb.reset(abvs);
+                    if (start > end) {
+                        XDMConstants.setEmptySequence(result);
+                        return;
+                    } else {
+                        for (long j = start; j <= end; ++j) {
+                            abvsInner.reset();
+                            dOutInner.write(ValueTag.XS_INTEGER_TAG);
+                            dOutInner.writeLong(j);
+                            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/OpToScalarEvaluatorFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message