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

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
                    |
                    +--edu.wpi.cs.dsrg.xmldb.xat.component.xatrewrite.ComputationPushdownRules

public class ComputationPushdownRules
extends ReWriteRules

This Class is used to push down operators by traversing the XAT.

Since:
1.0

Fields inherited from class edu.wpi.cs.dsrg.xmldb.xat.component.xatrewrite.ReWriteRules
classVector, result, statis, variableTable
 
Constructor Summary
ComputationPushdownRules()
          Default ComputationPushdownRules constructor.
 
Method Summary
protected  void cleanSchema(XATNode root)
          Clean all the schema of XAT with a given root.
protected  boolean deleteRedundantRename(NameColumn ncOp)
          Delete redundent Rename operator This method compares the old column name and new column, if they are equal or both of them are null, then return true, else return false.
protected  void findMatchingPatternNode(DOMPatternNode root, NavigationStep[] toMatch, java.util.Vector toFill)
          Find the nodes matching the give NavigationSteps.
protected  void nameColumnSubTree(XATOperator child, java.lang.String oldColumn, java.lang.String newColumn)
          Change all attached sub tree output column names.
protected  void renameExpression(BinExpression exp, java.lang.String newName, java.lang.String toMatch)
          The Method recursively looks at the left and right sides of an Expression.
protected  void renameTagger(DOMPatternNode root, java.lang.String toMatch, java.lang.String newName)
          This method recursively look at the DOM Tree, traverses through the DOMPattern tree, which has a DOMPatternNoe as root, until it finds all TagNode and ColumnNameNode.
 java.lang.Object visit(Aggregate parent, XATOperator child)
          Rules for removing a useless Aggregation operator.
 java.lang.Object visit(NameColumn parent, Aggregate child)
          Rules for pushing a NameColumn operator through an Aggregate operator.
 java.lang.Object visit(NameColumn parent, CartesianProduct child)
          Rules for pushing a NameColumn node through a generic XATOperator
 java.lang.Object visit(NameColumn parent, Function child)
          Rules for pushing a NameColumn operator through a Function operator.
 java.lang.Object visit(NameColumn parent, GroupBy child)
          Rules for pushing a NameColumn node through a GroupBy
 java.lang.Object visit(NameColumn parent, Navigate child)
          Rules for pushing a NameColumn node through a Navigate Node.
 java.lang.Object visit(NameColumn parent, Select child)
          Rules for pushing a NameColumn operator through a Select operator.
 java.lang.Object visit(NameColumn parent, Source child)
          Rules for pushing a NameColumn node through a Source Node.
 java.lang.Object visit(NameColumn parent, Tagger child)
          Rules for pushing a NameColumn operator through a Tagger operator.
 java.lang.Object visit(NameColumn parent, XATMultiSourceOperator child)
          Rules for pushing a NameColumn node through a generic XATOperator.
 java.lang.Object visit(Navigate parent, CartesianProduct child)
           Rules for pushing a Navigate node through a XATMultiSourceOperator .
 java.lang.Object visit(Navigate parent, GroupBy child)
          Rules for pushing a Navigate operator through a Groupby operator A Navigate can, but for the sake of order sensitive rewrite, is never pushed through a groupby (due to the way the tree is generated, this would normally only allow a navunnest of a text() to be pushed anyway).
 java.lang.Object visit(Navigate parent, NameColumn child)
          Rules for pushing a Navigate operator through a NameColumn operator A Navigate node can always be pushed through a NameColumn operartor This rule is the same as NameColumn / Navigate
 java.lang.Object visit(Navigate parent, Navigate child)
          Rules for pushing a Navigate operator through a Navigate operator.
 java.lang.Object visit(Navigate parent, Project child)
          Rules for pushing a Navigate operator through a Project operator A Navigate can always move through a Project, but the destination of the Navigate node must be added to columns that are Projected
 java.lang.Object visit(Navigate parent, Select child)
          Rules for pushing a Navigate operator through a Select operator A Navigate can always move through a Select
 java.lang.Object visit(Navigate parent, Source child)
          Rules for pushing a Navigate operator through a Source operator A Navigate can never go through a Source operator.
 java.lang.Object visit(Navigate parent, XATMultiSourceOperator child)
           Rules for pushing a Navigate node through a XATMultiSourceOperator .
 java.lang.Object visit(Navigate parent, XATOperator child)
          Rules for pushing a Navigate operator through a generic XATOperator operator A Navigate can always be pushed through a Distinct
 java.lang.Object visit(Select parent, CartesianProduct child)
           Select MultipleSource Operator Product Rule.
 java.lang.Object visit(Select parent, GroupBy child)
          Select GroupBy Rule.
 java.lang.Object visit(Select parent, Navigate child)
          Select Navigate Rule.
 java.lang.Object visit(Select parent, XATMultiSourceOperator child)
           Select MultipleSource Operator Product Rule.
 java.lang.Object visit(Select parent, XATOperator child)
          Select XATOperator Rule.
 java.lang.Object visit(Tagger parent, XATOperator child)
          Rules for removing a useless Tagger operator
 
