private static bool ProcessProjectOverProject( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node projectNode, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { newNode = projectNode; ProjectOp op1 = (ProjectOp)projectNode.Op; System.Data.Entity.Core.Query.InternalTrees.Node child1 = projectNode.Child1; System.Data.Entity.Core.Query.InternalTrees.Node child0 = projectNode.Child0; ProjectOp op2 = (ProjectOp)child0.Op; TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context; Dictionary <Var, int> varRefMap = new Dictionary <Var, int>(); foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in child1.Children) { if (!transformationRulesContext.IsScalarOpTree(child.Child0, varRefMap)) { return(false); } } Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> varMap = transformationRulesContext.GetVarMap(child0.Child1, varRefMap); if (varMap == null) { return(false); } System.Data.Entity.Core.Query.InternalTrees.Node node = transformationRulesContext.Command.CreateNode((Op)transformationRulesContext.Command.CreateVarDefListOp()); foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in child1.Children) { child.Child0 = transformationRulesContext.ReMap(child.Child0, varMap); transformationRulesContext.Command.RecomputeNodeInfo(child); node.Children.Add(child); } ExtendedNodeInfo extendedNodeInfo = transformationRulesContext.Command.GetExtendedNodeInfo(projectNode); foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in child0.Child1.Children) { VarDefOp op3 = (VarDefOp)child.Op; if (extendedNodeInfo.Definitions.IsSet(op3.Var)) { node.Children.Add(child); } } projectNode.Child0 = child0.Child0; projectNode.Child1 = node; return(true); }
private static bool ProcessJoinOverProject( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node joinNode, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { newNode = joinNode; TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context; Command command = transformationRulesContext.Command; System.Data.Entity.Core.Query.InternalTrees.Node node1 = joinNode.HasChild2 ? joinNode.Child2 : (System.Data.Entity.Core.Query.InternalTrees.Node)null; Dictionary <Var, int> varRefMap = new Dictionary <Var, int>(); if (node1 != null && !transformationRulesContext.IsScalarOpTree(node1, varRefMap)) { return(false); } VarVec varVec1 = command.CreateVarVec(); List <System.Data.Entity.Core.Query.InternalTrees.Node> args = new List <System.Data.Entity.Core.Query.InternalTrees.Node>(); if (joinNode.Op.OpType != OpType.LeftOuterJoin && joinNode.Child0.Op.OpType == OpType.Project && joinNode.Child1.Op.OpType == OpType.Project) { ProjectOp op1 = (ProjectOp)joinNode.Child0.Op; ProjectOp op2 = (ProjectOp)joinNode.Child1.Op; Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> varMap1 = transformationRulesContext.GetVarMap(joinNode.Child0.Child1, varRefMap); Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> varMap2 = transformationRulesContext.GetVarMap(joinNode.Child1.Child1, varRefMap); if (varMap1 == null || varMap2 == null) { return(false); } System.Data.Entity.Core.Query.InternalTrees.Node node2; if (node1 != null) { System.Data.Entity.Core.Query.InternalTrees.Node node3 = transformationRulesContext.ReMap(node1, varMap1); System.Data.Entity.Core.Query.InternalTrees.Node node4 = transformationRulesContext.ReMap(node3, varMap2); node2 = context.Command.CreateNode(joinNode.Op, joinNode.Child0.Child0, joinNode.Child1.Child0, node4); } else { node2 = context.Command.CreateNode(joinNode.Op, joinNode.Child0.Child0, joinNode.Child1.Child0); } varVec1.InitFrom(op1.Outputs); foreach (Var output in op2.Outputs) { varVec1.Set(output); } ProjectOp projectOp = command.CreateProjectOp(varVec1); args.AddRange((IEnumerable <System.Data.Entity.Core.Query.InternalTrees.Node>)joinNode.Child0.Child1.Children); args.AddRange((IEnumerable <System.Data.Entity.Core.Query.InternalTrees.Node>)joinNode.Child1.Child1.Children); System.Data.Entity.Core.Query.InternalTrees.Node node5 = command.CreateNode((Op)command.CreateVarDefListOp(), args); System.Data.Entity.Core.Query.InternalTrees.Node node6 = command.CreateNode((Op)projectOp, node2, node5); newNode = node6; return(true); } int index1; int index2; if (joinNode.Child0.Op.OpType == OpType.Project) { index1 = 0; index2 = 1; } else { System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(joinNode.Op.OpType != OpType.LeftOuterJoin, "unexpected non-LeftOuterJoin"); index1 = 1; index2 = 0; } System.Data.Entity.Core.Query.InternalTrees.Node child = joinNode.Children[index1]; ProjectOp op = child.Op as ProjectOp; Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> varMap = transformationRulesContext.GetVarMap(child.Child1, varRefMap); if (varMap == null) { return(false); } ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(joinNode.Children[index2]); VarVec varVec2 = command.CreateVarVec(op.Outputs); varVec2.Or(extendedNodeInfo.Definitions); op.Outputs.InitFrom(varVec2); if (node1 != null) { System.Data.Entity.Core.Query.InternalTrees.Node node2 = transformationRulesContext.ReMap(node1, varMap); joinNode.Child2 = node2; } joinNode.Children[index1] = child.Child0; context.Command.RecomputeNodeInfo(joinNode); newNode = context.Command.CreateNode((Op)op, joinNode, child.Child1); return(true); }