Beispiel #1
0
 // Delete this NodeInfo.
 // Precondition: this.children.Count < 2
 public void Delete()
 {
     Debug.Assert(this.Children.Count < 2);
     if (this.Children.Count == 0)
     {
         foreach (NodeInfoEdge edge in this.Parents)
         {
             edge.Parent.Children.Remove(edge);
         }
     }
     else
     {
         QueryNodeInfo child = this.Children[0].Child;
         child.Parents.Remove(this.Children[0]);
         foreach (NodeInfoEdge edge in this.Parents)
         {
             NodeInfoEdge newEdge = new NodeInfoEdge(edge.Parent, child);
             NodeInfoEdge.UpdateEdge(edge.Parent.Children, edge, newEdge);
             child.Parents.Add(newEdge);
         }
     }
     
     this.Parents.Clear();
     this.Children.Clear();
 }
Beispiel #2
0
 // Insert a node info on this edge.
 public void Insert(QueryNodeInfo nextInfo)
 {
     Debug.Assert(nextInfo.children.Count == 0 && nextInfo.parents.Count == 0);
     NodeInfoEdge edge1 = new NodeInfoEdge(this.parent, nextInfo);
     NodeInfoEdge edge2 = new NodeInfoEdge(nextInfo, this.child);
     UpdateEdge(this.parent.children, this, edge1);
     nextInfo.parents.Add(edge1);
     UpdateEdge(this.child.parents, this, edge2);
     nextInfo.children.Add(edge2);
 }
Beispiel #3
0
 // Insert a node info on this edge.
 public void Insert(QueryNodeInfo nextInfo)
 {
     Debug.Assert(nextInfo.Children.Count == 0 && nextInfo.Parents.Count == 0);
     NodeInfoEdge edge1 = new NodeInfoEdge(this.Parent, nextInfo);
     NodeInfoEdge edge2 = new NodeInfoEdge(nextInfo, this.Child);
     UpdateEdge(this.Parent.Children, this, edge1);
     nextInfo.Parents.Add(edge1);
     UpdateEdge(this.Child.Parents, this, edge2);
     nextInfo.Children.Add(edge2);
 }
Beispiel #4
0
 // Replace all occurences of oldEdge in edges by newEdge.
 public static bool UpdateEdge(List<NodeInfoEdge> edges, NodeInfoEdge oldEdge, NodeInfoEdge newEdge)
 {
     for (int i = 0; i < edges.Count; i++)
     {
         if (Object.ReferenceEquals(oldEdge, edges[i]))
         {
             edges[i] = newEdge;
             return true;
         }
     }
     return false;
 }
Beispiel #5
0
 // Replace all occurences of oldEdge in edges by newEdge.
 public static bool UpdateEdge(List<NodeInfoEdge> edges, NodeInfoEdge oldEdge, NodeInfoEdge newEdge)
 {
     for (int i = 0; i < edges.Count; i++)
     {
         if (Object.ReferenceEquals(oldEdge, edges[i]))
         {
             edges[i] = newEdge;
             return true;
         }
     }
     return false;
 }
Beispiel #6
0
 public QueryNodeInfo(Expression queryExpression,
                      bool isQueryOperator,
                      params QueryNodeInfo[] children)
 {
     this.QueryExpression = queryExpression;
     this.IsQueryOperator = isQueryOperator;
     this.Children = new List<NodeInfoEdge>(children.Length);
     foreach (QueryNodeInfo childInfo in children)
     {
         NodeInfoEdge edge = new NodeInfoEdge(this, childInfo);
         this.Children.Add(edge);
         childInfo.Parents.Add(edge);
     }
     this.Parents = new List<NodeInfoEdge>();
     this.QueryNode = null;
 }
