示例#1
0
 internal void InsertVertexNode(int index, DLinqQueryNode node)
 {
     if (index == -1)
     {
         this.m_vertexNodes.Add(node);
     }
     else
     {
         this.m_vertexNodes.Insert(index, node);
     }
 }
示例#2
0
        /// <summary>
        /// Helper for CodeShowVisit: do not revisit a node twice.
        /// </summary>
        /// <param name="plan">Return plan here.</param>
        /// <param name="n">Node to explain.</param>
        /// <param name="visited">Set of nodes already visited.</param>
        private void CodeShowVisit(StringBuilder plan, DLinqQueryNode n, HashSet <DLinqQueryNode> visited)
        {
            if (visited.Contains(n))
            {
                return;
            }
            visited.Add(n);

            foreach (DLinqQueryNode c in n.Children)
            {
                CodeShowVisit(plan, c, visited);
            }

            ExplainNode(plan, n);
        }
示例#3
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;
 }
示例#4
0
        internal override XmlElement CreateElem(XmlDocument queryDoc)
        {
            XmlElement managerElem = queryDoc.CreateElement("DynamicManager");
            XmlElement elem        = queryDoc.CreateElement("Type");

            elem.InnerText = Convert.ToString(this.ManagerType.ToString());
            managerElem.AppendChild(elem);

            elem           = queryDoc.CreateElement("SampleRate");
            elem.InnerText = Convert.ToString(this.m_sampleRate);
            managerElem.AppendChild(elem);

            elem = queryDoc.CreateElement("VertexId");
            DLinqQueryNode node = this.m_vertexNodes[0];

            if (node.SuperNode != null)
            {
                node = node.SuperNode;
            }
            elem.InnerText = Convert.ToString(node.m_uniqueId);
            managerElem.AppendChild(elem);

            return(managerElem);
        }
