// <summary> // Determines whether the var or a property of the var (if the var is defined as a NewRecord) // is defined exclusively over a single group aggregate. If so, it registers it as such with the // group aggregate var info manager. // </summary> public override void Visit(VarDefOp op, Node n) { VisitDefault(n); var definingNode = n.Child0; var definingNodeOp = definingNode.Op; GroupAggregateVarInfo referencedVarInfo; Node templateNode; bool isUnnested; if (GroupAggregateVarComputationTranslator.TryTranslateOverGroupAggregateVar( definingNode, true, _command, _groupAggregateVarInfoManager, out referencedVarInfo, out templateNode, out isUnnested)) { _groupAggregateVarInfoManager.Add(op.Var, referencedVarInfo, templateNode, isUnnested); } else if (definingNodeOp.OpType == OpType.NewRecord) { var newRecordOp = (NewRecordOp)definingNodeOp; for (var i = 0; i < definingNode.Children.Count; i++) { var argumentNode = definingNode.Children[i]; if (GroupAggregateVarComputationTranslator.TryTranslateOverGroupAggregateVar( argumentNode, true, _command, _groupAggregateVarInfoManager, out referencedVarInfo, out templateNode, out isUnnested)) { _groupAggregateVarInfoManager.Add(op.Var, referencedVarInfo, templateNode, isUnnested, newRecordOp.Properties[i]); } } } }
internal Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> GetVarMap( System.Data.Entity.Core.Query.InternalTrees.Node varDefListNode, Dictionary <Var, int> varRefMap) { VarDefListOp op1 = (VarDefListOp)varDefListNode.Op; Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> dictionary = new Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node>(); foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in varDefListNode.Children) { VarDefOp op2 = (VarDefOp)child.Op; int nonLeafNodeCount = 0; int num = 0; if (!this.IsScalarOpTree(child.Child0, (Dictionary <Var, int>)null, ref nonLeafNodeCount) || nonLeafNodeCount > 100 && varRefMap != null && (varRefMap.TryGetValue(op2.Var, out num) && num > 2)) { return((Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node>)null); } System.Data.Entity.Core.Query.InternalTrees.Node node; if (dictionary.TryGetValue(op2.Var, out node)) { System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(node == child.Child0, "reusing varDef for different Node?"); } else { dictionary.Add(op2.Var, child.Child0); } } return(dictionary); }
public override void Visit(VarDefOp op, System.Data.Entity.Core.Query.InternalTrees.Node n) { this.VisitDefault(n); System.Data.Entity.Core.Query.InternalTrees.Node child0 = n.Child0; Op op1 = child0.Op; GroupAggregateVarInfo groupAggregateVarInfo; System.Data.Entity.Core.Query.InternalTrees.Node templateNode; bool isUnnested; if (GroupAggregateVarComputationTranslator.TryTranslateOverGroupAggregateVar(child0, true, this._command, this._groupAggregateVarInfoManager, out groupAggregateVarInfo, out templateNode, out isUnnested)) { this._groupAggregateVarInfoManager.Add(op.Var, groupAggregateVarInfo, templateNode, isUnnested); } else { if (op1.OpType != OpType.NewRecord) { return; } NewRecordOp newRecordOp = (NewRecordOp)op1; for (int index = 0; index < child0.Children.Count; ++index) { if (GroupAggregateVarComputationTranslator.TryTranslateOverGroupAggregateVar(child0.Children[index], true, this._command, this._groupAggregateVarInfoManager, out groupAggregateVarInfo, out templateNode, out isUnnested)) { this._groupAggregateVarInfoManager.Add(op.Var, groupAggregateVarInfo, templateNode, isUnnested, (EdmMember)newRecordOp.Properties[index]); } } } }
// <summary> // If the node defines the node that needs to be remapped, // it remaps it to a new var. // </summary> public override void Visit(VarDefOp op, Node n) { if (op.Var == m_oldVar) { Var newVar = m_command.CreateComputedVar(n.Child0.Op.Type); n.Op = m_command.CreateVarDefOp(newVar); AddMapping(m_oldVar, newVar); } }
public override void Visit(VarDefOp op, System.Data.Entity.Core.Query.InternalTrees.Node n) { if (TypeUtils.IsStructuredType(op.Var.Type)) { PropertyRefList propertyRefList = this.GetPropertyRefList(op.Var); this.AddPropertyRefs(n.Child0, propertyRefList); } this.VisitChildren(n); }
private static bool ProcessGroupByWithSimpleVarRedefinitions( RuleProcessingContext context, System.Data.Entity.Core.Query.InternalTrees.Node n, out System.Data.Entity.Core.Query.InternalTrees.Node newNode) { newNode = n; GroupByOp op1 = (GroupByOp)n.Op; if (n.Child1.Children.Count == 0) { return(false); } TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context; Command command = transformationRulesContext.Command; ExtendedNodeInfo extendedNodeInfo = command.GetExtendedNodeInfo(n); bool flag = false; foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in n.Child1.Children) { System.Data.Entity.Core.Query.InternalTrees.Node child0 = child.Child0; if (child0.Op.OpType == OpType.VarRef) { VarRefOp op2 = (VarRefOp)child0.Op; if (!extendedNodeInfo.ExternalReferences.IsSet(op2.Var)) { flag = true; } } } if (!flag) { return(false); } List <System.Data.Entity.Core.Query.InternalTrees.Node> args = new List <System.Data.Entity.Core.Query.InternalTrees.Node>(); foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in n.Child1.Children) { VarDefOp op2 = (VarDefOp)child.Op; VarRefOp op3 = child.Child0.Op as VarRefOp; if (op3 != null && !extendedNodeInfo.ExternalReferences.IsSet(op3.Var)) { op1.Outputs.Clear(op2.Var); op1.Outputs.Set(op3.Var); op1.Keys.Clear(op2.Var); op1.Keys.Set(op3.Var); transformationRulesContext.AddVarMapping(op2.Var, op3.Var); } else { args.Add(child); } } System.Data.Entity.Core.Query.InternalTrees.Node node = command.CreateNode((Op)command.CreateVarDefListOp(), args); n.Child1 = node; return(true); }
/// <summary> /// VarDefOp handling /// /// Pushes the "desired" properties to the /// defining expression /// </summary> /// <param name="op"></param> /// <param name="n"></param> public override void Visit(VarDefOp op, Node n) { if (TypeUtils.IsStructuredType(op.Var.Type)) { PropertyRefList myProps = GetPropertyRefList(op.Var); // Push this down to the expression defining the var AddPropertyRefs(n.Child0, myProps); } VisitChildren(n); }
public override void Visit(VarDefOp op, System.Data.Entity.Core.Query.InternalTrees.Node n) { if (op.Var != this.m_oldVar) { return; } Var computedVar = (Var)this.m_command.CreateComputedVar(n.Child0.Op.Type); n.Op = (Op)this.m_command.CreateVarDefOp(computedVar); this.AddMapping(this.m_oldVar, computedVar); }
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); }
/// <summary> /// VarDefListOp /// /// Walks the children (VarDefOp), and looks for those whose Vars /// have been referenced. Only those VarDefOps are visited - the /// others are ignored. /// /// At the end, a new list of children is created - with only those /// VarDefOps that have been referenced /// </summary> /// <param name="op">the varDefListOp</param> /// <param name="n">corresponding node</param> /// <returns>modified node</returns> public override Node Visit(VarDefListOp op, Node n) { // NOTE: It would be nice to optimize this to only create a new node // and new list, if we needed to eliminate some arguments, but // I'm not sure that the effort to eliminate the allocations // wouldn't be more expensive than the allocations themselves. // It's something that we can consider if it shows up on the // perf radar. // Get rid of all the children that we don't care about (ie) // those VarDefOp's that haven't been referenced List <Node> newChildren = new List <Node>(); foreach (Node chi in n.Children) { VarDefOp varDefOp = chi.Op as VarDefOp; if (IsReferenced(varDefOp.Var)) { newChildren.Add(VisitNode(chi)); } } return(m_command.CreateNode(op, newChildren)); }
// <summary> // Copies a VarDefOp // </summary> // <param name="op"> The Op to Copy </param> // <param name="n"> The Node that references the Op </param> // <returns> A copy of the original Node that references a copy of the original Op </returns> public override Node Visit(VarDefOp op, Node n) { // First create a new Var var children = ProcessChildren(n); Debug.Assert(op.Var.VarType == VarType.Computed, "Unexpected VarType"); Var newVar = m_destCmd.CreateComputedVar(op.Var.Type); SetMappedVar(op.Var, newVar); return m_destCmd.CreateNode(m_destCmd.CreateVarDefOp(newVar), children); }
// <summary> // VarDefOp // Essentially, maintains m_varRefMap, adding an entry for each VarDef that has a // VarRef on it. // </summary> public override Node Visit(VarDefOp op, Node n) { VisitChildren(n); // perform any "remapping" m_varRemapper.RemapNode(n); if (n.Child0.Op.OpType == OpType.VarRef) { m_varRefMap.Add(op.Var, ((VarRefOp)n.Child0.Op).Var); } return n; }
/// <summary> /// Helps flatten out an enum or strong spatial Var /// </summary> /// <param name="varDefOp"> Var definition expression. Must not be null. </param> /// <param name="node"> Subtree rooted at the VarDefOp expression. Must not be null. </param> /// <returns> VarDefNode referencing the newly created Var. </returns> private Node FlattenEnumOrStrongSpatialVar(VarDefOp varDefOp, Node node) { DebugCheck.NotNull(varDefOp); DebugCheck.NotNull(node); Var newVar; var newVarDefNode = m_command.CreateVarDefNode(node, out newVar); m_varInfoMap.CreatePrimitiveTypeVarInfo(varDefOp.Var, newVar); return newVarDefNode; }
/// <summary> /// Helps flatten out an enum or strong spatial Var /// </summary> /// <param name="varDefOp">Var definition expression. Must not be null.</param> /// <param name="node">Subtree rooted at the VarDefOp expression. Must not be null.</param> /// <returns>VarDefNode referencing the newly created Var.</returns> private Node FlattenEnumOrStrongSpatialVar(VarDefOp varDefOp, Node node) { System.Diagnostics.Debug.Assert(varDefOp != null, "varDefOp != null"); System.Diagnostics.Debug.Assert(node != null, "node != null"); Var newVar; Node newVarDefNode = m_command.CreateVarDefNode(node, out newVar); m_varInfoMap.CreatePrimitiveTypeVarInfo(varDefOp.Var, newVar); return newVarDefNode; }
public override void Visit(VarDefOp op, Node n) { VisitAncillaryOpDefault(op, n); AssertScalarOp(n.Child0.Op); var varDefOp = op; AssertEqualTypes(varDefOp.Var.Type, n.Child0.Op.Type); }
/// <summary> /// VarDefOp handling /// /// Pushes the "desired" properties to the /// defining expression /// </summary> /// <param name="op"> </param> /// <param name="n"> </param> public override void Visit(VarDefOp op, Node n) { if (TypeUtils.IsStructuredType(op.Var.Type)) { var myProps = GetPropertyRefList(op.Var); // Push this down to the expression defining the var AddPropertyRefs(n.Child0, myProps); } VisitChildren(n); }
/// <summary> /// Visitor pattern method for VarDefOp /// </summary> /// <param name="op"> The VarDefOp being visited </param> /// <param name="n"> The Node that references the Op </param> public virtual void Visit(VarDefOp op, Node n) { VisitAncillaryOpDefault(op, n); }