edu.wpi.cs.dsrg.xmldb.xat.component.xatrewrite
Class ReWriteRules

java.lang.Object
  |
  +--edu.wpi.cs.dsrg.xmldb.xat.common.visitorpattern.InheritableVisitor
        |
        +--edu.wpi.cs.dsrg.xmldb.xat.common.visitorpattern.TwoParamVisitor
              |
              +--edu.wpi.cs.dsrg.xmldb.xat.component.xatrewrite.ReWriteRules
Direct Known Subclasses:
CancelOutNavigateRules, ComputationPushdownRules, MergeOperatorRules, ReWriteOrderByRules, ReWritePositionRules

public class ReWriteRules
extends TwoParamVisitor

This class is the super class for all equivalence rule classes.

 An object of this class is created with a Vector of Strings containing the order
 of classes to look at when trying to find a rule for 2 operators. 

 Calls are then made to evaluateRules with 2 nodes that the user wishes to evalute. 
 The TwoParamVisitor class from the visitorpattern package is used to determine the correct 
 equivalence rule to use for a given pair of XATOperators. This is done by iterating over 
 the classes provided in the classVector and calling the visit(Object, Object) method of each class. 
 
 If a rule is not found in a class, the next class is looked at.  If no rules are found for a given
 pair, an ReWriteRulesNoRulesFound exception is thrown.
 
 Equivalence rules are defined in subclasses named after the parent operator.  ReWriteNavigationRules
 defines the equivalence rules for Navigate Operators.  ReWriteOrderByRules defines the
 equivalence rules for OrderBy Operators and so on. 
 
 A rule is a method in the strucure of visit(XATOperator parent, XATOperator child).  The rule
 for swapping a Navigate with a Source is defined in ReWriteNavigationRules.visit(Navigate, Source). 
 Each rule will perform modififactions neccessary for the swap of the two operators if such a swap is
 possible.  If the nodes can be swapped, the rule will do so. 
 See each rule for the logic behind that rule.  Each rule returns a ReWriteResult object. 
 This object will tell the calling program if the Operators were be swapped, is the parent in its
 final position, and should either node be deleted.  
 

Since:
1.0
See Also:
ReWriteResult

Field Summary
protected  java.util.Vector classVector
          Vector that contains the list and order of rule classes to look at.
protected  ReWriteResult result
          ReWriteResult that describes the results from performing the Equivalence Rule
protected static java.util.Hashtable statis
          Hashtable to keep the rule statistics of this rewrite rules In the format of "method obj, Integer count".
protected  BindingTable variableTable
          BindingTable that is used to store the variables and the associated columnPaths
 
Constructor Summary
ReWriteRules()
          Default ReWriteRules constructor.
ReWriteRules(java.util.Vector sourceList)
          ReWriteRules constructor.
ReWriteRules(java.util.Vector sourceList, BindingTable varList)
          Constructor that accepts a Vector sourceList that is set to classVector and a Hashtable that is set to variableTable.
 
Method Summary
protected  NavigationStep[] combineSteps(NavigationStep[] entryPoint, NavigationStep[] destination)
          This method puts the entryPoint and destination step arrays of a Navigate Operator into 1 bigger array to make it easier to manipulate.
protected  boolean copyNode(XATNode parent, XATNode child)
          Replacing the child node with parent node.
 java.lang.String createString(NavigationStep[] step)
          Convert an array of NavigationStep into String.
 boolean deleteAggregate(XATNode param)
          Decide if an given Aggregate operator can be deleted or not.
 boolean deletePartialTagger(DOMPatternNode rootNode)
          Deprecated.  
 boolean deleteWholeTagger(DOMPatternNode rootNode)
          Deprecated.  
 java.lang.Object dispatch()
          To visit a null object.
 java.lang.Object dispatch(java.lang.Object object)
          To visit any object.
 java.lang.Object dispatch(java.lang.Object object1, java.lang.Object object2)
          To visit two objects.
 ReWriteResult evaluateRules(XATNode parent)
          Evaluate the rules over 2 XATOperators.
 ReWriteResult evaluateRules(XATNode parent, XATNode child)
          Evaluate the rules over 2 XATOperators.
protected  boolean findMatchingNavigationNode(java.lang.String binding, XATNode root)
          An alternate definition for findMatchingNavigationNode.
protected  boolean findMatchingNavigationNode(VarStep entryPoint, XATNode root)
          Find a Navigate operator whose binding matches the entryPoint array.
protected  void getChildren(java.util.Vector destinationVector, XATNode root)
          Get all children of a given root node.
protected  void getColumnNames(BinExpression exp, java.util.Vector columnNames)
          Iterates over the BinExpression in order to find all of the column Names anytime a column name is found, it is added into the Vector.