Methods inherited from class edu.wpi.cs.dsrg.xmldb.xat.component.xatrewrite.ReWriteRules
combineSteps, copyNode, createString, deleteAggregate, deletePartialTagger, deleteWholeTagger, dispatch, dispatch, dispatch, evaluateRules, evaluateRules, findMatchingNavigationNode, findMatchingNavigationNode, getChildren, getColumnNames, getStatis, getVariableTable, isDebug, isGatherStatistics, isUsedAbove, moveNode, moveNodeToRoot, setDebug, setVariableTable, swap, visit, visit
 
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
 

Constructor Detail

ComputationPushdownRules

public ComputationPushdownRules()
Default ComputationPushdownRules constructor. Constructs a ComputationPushdownRules object.
Since:
1.0
Method Detail

cleanSchema

protected void cleanSchema(XATNode root)
Clean all the schema of XAT with a given root. This method recursively clean the schema of XAT node. Set the schema of each node as null.
Parameters:
root - edu.wpi.cs.dsrg.xmldb.xat.common.xatnode.XATNode
Returns:
void
Since:
1.0
See Also:
XATTree, XATNode

deleteRedundantRename

protected boolean deleteRedundantRename(NameColumn ncOp)
Delete redundent Rename operator This method compares the old column name and new column, if they are equal or both of them are null, then return true, else return false.
Parameters:
ncOp - edu.wpi.cs.dsrg.xmldb.xat.common.operator.specialoperator.NameColumn
Returns:
boolean true: means can be deleted, because the new = old, otherwise, cannot be deleted.
Since:
1.0
See Also:
NameColumn

findMatchingPatternNode

protected void findMatchingPatternNode(DOMPatternNode root,
                                       NavigationStep[] toMatch,
                                       java.util.Vector toFill)
