1 22 23 package org.xquark.extractor.algebra; 24 25 import java.util.*; 26 27 import org.xquark.extractor.common.Debug; 28 import org.xquark.extractor.common.MessageLibrary; 29 import org.xquark.extractor.common.SqlWrapperException; 30 31 public final class AnalyzePredicateHandUpVisitor extends DefaultAlgebraVisitor { 32 private static final String RCSRevision = "$Revision: 1.4 $"; 33 private static final String RCSName = "$Name: $"; 34 35 List _predicateList = null; 36 Set _referredTI = null; 37 Expression _blockingNode = null; 38 39 public AnalyzePredicateHandUpVisitor() { 40 } 41 42 public void reinit() { 43 _predicateList = null; 44 _referredTI = null; 45 _blockingNode = null; 46 } 47 48 public void setPredicateList(List predicateList) { 49 _predicateList = predicateList; 50 } 51 52 public boolean isBlocked() { 53 return null != _blockingNode; 54 } 55 56 public Expression getBlockingNode() { 57 return _blockingNode; 58 } 59 60 public List getUnresolvedPredicateList() { 61 return _predicateList; 62 } 63 64 public void visit(Expression arg) { 65 visitFather(arg); 66 } 67 68 public void visit(Join arg) throws SqlWrapperException { 69 71 Set visibleTI = arg.visibleTableInstances(); 72 73 Set referedTI = null; 74 Expression predicate = null; 75 for (int i = _predicateList.size() - 1; i >= 0; i--) { 76 predicate = (Expression) _predicateList.get(i); 77 referedTI = predicate.getReferredTableInstances(); 78 if (visibleTI.containsAll(referedTI)) { 79 _predicateList.remove(predicate); 80 arg.addPredicate(predicate); 81 } 82 } 83 84 if (!_predicateList.isEmpty()) { 85 visitFather(arg); 86 } 87 88 } 90 91 public void visit(RenameRelation arg) throws SqlWrapperException { 92 94 Set visibleTI = arg.visibleTableInstances(); 95 Debug.assertTrue(1 == visibleTI.size(), "1 == visibleTI.size()"); 96 Map replaceMap = new HashMap(); 97 98 Expression ti = null; 99 for (Iterator i = visibleTI.iterator(); i.hasNext();) { 100 ti = (Expression) i.next(); 101 if (ti instanceof RenameRelation) { 102 replaceMap.put(ti, arg); 103 } 104 } 105 106 TopDownReplacer replacer = new TopDownReplacer(replaceMap); 107 Expression predicate = null; 108 for (int i = 0; i < _predicateList.size(); i++) { 109 predicate = (Expression) _predicateList.get(i); 110 predicate.accept(replacer); 111 } 112 113 visitFather(arg); 114 115 } 117 118 public void visit(UnOpProject arg) { 119 121 if (arg.getDistinct()) { 122 visitProjectDistinct(arg); 123 } else { 124 visitProject(arg); 125 } 126 127 } 129 130 protected void visitFather(Expression arg) { 131 Expression father = arg.getFather(); 133 if (father != null) { 134 father.accept(this); 135 } else { 136 throw new SqlWrapperException(MessageLibrary.getMessage("IE_ERR", "Can not arrange predicate " 137 ), null); 138 } 139 140 } 142 private void visitProjectDistinct(UnOpProject arg) { 143 _blockingNode = arg; 145 } 147 148 private void visitProject(UnOpProject arg) { 149 Debug.nyi("visitProject(UnOpProject arg)"); 150 } 151 152 } 153 | Popular Tags |