Beispiel #7
0
        // Delete this NodeInfo.
        // Precondition: this.children.Count < 2
        public void Delete()
        {
            Debug.Assert(this.children.Count < 2);
            if (this.children.Count == 0)
            {
                foreach (NodeInfoEdge edge in this.parents)
                {
                    edge.parent.children.Remove(edge);
                }
            }
            else
            {
                QueryNodeInfo child = this.children[0].child;
                child.parents.Remove(this.children[0]);
                foreach (NodeInfoEdge edge in this.parents)
                {
                    NodeInfoEdge newEdge = new NodeInfoEdge(edge.parent, child);
                    NodeInfoEdge.UpdateEdge(edge.parent.children, edge, newEdge);
                    child.parents.Add(newEdge);
                }
            }

            this.parents.Clear();
            this.children.Clear();
        }
Beispiel #8
0
 public QueryNodeInfo(Expression queryExpression,
                      bool isQueryOperator,
                      params QueryNodeInfo[] children)
 {
     this.queryExpression = queryExpression;
     this.isQueryOperator = isQueryOperator;
     this.children = new List<NodeInfoEdge>(children.Length);
     foreach (QueryNodeInfo childInfo in children)
     {
         NodeInfoEdge edge = new NodeInfoEdge(this, childInfo);
         this.children.Add(edge);
         childInfo.parents.Add(edge);
     }
     this.parents = new List<NodeInfoEdge>();
     this.queryNode = null;
 }
Beispiel #9
0
 // Return true iff EPG is modified by this method.
 public bool RewriteOne(int idx)
 {
     QueryNodeInfo curNode = this.m_nodeInfos[idx];
     if (curNode.OperatorName == "Where" && !curNode.Children[0].Child.IsForked)
     {
         LambdaExpression lambda = DryadLinqExpression.GetLambda(((MethodCallExpression)curNode.QueryExpression).Arguments[1]);
         if (lambda.Type.GetGenericArguments().Length == 2)
         {
             QueryNodeInfo child = curNode.Children[0].Child;
             string[] names = new string[] { "OrderBy", "Distinct", "RangePartition", "HashPartition" };
             if (names.Contains(child.OperatorName))
             {
                 curNode.Swap(child);
                 return true;
             }
             if (child.OperatorName == "Concat")
             {
                 curNode.Delete();
                 for (int i = 0; i < child.Children.Count; i++)
                 {
                     NodeInfoEdge edge = child.Children[i];
                     QueryNodeInfo node = curNode.Clone();
                     this.m_nodeInfos.Add(node);
                     edge.Insert(node);
                 }
                 return true;
             }
         }
     }
     else if ((curNode.OperatorName == "Select" || curNode.OperatorName == "SelectMany") &&
              !curNode.Children[0].Child.IsForked)
     {
         LambdaExpression lambda = DryadLinqExpression.GetLambda(((MethodCallExpression)curNode.QueryExpression).Arguments[1]);
         if (lambda.Type.GetGenericArguments().Length == 2)
         {
             QueryNodeInfo child = curNode.Children[0].Child;
             if (child.OperatorName == "Concat")
             {
                 curNode.Delete();
                 for (int i = 0; i < child.Children.Count; i++)
                 {
                     NodeInfoEdge edge = child.Children[i];
                     QueryNodeInfo node = curNode.Clone();
                     this.m_nodeInfos.Add(node);
                     edge.Insert(node);
                 }
                 return true;
             }
         }
     }
     else if (curNode.OperatorName == "Take" && !curNode.Children[0].Child.IsForked)
     {
         QueryNodeInfo child = curNode.Children[0].Child;
         if (child.OperatorName == "Select")
         {
             QueryNodeInfo cchild = child.Children[0].Child;
             if (cchild.OperatorName != "GroupBy")
             {
                 curNode.Swap(child);
                 return true;
             }
         }
     }
     else if ((curNode.OperatorName == "Contains" ||
               curNode.OperatorName == "ContainsAsQuery" ||
               curNode.OperatorName == "All" ||
               curNode.OperatorName == "AllAsQuery" ||
               curNode.OperatorName == "Any" ||
               curNode.OperatorName == "AnyAsQuery") &&
              !curNode.Children[0].Child.IsForked)
     {
         QueryNodeInfo child = curNode.Children[0].Child;
         string[] names = new string[] { "OrderBy", "Distinct", "RangePartition", "HashPartition" };
         if (names.Contains(child.OperatorName))
         {
             child.Delete();
             return true;
         }
     }
     return false;
 }