[SYSTEMML-2377] Fix rewrite 'fuse order operation chains' (for overlap)

This patch fixes special cases where the rewrite for fusing multiple
sort operators w/ single by attributes into a single sort operator w/ a
list of by attributes led to runtime exceptions. Specifically, we now
fuse these operations under awareness of potential overlap.


Project: http://git-wip-us.apache.org/repos/asf/systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/0177a131
Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/0177a131
Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/0177a131

Branch: refs/heads/master
Commit: 0177a13108cd6fca80609dab029572b40b02d13c
Parents: 37e6603
Author: Matthias Boehm <[email protected]>
Authored: Sat Jun 9 00:38:02 2018 -0700
Committer: Matthias Boehm <[email protected]>
Committed: Sat Jun 9 00:38:02 2018 -0700

----------------------------------------------------------------------
 .../hops/rewrite/RewriteAlgebraicSimplificationStatic.java    | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/0177a131/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
 
b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
index db28a18..8f9aad9 100644
--- 
a/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
+++ 
b/src/main/java/org/apache/sysml/hops/rewrite/RewriteAlgebraicSimplificationStatic.java
@@ -21,8 +21,10 @@ package org.apache.sysml.hops.rewrite;
 
 import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -1475,16 +1477,19 @@ public class RewriteAlgebraicSimplificationStatic 
extends HopRewriteRule
                        boolean desc = 
HopRewriteUtils.getBooleanValue((LiteralOp)hi.getInput().get(2));
                        
                        //find chain of order operations with same desc/ixret 
configuration and single consumers
+                       Set<String> probe = new HashSet<>();
                        ArrayList<LiteralOp> byList = new 
ArrayList<LiteralOp>();
-                       byList.add(by);
+                       byList.add(by); probe.add(by.getStringValue());
                        Hop input = hi.getInput().get(0);
                        while( HopRewriteUtils.isReorg(input, ReOrgOp.SORT)
                                && input.getInput().get(1) instanceof LiteralOp 
//scalar by
+                               && 
!probe.contains(input.getInput().get(1).getName())
                                && 
HopRewriteUtils.isLiteralOfValue(input.getInput().get(2), desc)
                                && 
HopRewriteUtils.isLiteralOfValue(hi.getInput().get(3), false)
                                && input.getParent().size() == 1 ) 
                        {
                                byList.add((LiteralOp)input.getInput().get(1));
+                               probe.add(input.getInput().get(1).getName());
                                input = input.getInput().get(0);
                        }
                        

Reply via email to