// <summary> // Common copy path for all SetOps // </summary> // <param name="op"> The SetOp to Copy (must be one of ExceptOp, IntersectOp, UnionAllOp) </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> private Node CopySetOp(SetOp op, Node n) { // Visit the Node's children and map their Vars var children = ProcessChildren(n); var leftMap = new VarMap(); var rightMap = new VarMap(); foreach (var kv in op.VarMap[0]) { // Create a new output Var that is a copy of the original output Var Var outputVar = m_destCmd.CreateSetOpVar(kv.Key.Type); // Add a mapping for the new output var we've just created SetMappedVar(kv.Key, outputVar); // Add this output var's entries to the new VarMaps leftMap.Add(outputVar, GetMappedVar(kv.Value)); rightMap.Add(outputVar, GetMappedVar((op.VarMap[1])[kv.Key])); } SetOp newSetOp = null; switch (op.OpType) { case OpType.UnionAll: { var branchDiscriminator = ((UnionAllOp)op).BranchDiscriminator; if (null != branchDiscriminator) { branchDiscriminator = GetMappedVar(branchDiscriminator); } newSetOp = m_destCmd.CreateUnionAllOp(leftMap, rightMap, branchDiscriminator); } break; case OpType.Intersect: { newSetOp = m_destCmd.CreateIntersectOp(leftMap, rightMap); } break; case OpType.Except: { newSetOp = m_destCmd.CreateExceptOp(leftMap, rightMap); } break; default: { Debug.Assert(false, "Unexpected SetOpType"); } break; } return(m_destCmd.CreateNode(newSetOp, children)); }
internal virtual void BuildUnionAllLadder( IList <Node> inputNodes, IList <Var> inputVars, out Node resultNode, out IList <Var> resultVars) { if (inputNodes.Count == 0) { resultNode = (Node)null; resultVars = (IList <Var>)null; } else { int num = inputVars.Count / inputNodes.Count; if (inputNodes.Count == 1) { resultNode = inputNodes[0]; resultVars = inputVars; } else { List <Var> varList1 = new List <Var>(); Node node = inputNodes[0]; for (int index = 0; index < num; ++index) { varList1.Add(inputVars[index]); } for (int index1 = 1; index1 < inputNodes.Count; ++index1) { VarMap leftMap = new VarMap(); VarMap rightMap = new VarMap(); List <Var> varList2 = new List <Var>(); for (int index2 = 0; index2 < num; ++index2) { SetOpVar setOpVar = this.CreateSetOpVar(varList1[index2].Type); varList2.Add((Var)setOpVar); leftMap.Add((Var)setOpVar, varList1[index2]); rightMap.Add((Var)setOpVar, inputVars[index1 * num + index2]); } node = this.CreateNode((Op)this.CreateUnionAllOp(leftMap, rightMap), node, inputNodes[index1]); varList1 = varList2; } resultNode = node; resultVars = (IList <Var>)varList1; } } }
private Node CopySetOp(SetOp op, Node n) { List <Node> args = this.ProcessChildren(n); VarMap leftMap = new VarMap(); VarMap rightMap = new VarMap(); foreach (KeyValuePair <Var, Var> keyValuePair in (Dictionary <Var, Var>)op.VarMap[0]) { Var setOpVar = (Var)this.m_destCmd.CreateSetOpVar(keyValuePair.Key.Type); this.SetMappedVar(keyValuePair.Key, setOpVar); leftMap.Add(setOpVar, this.GetMappedVar(keyValuePair.Value)); rightMap.Add(setOpVar, this.GetMappedVar(op.VarMap[1][keyValuePair.Key])); } SetOp setOp = (SetOp)null; switch (op.OpType) { case OpType.UnionAll: Var var = ((UnionAllOp)op).BranchDiscriminator; if (var != null) { var = this.GetMappedVar(var); } setOp = (SetOp)this.m_destCmd.CreateUnionAllOp(leftMap, rightMap, var); break; case OpType.Intersect: setOp = (SetOp)this.m_destCmd.CreateIntersectOp(leftMap, rightMap); break; case OpType.Except: setOp = (SetOp)this.m_destCmd.CreateExceptOp(leftMap, rightMap); break; } return(this.m_destCmd.CreateNode((Op)setOp, args)); }
// <summary> // Set the "cloned" var for a given Var // WARNING: If a mapping already exists, an exception is raised // </summary> // <param name="v"> The original Var </param> // <param name="mappedVar"> The cloned Var </param> private void SetMappedVar(Var v, Var mappedVar) { m_varMap.Add(v, mappedVar); }