示例#5
0
        internal virtual string AddVertexCode(DLinqQueryNode node,
                                              CodeMemberMethod vertexMethod,
                                              string[] readerNames,
                                              string[] writerNames)
        {
            switch (node.NodeType)
            {
            case QueryNodeType.InputTable:
            {
                return(this.Visit((DLinqInputNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.OutputTable:
            {
                return(this.Visit((DLinqOutputNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Aggregate:
            {
                return(this.Visit((DLinqAggregateNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Select:
            case QueryNodeType.SelectMany:
            {
                return(this.Visit((DLinqSelectNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Where:
            {
                return(this.Visit((DLinqWhereNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Distinct:
            {
                return(this.Visit((DLinqDistinctNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.BasicAggregate:
            {
                return(this.Visit((DLinqBasicAggregateNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.GroupBy:
            {
                return(this.Visit((DLinqGroupByNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.OrderBy:
            {
                return(this.Visit((DLinqOrderByNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Skip:
            case QueryNodeType.SkipWhile:
            case QueryNodeType.Take:
            case QueryNodeType.TakeWhile:
            {
                return(this.Visit((DLinqPartitionOpNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Contains:
            {
                return(this.Visit((DLinqContainsNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Join:
            case QueryNodeType.GroupJoin:
            {
                return(this.Visit((DLinqJoinNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Union:
            case QueryNodeType.Intersect:
            case QueryNodeType.Except:
            {
                return(this.Visit((DLinqSetOperationNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Concat:
            {
                return(this.Visit((DLinqConcatNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Zip:
            {
                return(this.Visit((DLinqZipNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Super:
            {
                return(this.Visit((DLinqSuperNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.RangePartition:
            {
                return(this.Visit((DLinqRangePartitionNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.HashPartition:
            {
                return(this.Visit((DLinqHashPartitionNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Merge:
            {
                return(this.Visit((DLinqMergeNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Apply:
            {
                return(this.Visit((DLinqApplyNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Fork:
            {
                return(this.Visit((DLinqForkNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Tee:
            {
                return(this.Visit((DLinqTeeNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Dynamic:
            {
                return(this.Visit((DLinqDynamicNode)node, vertexMethod, readerNames, writerNames));
            }

            case QueryNodeType.Dummy:
            {
                return(this.Visit((DLinqDummyNode)node, vertexMethod, readerNames, writerNames));
            }

            default:
            {
                throw new DryadLinqException("Internal error: unhandled node type " + node.NodeType);
            }
            }
        }
示例#6
0
        /// <summary>
        /// Explain one query node.
        /// </summary>
        /// <param name="plan">Return plan here.</param>
        /// <param name="n">Node to explain.</param>
        internal static void ExplainNode(StringBuilder plan, DLinqQueryNode n)
        {
            if (n is DLinqTeeNode || n is DLinqOutputNode ||
                n is DLinqDoWhileNode || n is DLinqDummyNode)
            {
                return;
            }
            else if (n is DLinqInputNode)
            {
                plan.AppendLine("Input:");
                plan.Append("\t");
                n.BuildString(plan);
                plan.AppendLine();
                return;
            }

            plan.Append(n.m_vertexEntryMethod);
            plan.AppendLine(":");

            HashSet <DLinqQueryNode> allchildren = new HashSet <DLinqQueryNode>();

            if (n is DLinqSuperNode)
            {
                DLinqSuperNode        sn      = n as DLinqSuperNode;
                List <DLinqQueryNode> tovisit = new List <DLinqQueryNode>();

                tovisit.Add(sn.RootNode);

                while (tovisit.Count > 0)
                {
                    DLinqQueryNode t = tovisit[0];
                    tovisit.RemoveAt(0);
                    if (!(t is DLinqSuperNode))
                    {
                        allchildren.Add(t);
                    }
                    foreach (DLinqQueryNode tc in t.Children)
                    {
                        if (!allchildren.Contains(tc) && sn.Contains(tc))
                        {
                            tovisit.Add(tc);
                        }
                    }
                }
            }
            else
            {
                allchildren.Add(n);
            }

            foreach (DLinqQueryNode nc in allchildren.Reverse())
            {
                Expression    expression = null;                // expression to print
                List <string> additional = new List <string>(); // additional arguments to print
                int           argsToSkip = 0;
                string        methodname = nc.OpName;

                plan.Append("\t");

                if (nc is DLinqMergeNode)
                {
                    expression = ((DLinqMergeNode)nc).ComparerExpression;
                }
                else if (nc is DLinqHashPartitionNode)
                {
                    DLinqHashPartitionNode hp = (DLinqHashPartitionNode)nc;
                    expression = hp.KeySelectExpression;
                    additional.Add(hp.NumberOfPartitions.ToString());
                }
                else if (nc is DLinqGroupByNode)
                {
                    DLinqGroupByNode gb = (DLinqGroupByNode)nc;
                    expression = gb.KeySelectExpression;
                    if (gb.ElemSelectExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(gb.ElemSelectExpression));
                    }
                    if (gb.ResSelectExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(gb.ResSelectExpression));
                    }
                    if (gb.ComparerExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(gb.ComparerExpression));
                    }
                    if (gb.SeedExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(gb.SeedExpression));
                    }
                    if (gb.AccumulatorExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(gb.AccumulatorExpression));
                    }
                }
                else if (nc is DLinqOrderByNode)
                {
                    DLinqOrderByNode ob = (DLinqOrderByNode)nc;
                    expression = ob.KeySelectExpression;
                    if (ob.ComparerExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(ob.ComparerExpression));
                    }
                }
                else if (nc is DLinqWhereNode)
                {
                    expression = ((DLinqWhereNode)nc).WhereExpression;
                }
                else if (nc is DLinqSelectNode)
                {
                    DLinqSelectNode s = (DLinqSelectNode)nc;
                    expression = s.SelectExpression;
                    if (s.ResultSelectExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(s.ResultSelectExpression));
                    }
                }
                else if (nc is DLinqAggregateNode)
                {
                    DLinqAggregateNode a = (DLinqAggregateNode)nc;
                    expression = a.FuncLambda;
                    if (a.SeedExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(a.SeedExpression));
                    }
                    if (a.ResultLambda != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(a.ResultLambda));
                    }
                }
                else if (nc is DLinqPartitionOpNode)
                {
                    expression = ((DLinqPartitionOpNode)nc).ControlExpression;
                }
                else if (nc is DLinqJoinNode)
                {
                    DLinqJoinNode j = (DLinqJoinNode)nc;
                    expression = j.OuterKeySelectorExpression;
                    additional.Add(DryadLinqExpression.Summarize(j.InnerKeySelectorExpression));
                    additional.Add(DryadLinqExpression.Summarize(j.ResultSelectorExpression));
                    if (j.ComparerExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(j.ComparerExpression));
                    }
                }
                else if (nc is DLinqDistinctNode)
                {
                    expression = ((DLinqDistinctNode)nc).ComparerExpression;
                }
                else if (nc is DLinqContainsNode)
                {
                    DLinqContainsNode c = (DLinqContainsNode)nc;
                    expression = c.ValueExpression;
                    if (c.ComparerExpression != null)
                    {
                        additional.Add(DryadLinqExpression.Summarize(c.ComparerExpression));
                    }
                }
                else if (nc is DLinqBasicAggregateNode)
                {
                    expression = ((DLinqBasicAggregateNode)nc).SelectExpression;
                }
                else if (nc is DLinqConcatNode)
                // nothing to do
                {
                }
                else if (nc is DLinqSetOperationNode)
                {
                    expression = ((DLinqSetOperationNode)nc).ComparerExpression;
                }
                else if (nc is DLinqRangePartitionNode)
                {
                    DLinqRangePartitionNode r = (DLinqRangePartitionNode)nc;
                    expression = r.CountExpression;
                    // TODO: there's some other possible interesting info
                }
                else if (nc is DLinqApplyNode)
                {
                    expression = ((DLinqApplyNode)nc).LambdaExpression;
                }

                else if (nc is DLinqForkNode)
                {
                    expression = ((DLinqForkNode)nc).ForkLambda;
                }
                else if (nc is DLinqTeeNode)
                {
                    // nothing
                }
                else if (nc is DLinqDynamicNode)
                {
                    // nothing
                }
                else
                {
                    expression = nc.QueryExpression;
                }

                if (expression is MethodCallExpression)
                {
                    MethodCallExpression mc = (MethodCallExpression)expression;
                    methodname = mc.Method.Name;  // overwrite methodname

                    // determine which arguments to skip
                    #region LINQMETHODS
                    switch (mc.Method.Name)
                    {
                    case "Aggregate":
                    case "AggregateAsQuery":
                    case "Select":
                    case "LongSelect":
                    case "SelectMany":
                    case "LongSelectMany":
                    case "OfType":
                    case "Where":
                    case "LongWhere":
                    case "First":
                    case "FirstOrDefault":
                    case "FirstAsQuery":
                    case "Single":
                    case "SingleOrDefault":
                    case "SingleAsQuery":
                    case "Last":
                    case "LastOrDefault":
                    case "LastAsQuery":
                    case "Distinct":
                    case "Any":
                    case "AnyAsQuery":
                    case "All":
                    case "AllAsQuery":
                    case "Count":
                    case "CountAsQuery":
                    case "LongCount":
                    case "LongCountAsQuery":
                    case "Sum":
                    case "SumAsQuery":
                    case "Min":
                    case "MinAsQuery":
                    case "Max":
                    case "MaxAsQuery":
                    case "Average":
                    case "AverageAsQuery":
                    case "GroupBy":
                    case "OrderBy":
                    case "OrderByDescending":
                    case "ThenBy":
                    case "ThenByDescending":
                    case "Take":
                    case "TakeWhile":
                    case "LongTakeWhile":
                    case "Skip":
                    case "SkipWhile":
                    case "LongSkipWhile":
                    case "Contains":
                    case "ContainsAsQuery":
                    case "Reverse":
                    case "Merge":
                    case "HashPartition":
                    case "RangePartition":
                    case "Fork":
                    case "ForkChoose":
                    case "AssumeHashPartition":
                    case "AssumeRangePartition":
                    case "AssumeOrderBy":
                    case "ToPartitionedTableLazy":
                    case "AddCacheEntry":
                    case "SlidingWindow":
                    case "ApplyWithPartitionIndex":
                    case "DoWhile":
                        argsToSkip = 1;
                        break;

                    case "Join":
                    case "GroupJoin":
                    case "Concat":
                    case "MultiConcat":
                    case "Union":
                    case "Intersect":
                    case "Except":
                    case "SequenceEqual":
                    case "SequenceEqualAsQuery":
                    case "Zip":
                        argsToSkip = 2;
                        break;

                    case "Apply":
                    case "ApplyPerPartition":
                        if (mc.Arguments.Count < 3)
                        {
                            argsToSkip = 1;
                        }
                        else
                        {
                            argsToSkip = 2;
                        }
                        break;

                    default:
                        throw DryadLinqException.Create(DryadLinqErrorCode.OperatorNotSupported,
                                                        String.Format(SR.OperatorNotSupported, mc.Method.Name),
                                                        expression);
                    }
                    #endregion

                    plan.Append(methodname);
                    plan.Append("(");

                    int argno = 0;
                    foreach (var arg in mc.Arguments)
                    {
                        argno++;
                        if (argno <= argsToSkip)
                        {
                            continue;
                        }
                        if (argno > argsToSkip + 1)
                        {
                            plan.Append(",");
                        }
                        plan.Append(DryadLinqExpression.Summarize(arg));
                    }
                    plan.AppendLine(")");
                }
                else
                {
                    // expression is not methodcall
                    plan.Append(methodname);
                    plan.Append("(");
                    if (expression != null)
                    {
                        plan.Append(DryadLinqExpression.Summarize(expression));
                    }
                    foreach (string e in additional)
                    {
                        plan.Append(",");
                        plan.Append(e);
                    }
                    plan.AppendLine(")");
                }
            }
        }
示例#7
0
 /// <summary>
 /// Create a dynamic manager with a single parameter node.
 /// </summary>
 /// <param name="type">Type of manager to create.</param>
 /// <param name="node">Node that the manager depends on.</param>
 internal DynamicManager(DynamicManagerType type, DLinqQueryNode node)
     : this(type)
 {
     this.m_vertexNodes.Add(node);
 }
示例#8
0
 internal DynamicRangeDistributor(DLinqQueryNode node)
     : base(DynamicManagerType.RangeDistributor, node)
 {
     //@@TODO[P2]: This sample rate used here should really be its own constant.
     this.m_sampleRate = DryadLinqSampler.SAMPLE_RATE;
 }
示例#9
0
        internal override DLinqQueryNode CreatePartitionNode(LambdaExpression keySel, DLinqQueryNode child)
        {
            Expression comparerExpr = Expression.Constant(this.m_comparer, typeof(IEqualityComparer <TKey>));

            return(new DLinqHashPartitionNode(keySel, comparerExpr, this.Count, child.QueryExpression, child));
        }
示例#10
0
        internal override DLinqQueryNode CreatePartitionNode(LambdaExpression keySel, DLinqQueryNode child)
        {
            Expression keysExpr         = Expression.Constant(this.m_partitionKeys);
            Expression comparerExpr     = Expression.Constant(this.m_comparer, typeof(IComparer <TKey>));
            Expression isDescendingExpr = Expression.Constant(this.m_isDescending);

            return(new DLinqRangePartitionNode(keySel, null, keysExpr, comparerExpr, isDescendingExpr, null, child.QueryExpression, child));
        }
示例#11
0
 internal override DLinqQueryNode CreatePartitionNode(LambdaExpression keySel, DLinqQueryNode child)
 {
     throw new DryadLinqException(DryadLinqErrorCode.CannotCreatePartitionNodeRandom,
                                  SR.CannotCreatePartitionNodeRandom);
 }
示例#12
0
 internal abstract DLinqQueryNode CreatePartitionNode(LambdaExpression keySelector, DLinqQueryNode child);