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 2013/08/28 06:33:41 UTC

svn commit: r1518072 - /incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java

Author: prestonc
Date: Wed Aug 28 04:33:40 2013
New Revision: 1518072

URL: http://svn.apache.org/r1518072
Log:
Updated the comments and moved DATASOURCESCAN operator into the Cardinality.MANY setting.

Modified:
    incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java

Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java?rev=1518072&r1=1518071&r2=1518072&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/compiler/rewriter/rules/RemoveUnusedSortDistinctNodesRule.java Wed Aug 28 04:33:40 2013
@@ -47,6 +47,50 @@ import edu.uci.ics.hyracks.algebricks.co
 import edu.uci.ics.hyracks.algebricks.core.algebra.operators.logical.UnnestOperator;
 import edu.uci.ics.hyracks.algebricks.core.rewriter.base.IAlgebraicRewriteRule;
 
+/**
+ * The rule searches for where the xquery sort distinct function is used and
+ * determines if the sort and distinct is necessary. The plan is modified if
+ * any of these items is not required.
+ * 
+ * <pre>
+ * Before
+ * 
+ *   plan__parent
+ *   ASSIGN( $v1 : sort_distinct_nodes_asc_or_atomics( $v0 ) )
+ *   plan__child
+ *   
+ *   Where $v0 is a variable defined in plan__child.
+ *   
+ * After 
+ * 
+ *   if ( $v0 is unique nodes && $v0 is in document order )
+ *     
+ *     plan__parent
+ *     ASSIGN( $v1 : $v0 )
+ *     plan__child
+ *     
+ *   if ( $v0 is NOT unique nodes && $v0 is in document order )
+ *   
+ *     plan__parent
+ *     ASSIGN( $v1 : distinct_nodes_or_atomics( $v0 ) )
+ *     plan__child
+ *     
+ *   if ( $v0 is unique nodes && $v0 is NOT in document order )
+ *   
+ *     plan__parent
+ *     ASSIGN( $v1 : sort_nodes_asc( $v0 ) )
+ *     plan__child
+ *     
+ *   if ( $v0 is NOT unique nodes && $v0 is NOT in document order )
+ *   
+ *     plan__parent
+ *     ASSIGN( $v1 : sort_distinct_nodes_asc_or_atomics( $v0 ) )
+ *     plan__child
+ * </pre>
+ * 
+ * @author prestonc
+ */
+
 public class RemoveUnusedSortDistinctNodesRule implements IAlgebraicRewriteRule {
 
     @Override
@@ -54,10 +98,6 @@ public class RemoveUnusedSortDistinctNod
         return false;
     }
 
-    /**
-     * Find where a sort distinct nodes is being used and not required based on input parameters.
-     * Search pattern: assign [function-call: sort-distinct-nodes-asc-or-atomics]
-     */
     @Override
     public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) {
         boolean operatorChanged = false;
@@ -313,13 +353,13 @@ public class RemoveUnusedSortDistinctNod
                         .getNestedPlans().get(0).getRoots().get(0).getValue();
                 cardinalityVariable = vxqueryContext.getCardinalityOperatorMap(lastOperator);
                 break;
+            case DATASOURCESCAN:
             case UNNEST:
                 cardinalityVariable = Cardinality.MANY;
                 break;
 
             // The following operators do not change the variable.
             case ASSIGN:
-            case DATASOURCESCAN:
             case EMPTYTUPLESOURCE:
             case EXCHANGE:
             case LIMIT: