You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by ti...@apache.org on 2010/06/06 21:46:57 UTC

svn commit: r951938 - in /incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery: functions/builtin-operators.xml runtime/functions/OpIntersectIterator.java xmlquery/query/XMLQueryTranslator.java

Author: tillw
Date: Sun Jun  6 19:46:56 2010
New Revision: 951938

URL: http://svn.apache.org/viewvc?rev=951938&view=rev
Log:
- added op:intersect
- some slightly better exception messages


Added:
    incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpIntersectIterator.java
Modified:
    incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
    incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java

Modified: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml?rev=951938&r1=951937&r2=951938&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml (original)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml Sun Jun  6 19:46:56 2010
@@ -245,6 +245,8 @@
         <param name="parameter1" type="node()*"/>
         <param name="parameter2" type="node()*"/>
         <return type="node()*"/>
+        <!-- implementation assumes input in document order -->
+        <runtime class="org.apache.vxquery.runtime.functions.OpIntersectIterator"/>
     </operator>
 
     <!-- op:is-same-node($parameter1  as node(), $parameter2 as node())  as xs:boolean -->

Added: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpIntersectIterator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpIntersectIterator.java?rev=951938&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpIntersectIterator.java (added)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpIntersectIterator.java Sun Jun  6 19:46:56 2010
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.vxquery.runtime.functions;
+
+import org.apache.vxquery.context.StaticContext;
+import org.apache.vxquery.datamodel.XDMNode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.functions.Function;
+import org.apache.vxquery.runtime.CallStackFrame;
+import org.apache.vxquery.runtime.RegisterAllocator;
+import org.apache.vxquery.runtime.base.AbstractLazilyEvaluatedFunctionIterator;
+import org.apache.vxquery.runtime.base.RuntimeIterator;
+
+public class OpIntersectIterator extends AbstractLazilyEvaluatedFunctionIterator {
+    public OpIntersectIterator(RegisterAllocator rAllocator, Function fn, RuntimeIterator[] arguments, StaticContext ctx) {
+        super(rAllocator, fn, arguments, ctx);
+    }
+
+    @Override
+    public void close(CallStackFrame frame) {
+        arguments[1].close(frame);
+        arguments[0].close(frame);
+    }
+
+    @Override
+    public Object next(CallStackFrame frame) throws SystemException {
+        XDMNode right = (XDMNode) arguments[1].next(frame);
+        if (right == null) {
+            return null;
+        }
+        XDMNode left = (XDMNode) arguments[0].next(frame);
+        while (true) {
+            while (left != null && left.compareDocumentOrder(right) < 0) {
+                left = (XDMNode) arguments[0].next(frame);
+            }
+            if (left == null) {
+                return null;
+            }
+            while (right != null && left.compareDocumentOrder(right) > 0) {
+                right = (XDMNode) arguments[1].next(frame);
+            }
+            if (right == null) {
+                return null;
+            }
+            if (left.isSameNode(right)) {
+                return left;
+            }
+        }
+    }
+
+    @Override
+    public void open(CallStackFrame frame) {
+        arguments[0].open(frame);
+        arguments[1].open(frame);
+    }
+}
\ No newline at end of file

Modified: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java?rev=951938&r1=951937&r2=951938&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java (original)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/xmlquery/query/XMLQueryTranslator.java Sun Jun  6 19:46:56 2010
@@ -651,7 +651,7 @@ final class XMLQueryTranslator {
             }
 
             case SCHEMA_ATTRIBUTE_TEST: {
-                throw new UnsupportedOperationException();
+                throw new UnsupportedOperationException("schema-attribute(...) is not supported");
             }
 
             case ELEMENT_TEST: {
@@ -688,7 +688,7 @@ final class XMLQueryTranslator {
             }
 
             case SCHEMA_ELEMENT_TEST: {
-                throw new UnsupportedOperationException();
+                throw new UnsupportedOperationException("schema-element(...) is not supported");
             }
 
             default:
@@ -730,6 +730,10 @@ final class XMLQueryTranslator {
                 Signature sign = operator.getSignature();
                 Expression arg1 = normalize(currCtx, translateExpression(ie.getLeftExpr()), sign.getParameterType(0));
                 Expression arg2 = normalize(currCtx, translateExpression(ie.getRightExpr()), sign.getParameterType(1));
+                if (BuiltinOperators.EXCEPT.equals(operator) || BuiltinOperators.INTERSECT.equals(operator)) {
+                    arg1 = ExpressionBuilder.functionCall(currCtx, BuiltinOperators.SORT_DISTINCT_NODES_ASC, arg1);
+                    arg2 = ExpressionBuilder.functionCall(currCtx, BuiltinOperators.SORT_DISTINCT_NODES_ASC, arg2);
+                }
                 Expression result = ExpressionBuilder.functionCall(currCtx, operator, arg1, arg2);
                 if (BuiltinOperators.UNION.equals(operator)) {
                     result = ExpressionBuilder.functionCall(currCtx, BuiltinOperators.SORT_DISTINCT_NODES_ASC, result);