Find the nodes matching the give NavigationSteps. This method traverse a DOMPattern starting from the root and returns all nodes that match the NavigationSteps. The Vector toFill contains all of the matches found. This is used to aid in Navigate / Tagger cancelout by finding all DOMPatternNodes that match the Navigate node. Logic for determining a match
  • A ColumnNameNode will be a match if the tagValue if the last Step is toMatch and the ColumnNameNode's parent's tagName corresponds to 2nd to last toMatch step toMatch array
  • An AttributeNode will be a match if the last toMatch step begins with "@" and the text after that corresponds to the tagName of the node
  • A TagNode will be a match if the tagName corresponds to any value in the toMatch array
  • A TextNode could not be canceled out
  • Parameters:
    root - The root of the DOMPatternNode.
    toMatch - The NavigationStep used as match pattern.
    toFill - All the matches found.
    Returns:
    void
    Since:
    1.0
    See Also:
    DOMPattern, DOMPatternNode, ColumnNameNodeImp, AttributeNodeImp, TagNodeImp, TextNodeImp

    nameColumnSubTree

    protected void nameColumnSubTree(XATOperator child,
                                     java.lang.String oldColumn,
                                     java.lang.String newColumn)
    Change all attached sub tree output column names. This method change all the oldColumn name as newColumn name. Call recursively if the child node is of type GroupBy.
    Parameters:
    The - XATTree attached to a GroupBy node (GroupBy, Function, Aggregate).
    oldColumn - The name of old column.
    newColumn - The name of new column.
    Returns:
    void
    Since:
    1.0
    See Also:
    GroupBy, XATOperator, XATTree.

    renameExpression

    protected void renameExpression(BinExpression exp,
                                    java.lang.String newName,
                                    java.lang.String toMatch)
    The Method recursively looks at the left and right sides of an Expression. Traverses through the Expression tree until it finds all Terminal Expressions. It then checks for if the TE's column equals the column to rename. If so, replace all the old column name as new column name.
    Parameters:
    exp - The expression going to be searched.
    toMatch - The name of the column being searched.
    newName - The new column name.
    Returns:
    void
    Since:
    1.0
    See Also:
    BinExpression, TerminalExpression, ColumnNameNodeImp

    renameTagger

    protected void renameTagger(DOMPatternNode root,
                                java.lang.String toMatch,
                                java.lang.String newName)
    This method recursively look at the DOM Tree, traverses through the DOMPattern tree, which has a DOMPatternNoe as root, until it finds all TagNode and ColumnNameNode. It then checks for if the node's column equals the column to rename. If so, for tag node, replace the old tag name as new tag name, for ColumnNameNode, then replace the ole TagValue as newName.
    Parameters:
    root - The root node of DOM pattern tree.
    newName - The new column name.
    toMatch - The name of the column being searhed.
    Returns:
    void
    Since:
    1.0
    See Also:
    DOMPattern, DOMPatternNode, ColumnNameNodeImp, TagNodeImp

    visit

    public java.lang.Object visit(NameColumn parent,
                                  Function child)
    Rules for pushing a NameColumn operator through a Function operator.
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (Function).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, Function, ReWriteResult

    visit

    public java.lang.Object visit(NameColumn parent,
                                  Source child)
    Rules for pushing a NameColumn node through a Source Node.
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (Source).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, Source, ReWriteResult

    visit

    public java.lang.Object visit(NameColumn parent,
                                  CartesianProduct child)
    Rules for pushing a NameColumn node through a generic XATOperator
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (CartesianProduct).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, CartesianProduct, ReWriteResult, renameExpression, deleteRedundantRename

    visit

    public java.lang.Object visit(NameColumn parent,
                                  GroupBy child)
    Rules for pushing a NameColumn node through a GroupBy
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (XATOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, Function, ReWriteResult, nameColumnSubTree

    visit

    public java.lang.Object visit(NameColumn parent,
                                  Select child)
    Rules for pushing a NameColumn operator through a Select operator.
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (Select).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, Select, ReWriteResult, renameExpression

    visit

    public java.lang.Object visit(NameColumn parent,
                                  XATMultiSourceOperator child)
    Rules for pushing a NameColumn node through a generic XATOperator. MultipleSource are operators exclude CartesianProduct family operators. For example: Merge, Set operator, IF_THEN_ELSE operator, "Or" operator. In this case, for the semantic will be changed, no push down will be applied.
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (XATMultiSourceOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    NameColumn, XATMultiSourceOperator, ReWriteResult, deleteRedundantRename

    visit

    public java.lang.Object visit(NameColumn parent,
                                  Aggregate child)
    Rules for pushing a NameColumn operator through an Aggregate operator.
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (Aggregate).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, Aggregate, ReWriteResult

    visit

    public java.lang.Object visit(NameColumn parent,
                                  Navigate child)
    Rules for pushing a NameColumn node through a Navigate Node. If the Navigate's binding, entryPoint or destination matches the oldColumnName from the NameColumn, then change it to the newColumnName.
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (Navigate).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, Function, ReWriteResult, deleteRedundantRename

    visit

    public java.lang.Object visit(NameColumn parent,
                                  Tagger child)
    Rules for pushing a NameColumn operator through a Tagger operator.
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (Tagger).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    NameColumn, Tagger, ReWriteResult

    visit

    public java.lang.Object visit(Select parent,
                                  CartesianProduct child)
     Select MultipleSource Operator Product Rule.
     we want to determine what to do with the Select,  there are 4 possiblities.
     1) The Select should move to the left branch
     2) The Select should move to the right branch
     3) The Select should be merged with the Cartesian to form an OuterJoin
     4) The Select should stay on top of the Cartesian
     to determine which case we have, we will try to findMatchingNavigateNode on both the
     left and right branches of the Cartesian with both the left and right column names of the select
     to accomplish this, we will use a state machine
     two booleans, left and right are set to true.  if any column name does not go to that side,
     then the boolean is set to false
     after all column names have been checked against all branches, we can determine which of the 4
     actions to take
     1) true / false
     2) false / true
     3) true / true
     4) false / false
     
    Parameters:
    parent - parent XAT operator (Select).
    child - child XAT Operator (CartesianProduct).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Select, CartesianProduct, ReWriteResult, findMatchingNavigationNode, moveNode

    visit

    public java.lang.Object visit(Select parent,
                                  GroupBy child)
    Select GroupBy Rule. Select cannot be pushed past the Groupby
    Parameters:
    parent - parent XAT operator (Select).
    child - child XAT Operator (GroupBy).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Select, GroupBy, ReWriteResult

    visit

    public java.lang.Object visit(Select parent,
                                  XATMultiSourceOperator child)
     Select MultipleSource Operator Product Rule.
     MultipleSource are operators exclude CartesianProduct family operators.
     For example: Merge, Set operator, IF_THEN_ELSE operator, "Or" operator.
    
     In this case, no push down will be applied. For the semantic will be changed.
     
    Parameters:
    parent - parent XAT operator (Select).
    child - child XAT Operator (XATMultiSourceOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Select, XATMultiSourceOperator, ReWriteResult

    visit

    public java.lang.Object visit(Select parent,
                                  XATOperator child)
    Select XATOperator Rule. Select can always be swapped with any XATOperator that doesnt have its own rule.
    Parameters:
    parent - parent XAT operator (Select).
    child - child XAT Operator (XATOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Select, XATOperator, ReWriteResult

    visit

    public java.lang.Object visit(Select parent,
                                  Navigate child)
    Select Navigate Rule. Select can swap with a Navigate if the bindings dont match
    Parameters:
    parent - parent XAT operator (Select).
    child - child XAT Operator (Navigate).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Select, Navigate, ReWriteResult

    visit

    public java.lang.Object visit(Aggregate parent,
                                  XATOperator child)
    Rules for removing a useless Aggregation operator.
    Parameters:
    parent - parent XAT operator (Aggregate).
    child - child XAT Operator.
    Returns:
    ReWriteResult. The swap flag in ReWriteResult true if the nodes were swapped, false otherwise.
    Since:
    1.0
    See Also:
    XATOperator, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  NameColumn child)
    Rules for pushing a Navigate operator through a NameColumn operator A Navigate node can always be pushed through a NameColumn operartor This rule is the same as NameColumn / Navigate
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (NameColumn).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, GroupBy, ReWriteResult, deleteRedundantRename

    visit

    public java.lang.Object visit(Navigate parent,
                                  Source child)
    Rules for pushing a Navigate operator through a Source operator A Navigate can never go through a Source operator. The Source operators are on the very bottom of trees and swapping the 2 would cause errors
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (Source).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, Source, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  CartesianProduct child)
     Rules for pushing a Navigate node through a XATMultiSourceOperator .
     This is also the same rule for Navigate
     The XATMultiSourceOperator node will have n branches, the Navigate node must be moved to
     the branch that contains a Navigate node whose destination equals parent.entryPoint
    
     findMatchingNavigationNode is used to determine which branch to move to
    
     This rules apply to cartesian product operators.
     
    Parameters:
    parent - parent XAT operator (NameColumn).
    child - child XAT Operator (XATMultiSourceOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, XATMultiSourceOperator, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  GroupBy child)
    Rules for pushing a Navigate operator through a Groupby operator A Navigate can, but for the sake of order sensitive rewrite, is never pushed through a groupby (due to the way the tree is generated, this would normally only allow a navunnest of a text() to be pushed anyway).
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (GroupBy).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, GroupBy, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  Project child)
    Rules for pushing a Navigate operator through a Project operator A Navigate can always move through a Project, but the destination of the Navigate node must be added to columns that are Projected
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (Project).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, Project, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  Select child)
    Rules for pushing a Navigate operator through a Select operator A Navigate can always move through a Select
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (Select).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, Select, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  XATMultiSourceOperator child)
     Rules for pushing a Navigate node through a XATMultiSourceOperator .
     MultipleSource are operators exclude CartesianProduct family operators.
     For example: Merge, Set operator, IF_THEN_ELSE operator, "Or" operator.
    
     In this case, no push down will be applied. For the semantic will be changed.
     
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (XATMultiSourceOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, XATMultiSourceOperator, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  XATOperator child)
    Rules for pushing a Navigate operator through a generic XATOperator operator A Navigate can always be pushed through a Distinct
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (XATOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, XATOperator, ReWriteResult

    visit

    public java.lang.Object visit(Navigate parent,
                                  Navigate child)
    Rules for pushing a Navigate operator through a Navigate operator. If the entry point for the parent is the same as the complete path for the child, the nodes cannot be swapped and the parent is pushedDown. Otherwise, the swap is legal.
    Parameters:
    parent - parent XAT operator (Navigate).
    child - child XAT Operator (Navigate).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Navigate, Navigate, ReWriteResult

    visit

    public java.lang.Object visit(Tagger parent,
                                  XATOperator child)
    Rules for removing a useless Tagger operator
    Parameters:
    parent - parent XAT operator (Tagger).
    child - child XAT Operator (XATOperator).
    Returns:
    ReWriteResult. The swap flag in ReWriteResult false.
    Since:
    1.0
    See Also:
    Tagger, XATOperator, ReWriteResult