static java.util.Hashtable getStatis()
          Return the statistics of the rewrite rules.
 BindingTable getVariableTable()
          Insert the method's description here.
protected  boolean isDebug()
          Get the value of the propertity 'DEBUG_NavTaggerCancelout'.
protected  boolean isGatherStatistics()
          A flag to check whether to get the statistics from rewrite rules.
protected  boolean isUsedAbove(XATNode startingPoint, java.lang.String columnToFind)
          traverse up the tree, starting from the startingPoint parameter, checking if columnToFind is used in any entry point in a Navigate, parameter in a Select, or column in a Tagger.
protected  void moveNode(XATNode parent, XATNode child)
           MoveNode will alter the XATTree structue by moving the parent node directly under the child.
protected  void moveNodeToRoot(XATNode root, XATNode nodeToMove)
           MoveNodeToRoot will alter the XATTree structue by moving the node to the root.
 void setDebug(boolean newDebug)
          Insert the method's description here.
 void setVariableTable(BindingTable newVariableTable)
          Insert the method's description here.
protected  void swap(XATOperator operator1, XATOperator operator2)
          Swaps the operators of 2 nodes.
 java.lang.Object visit(java.lang.Object object)
          If there is an inheretance between the visited objects, it will only match the highest class.
 java.lang.Object visit(java.lang.Object obj1, java.lang.Object obj2)
          We add funtionality to print out the rules used in this rewrite.
 
Methods inherited from class edu.wpi.cs.dsrg.xmldb.xat.common.visitorpattern.TwoParamVisitor
getMethod, visit
 
Methods inherited from class edu.wpi.cs.dsrg.xmldb.xat.common.visitorpattern.InheritableVisitor
getAncestors, getMethod, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

result

protected ReWriteResult result
ReWriteResult that describes the results from performing the Equivalence Rule
Since:
1.0

classVector

protected java.util.Vector classVector
Vector that contains the list and order of rule classes to look at.
Since:
1.0

variableTable

protected BindingTable variableTable
BindingTable that is used to store the variables and the associated columnPaths
Since:
1.0

statis

protected static java.util.Hashtable statis
Hashtable to keep the rule statistics of this rewrite rules In the format of "method obj, Integer count". This is an object for all the instances of this class.
Since:
1.0
Constructor Detail

ReWriteRules

public ReWriteRules()
Default ReWriteRules constructor.
Since:
1.0

ReWriteRules

public ReWriteRules(java.util.Vector sourceList)
ReWriteRules constructor.
Parameters:
sourceList - The list of operator types being considered to apply this rewrite rule.
Since:
1.0
See Also:
BindingTable

ReWriteRules

public ReWriteRules(java.util.Vector sourceList,
                    BindingTable varList)
Constructor that accepts a Vector sourceList that is set to classVector and a Hashtable that is set to variableTable. The result object is instantiated.
Parameters:
sourceList - The list of operator types being considered to apply this rewrite rule.
BindingTable - The binding table of given XAT.
Since:
1.0
See Also:
BindingTable
Method Detail

combineSteps

protected NavigationStep[] combineSteps(NavigationStep[] entryPoint,
                                        NavigationStep[] destination)
This method puts the entryPoint and destination step arrays of a Navigate Operator into 1 bigger array to make it easier to manipulate.
Parameters:
entryPoint - The entry point of Navigate operator.
destination - The destination of Navigate operator.
Returns:
NavigationStep[] The array for combined Navigation Steps.
Since:
1.0
See Also:
NavigationStep

copyNode

protected boolean copyNode(XATNode parent,
                           XATNode child)
Replacing the child node with parent node.
 This method will alter the XATTree structue by copying the parent
 node directly replace child. The child's children will be altered to
 point to parent. This is primarily used to copy a node under the correct 
 Join / Union branch.

  Structure of tree 
 parent = x2, child = x4
   
   	old structure
   	x1 -> x2 ---> x3 -> x4
   
   	new structure
   	x1 -> x2 ---> x3 -> Clone of x2 -> x4
 
Parameters:
parent - The parent node.
child - The child node.
Returns:
boolean The boolean value indicates operation finished successfully.
Since:
1.0
See Also:
swap

createString

public java.lang.String createString(NavigationStep[] step)
Convert an array of NavigationStep into String. This method accepts an array of NavigationSteps and will convert these steps into one long string. If a VarStep is found, it will be replaced by the actual column name(s) as found in this.variableTable The array is formatted with "/" between steps. A "/" is added at the end of the string as well
Parameters:
step - NavigationStep from which to create a string.
Returns:
String The result corresponding step string.
Since:
1.0
See Also:
NavigationStep

deleteAggregate

public boolean deleteAggregate(XATNode param)
Decide if an given Aggregate operator can be deleted or not. The given Aggregrate operator can be deleted if either its parent or child is not a Tagger.
Parameters:
param - The node of Aggregrate operator.
Returns:
boolean True: if the aggregate can be deleted. False: otherwise.
Since:
1.0
See Also:
Tagger, Aggregate

deletePartialTagger

public boolean deletePartialTagger(DOMPatternNode rootNode)
Deprecated.  

Decide if a Tagger operator can be deleted or not. This method will iterate over a Tagger operator and determine if the operator can be deleted or not. A Tagger may be deleted when all of its nodes have been cancelout
Parameters:
rootNode - The root of the DOMPattern to start iterating over.
Returns:
boolean True: if the tagger can be deleted. False: otherwise.
Since:
1.0
See Also:
Tagger, DOMPatternNode, RootNodeImp

deleteWholeTagger

public boolean deleteWholeTagger(DOMPatternNode rootNode)
Deprecated.  

Decide if the Tagger can be deleted or not. This method will iterate over a Tagger operator and determine if the operator can be deleted or not. A Tagger may be deleted when all of its nodes have been cancelout.
Parameters:
rootNode - The root of the DOMPattern to start iterating over.
Returns:
boolean True: if the tagger can be deleted. False: otherwise.
Since:
1.0
See Also:
Tagger, RootNodeImp, DOMPatternNode

dispatch

public java.lang.Object dispatch()
Description copied from class: InheritableVisitor
To visit a null object.
Overrides:
dispatch in class InheritableVisitor

dispatch

public java.lang.Object dispatch(java.lang.Object object)
Description copied from class: InheritableVisitor
To visit any object.
Overrides:
dispatch in class InheritableVisitor

dispatch

public java.lang.Object dispatch(java.lang.Object object1,
                                 java.lang.Object object2)
Description copied from class: TwoParamVisitor
To visit two objects.
Overrides:
dispatch in class TwoParamVisitor

evaluateRules

public ReWriteResult evaluateRules(XATNode parent)
                            throws ReWriteRulesNoRulesFound
Evaluate the rules over 2 XATOperators. This method uses java.lang.reflect methods to instantiate the classes in this.classVector. The method iterates over the classes, instantiates the class, then calls the visit function with the operators of parent and child. If no rule is found, the next class is instantiated and the process repeats itself. the function returns true if the function cannot be pushedDown further otherwise it returns false
Parameters:
parent - The parent node that we will try to find a rule for.
Returns:
ReWriteResult An object containing a summary of what was performed by the rule.
Throws:
ReWriteRulesNoRulesFound - Exception thrown when the system has looked at all classes in the classVector and is unable to find a rule for parent and child.
Since:
1.0
See Also:
ReWriteResult

evaluateRules

public ReWriteResult evaluateRules(XATNode parent,
                                   XATNode child)
                            throws ReWriteRulesNoRulesFound
Evaluate the rules over 2 XATOperators. This method uses java.lang.reflect methods to instantiate the classes in this.classVector. The method iterates over the classes, instantiates the class, then calls the visit function with the operators of parent and child. If no rule is found, the next class is instantiated and the process repeats itself. the function returns true if the function cannot be pushedDown further otherwise it returns false
Parameters:
parent - The parent node that we will try to find a rule for.
child - The child node that we will try to find a rule for.
Returns:
ReWriteResult An object containing a summary of what was performed by the rule.
Throws:
ReWriteRulesNoRulesFound - Exception thrown when the system has looked at all classes in the classVector and is unable to find a rule for parent and child.
Since:
1.0
See Also:
ReWriteResult

findMatchingNavigationNode

protected boolean findMatchingNavigationNode(VarStep entryPoint,
                                             XATNode root)
Find a Navigate operator whose binding matches the entryPoint array. This method accepts a NavigationStep[] entryPoint and will find a Navigate operator whose binding matches the entryPoint array. This is used to match a Navigate with a Navigate and is useful when trying to determine which side of a join a Navigate matches A Navigate's entryPoint is to be matched with the binding of another
Parameters:
entryPoint - The EntryPoint to match.
root - The root node to start looking at.
Returns:
boolean True: if a match is found. False: otherwise.
Since:
1.0
See Also:
VarStep

findMatchingNavigationNode

protected boolean findMatchingNavigationNode(java.lang.String binding,
                                             XATNode root)
