internal string AddVertexCode(CodeMemberMethod vertexMethod, Pipeline pipeline) { if (pipeline.Length == 0) { //@@TODO: this should not be reachable. could change to Assert/InvalidOpEx throw new DryadLinqException(DryadLinqErrorCode.Internal, SR.CannotBeEmpty); } DLinqQueryNode firstNode = pipeline[0]; if (firstNode.CanAttachPipeline) { firstNode.AttachedPipeline = pipeline; return this.m_vertexCodeGen.AddVertexCode( firstNode, vertexMethod, pipeline.ReaderNames, pipeline.WriterNames); } int startIndex = 0; string applySource = pipeline.ReaderNames[0]; if (!firstNode.IsHomomorphic) { applySource = this.m_vertexCodeGen.AddVertexCode( firstNode, vertexMethod, pipeline.ReaderNames, pipeline.WriterNames); if (pipeline.Length == 1) return applySource; startIndex = 1; } // The vertex code Type paramType = pipeline[startIndex].InputTypes[0].MakeArrayType(); ParameterExpression param = Expression.Parameter(paramType, MakeUniqueName("x")); CodeExpression pipelineArg = pipeline.BuildExpression(startIndex, param, param); bool orderPreserving = (m_context.SelectOrderPreserving || pipeline[pipeline.Length - 1].OutputDataSetInfo.orderByInfo.IsOrdered); CodeExpression applyExpr; if (this.m_context.EnableMultiThreadingInVertex) { applyExpr = new CodeMethodInvokeExpression( DryadLinqCodeGen.DLVTypeExpr, "PApply", new CodeVariableReferenceExpression(applySource), pipelineArg, new CodePrimitiveExpression(orderPreserving)); } else { applyExpr = new CodeMethodInvokeExpression( DryadLinqCodeGen.DLVTypeExpr, "Apply", new CodeVariableReferenceExpression(applySource), pipelineArg); } CodeVariableDeclarationStatement sourceDecl = this.MakeVarDeclStatement("var", "source", applyExpr); vertexMethod.Statements.Add(sourceDecl); return sourceDecl.Name; }
private void MakeSuperBody(CodeMemberMethod vertexMethod, DLinqQueryNode curNode, string[] writerNames, Pipeline pipeline) { bool isHomomorphic = curNode.IsHomomorphic; DLinqQueryNode[] curChildren = curNode.Children; string[] curSources = new string[curChildren.Length]; for (int i = 0; i < curChildren.Length; i++) { DLinqQueryNode child = curChildren[i]; if (this.Contains(child)) { this.MakeSuperBody(vertexMethod, child, writerNames, pipeline); if (!isHomomorphic) { curSources[i] = this.QueryGen.CodeGen.AddVertexCode(vertexMethod, pipeline); } } else { Type inputType = child.OutputTypes[0]; string factoryName = this.QueryGen.CodeGen.GetStaticFactoryName(inputType); CodeVariableDeclarationStatement readerDecl = this.QueryGen.CodeGen.MakeVertexReaderDecl(inputType, factoryName); vertexMethod.Statements.Add(readerDecl); curSources[i] = readerDecl.Name; pipeline.Reset(new string[] { readerDecl.Name }); } } if (!isHomomorphic) { pipeline.Reset(curSources); } pipeline.Add(curNode); }
internal DLinqDistinctNode(bool isPartial, Expression comparerExpr, Expression queryExpr, DLinqQueryNode child) : base(QueryNodeType.Distinct, child.QueryGen, queryExpr, child) { this.m_isPartial = isPartial; this.m_comparerExpr = comparerExpr; this.m_opName = "Distinct"; this.m_attachedPipeline = null; this.m_comparer = null; this.m_comparerIdx = -1; if (comparerExpr != null) { ExpressionSimplifier<object> evaluator = new ExpressionSimplifier<object>(); this.m_comparer = evaluator.Eval(comparerExpr); this.m_comparerIdx = DryadLinqObjectStore.Put(this.m_comparer); } this.m_partitionCount = child.OutputDataSetInfo.partitionInfo.Count; this.m_outputDataSetInfo = new DataSetInfo(child.OutputDataSetInfo); this.m_outputDataSetInfo.distinctInfo = DistinctInfo.Create(this.m_comparer, this.OutputTypes[0]); this.m_dynamicManager = this.InferDynamicManager(); }
internal override string AddVertexCode(CodeMemberMethod vertexMethod, string[] readerNames, string[] writerNames) { Pipeline pipeline = new Pipeline(vertexMethod, this.QueryGen.CodeGen, writerNames); this.MakeSuperBody(vertexMethod, this.m_rootNode, writerNames, pipeline); return this.QueryGen.CodeGen.AddVertexCode(vertexMethod, pipeline); }
internal DLinqJoinNode(QueryNodeType nodeType, string opName, LambdaExpression outerKeySelectExpr, LambdaExpression innerKeySelectExpr, LambdaExpression resultSelectExpr, Expression comparerExpr, Expression queryExpr, DLinqQueryNode outerChild, DLinqQueryNode innerChild) : base(nodeType, outerChild.QueryGen, queryExpr, outerChild, innerChild) { Debug.Assert(nodeType == QueryNodeType.Join || nodeType == QueryNodeType.GroupJoin); this.m_outerKeySelectExpr = outerKeySelectExpr; this.m_innerKeySelectExpr = innerKeySelectExpr; this.m_resultSelectExpr = resultSelectExpr; this.m_comparerExpr = comparerExpr; this.m_opName = opName; this.m_attachedPipeline = null; this.m_comparer = null; this.m_comparerIdx = -1; if (comparerExpr != null) { ExpressionSimplifier<object> evaluator = new ExpressionSimplifier<object>(); this.m_comparer = evaluator.Eval(comparerExpr); this.m_comparerIdx = DryadLinqObjectStore.Put(m_comparer); } if (StaticConfig.UseMemoryFIFO) { bool isStateful = this.IsStateful; foreach (DLinqQueryNode child in this.Children) { if (!(child is DLinqInputNode) && !child.IsForked && !(isStateful && child.IsStateful) && child.PartitionCount > 1) { child.ChannelType = ChannelType.MemoryFIFO; } isStateful = isStateful || child.IsStateful; } } this.m_partitionCount = outerChild.OutputDataSetInfo.partitionInfo.Count; this.m_outputDataSetInfo = this.ComputeOutputDataSetInfo(); this.m_dynamicManager = DynamicManager.None; }