An alternate definition for findMatchingNavigationNode. This method takes the binding parameter, converts it to a NavigationStep[] and calls the other findMatchingNavigationNode method.
Parameters:
binding - The binding of a Navigate operator to the match.
root - The root node to start looking at.
Returns:
boolean True if a match is found. False: otherwise.
Since:
1.0
See Also:
VarStepImp, findMatchingNavigationNode

getChildren

protected void getChildren(java.util.Vector destinationVector,
                           XATNode root)
Get all children of a given root node. This method accepts a destination Vector and an XATNode and all of the root's children are puts into destinationVector This is used to convert the root's children (stored as arrays) into a Vector.
Parameters:
destinationVector - The vector to hold all children nodes.
root - The root XATNode to get the children from.
Returns:
void
Since:
1.0
See Also:
XATNode

getColumnNames

protected void getColumnNames(BinExpression exp,
                              java.util.Vector columnNames)
Iterates over the BinExpression in order to find all of the column Names anytime a column name is found, it is added into the Vector.
Parameters:
exp - Expression
Returns:
boolean

getStatis

public static java.util.Hashtable getStatis()
Return the statistics of the rewrite rules.
Since:
1.0

getVariableTable

public BindingTable getVariableTable()
Insert the method's description here.
Returns:
BindingTable

isDebug

protected boolean isDebug()
Get the value of the propertity 'DEBUG_NavTaggerCancelout'.
Returns:
boolean True: With debug information. False: No debug information.
Since:
1.0

isGatherStatistics

protected boolean isGatherStatistics()
A flag to check whether to get the statistics from rewrite rules. Creation date: (9/16/2002 5:13:23 PM)
Returns:
boolean

isUsedAbove

protected boolean isUsedAbove(XATNode startingPoint,
                              java.lang.String columnToFind)
traverse up the tree, starting from the startingPoint parameter, checking if columnToFind is used in any entry point in a Navigate, parameter in a Select, or column in a Tagger. It will be failed if the variable is not used in the inner tree, but used in the outer tree. In that case, for the FOR node in the tree, the Sub tree's root Node should have a link to the FOR/GB Node. This bug should be fixed in ParserTraverse. This bug is identified as BUG 698225 on Source Forge.net. Creation date: (7/25/2002 12:50:10 AM)
Parameters:
column - java.lang.String

moveNode

protected void moveNode(XATNode parent,
                        XATNode child)
 MoveNode will alter the XATTree structue by moving the parent
 node directly under the child. The child's children will be altered to
 point to parent. This is primarily used to move a node under the correct Join / Union branch.

  Structure of tree 
 parent = x2, child = x4
   
   	old structure
   	x1 -> x2 -> x3 -> x4
   
   	new structure
   	x1 -> x3 ->	x2 -> x4
 
 Any other time you want to switch the positions of 2 nodes, swap(XATOperator, XATOperator) 
 should be used.
 
Parameters:
parent -  
child -  
See Also:
swap

moveNodeToRoot

protected void moveNodeToRoot(XATNode root,
                              XATNode nodeToMove)
 MoveNodeToRoot will alter the XATTree structue by moving the 
 node to the root.  This is to be used in conjunction with
 rename push down.  Renames will be put as the new root,
 then pushed down and each node it goes through will be
 changed.

  Structure of tree 
 root = x1, node = x4
   
   	old structure
   	x1 -> ... -> x3 -> x4 -> x5
   
   	new structure
   	x4 -> x1 -> ... x3 -> x5
 
 
Parameters:
root -  
nodeToMove -  
See Also:
rename

setDebug

public void setDebug(boolean newDebug)
Insert the method's description here. Creation date: (9/16/2002 5:13:23 PM)
Parameters:
newDebug - boolean

setVariableTable

public void setVariableTable(BindingTable newVariableTable)
Insert the method's description here.
Parameters:
newVariableTable - java.util.BindingTable

swap

protected void swap(XATOperator operator1,
                    XATOperator operator2)
Swaps the operators of 2 nodes. This is used when the appropriate equivalance rule determines that the 2 nodes can be swapped.
Parameters:
operator1 -  
operator2 -  

visit

public java.lang.Object visit(java.lang.Object object)
If there is an inheretance between the visited objects, it will only match the highest class.
Overrides:
visit in class InheritableVisitor
Tags copied from class: InheritableVisitor
Parameters:
object -  
Returns:
Object

visit

public java.lang.Object visit(java.lang.Object obj1,
                              java.lang.Object obj2)
We add funtionality to print out the rules used in this rewrite. If there is an inheretance between the visited objects, it will only match the highest class.
Overrides:
visit in class TwoParamVisitor
Tags copied from class: TwoParamVisitor
Parameters:
obj1 - The first object.
obj2 - The second object.
Returns:
Object