本文整理汇总了C#中System.Data.Entity.Core.Query.InternalTrees.Node类的典型用法代码示例。如果您正苦于以下问题:C# Node类的具体用法?C# Node怎么用?C# Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于System.Data.Entity.Core.Query.InternalTrees命名空间,在下文中一共展示了Node类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PatternMatchRule
/// <summary>
/// Basic constructor
/// </summary>
/// <param name="pattern"> The pattern to look for </param>
/// <param name="processDelegate"> The callback to invoke when such a pattern is identified </param>
internal PatternMatchRule(Node pattern, ProcessNodeDelegate processDelegate)
: base(pattern.Op.OpType, processDelegate)
{
Debug.Assert(pattern != null, "null pattern");
Debug.Assert(pattern.Op != null, "null pattern Op");
m_pattern = pattern;
}
示例2: VisitDefault
protected override Node VisitDefault(Node n)
{
var negated = _negated;
switch (n.Op.OpType)
{
case OpType.Not:
_negated = !_negated;
n = base.VisitDefault(n);
break;
case OpType.Or:
n = HandleOr(n);
break;
case OpType.And:
n = base.VisitDefault(n);
break;
case OpType.EQ:
_negated = false;
n = HandleEQ(n, negated);
break;
case OpType.NE:
n = HandleNE(n);
break;
default:
_negated = false;
n = base.VisitDefault(n);
break;
}
_negated = negated;
return n;
}
示例3: ProcessSetOpOverEmptySet
/// <summary>
/// Process a SetOp when one of the inputs is an emptyset.
///
/// An emptyset is represented by a Filter(X, ConstantPredicate)
/// where the ConstantPredicate has a value of "false"
///
/// The general rules are
/// UnionAll(X, EmptySet) => X
/// UnionAll(EmptySet, X) => X
/// Intersect(EmptySet, X) => EmptySet
/// Intersect(X, EmptySet) => EmptySet
/// Except(EmptySet, X) => EmptySet
/// Except(X, EmptySet) => X
///
/// These rules then translate into
/// UnionAll: return the non-empty input
/// Intersect: return the empty input
/// Except: return the "left" input
/// </summary>
/// <param name="context"> Rule processing context </param>
/// <param name="setOpNode"> the current setop tree </param>
/// <param name="filterNodeIndex"> Index of the filter node in the setop </param>
/// <param name="newNode"> transformed subtree </param>
/// <returns> transformation status </returns>
private static bool ProcessSetOpOverEmptySet(RuleProcessingContext context, Node setOpNode, out Node newNode)
{
var leftChildIsEmptySet = context.Command.GetExtendedNodeInfo(setOpNode.Child0).MaxRows == RowCount.Zero;
var rightChildIsEmptySet = context.Command.GetExtendedNodeInfo(setOpNode.Child1).MaxRows == RowCount.Zero;
if (!leftChildIsEmptySet
&& !rightChildIsEmptySet)
{
newNode = setOpNode;
return false;
}
int indexToReturn;
var setOp = (SetOp)setOpNode.Op;
if (!rightChildIsEmptySet && setOp.OpType == OpType.UnionAll
||
!leftChildIsEmptySet && setOp.OpType == OpType.Intersect)
{
indexToReturn = 1;
}
else
{
indexToReturn = 0;
}
newNode = setOpNode.Children[indexToReturn];
var trc = (TransformationRulesContext)context;
foreach (var kv in setOp.VarMap[indexToReturn])
{
trc.AddVarMapping(kv.Key, kv.Value);
}
return true;
}
示例4: ProcessSimplifyCase
/// <summary>
/// We perform the following simple transformation for CaseOps. If every single
/// then/else expression in the CaseOp is equivalent, then we can simply replace
/// the Op with the first then/expression. Specifically,
/// case when w1 then t1 when w2 then t2 ... when wn then tn else e end
/// => t1
/// assuming that t1 is equivalent to t2 is equivalent to ... to e
/// </summary>
/// <param name="context"> Rule Processing context </param>
/// <param name="caseOpNode"> The current subtree for the CaseOp </param>
/// <param name="newNode"> the (possibly) modified subtree </param>
/// <returns> true, if we performed any transformations </returns>
private static bool ProcessSimplifyCase(RuleProcessingContext context, Node caseOpNode, out Node newNode)
{
var caseOp = (CaseOp)caseOpNode.Op;
newNode = caseOpNode;
//
// Can I collapse the entire case-expression into a single expression - yes,
// if all the then/else clauses are the same expression
//
if (ProcessSimplifyCase_Collapse(caseOpNode, out newNode))
{
return true;
}
//
// Can I remove any unnecessary when-then pairs ?
//
if (ProcessSimplifyCase_EliminateWhenClauses(context, caseOp, caseOpNode, out newNode))
{
return true;
}
// Nothing else I can think of
return false;
}
示例5: HandleOr
private Node HandleOr(Node n)
{
// Check for the pattern '(varRef IS NULL) OR expression'.
var isNullNode =
n.Child0.Op.OpType == OpType.IsNull
? n.Child0
: null;
if (isNullNode == null
|| isNullNode.Child0.Op.OpType != OpType.VarRef)
{
return base.VisitDefault(n);
}
// Mark 'variable' as not nullable while 'expression' is visited.
Var variable = ((VarRefOp)isNullNode.Child0.Op).Var;
var nullable = _variableNullabilityTable[variable];
_variableNullabilityTable[variable] = false;
n.Child1 = VisitNode(n.Child1);
_variableNullabilityTable[variable] = nullable;
return n;
}
示例6: Match
private bool Match(Node pattern, Node original)
{
if (pattern.Op.OpType
== OpType.Leaf)
{
return true;
}
if (pattern.Op.OpType
!= original.Op.OpType)
{
return false;
}
if (pattern.Children.Count
!= original.Children.Count)
{
return false;
}
for (var i = 0; i < pattern.Children.Count; i++)
{
if (!Match(pattern.Children[i], original.Children[i]))
{
return false;
}
}
return true;
}
示例7: VisitChildren
/// <summary>
/// Visit the children of this Node
/// </summary>
/// <param name="n"> The Node that references the Op </param>
protected virtual void VisitChildren(Node n)
{
foreach (var chi in n.Children)
{
VisitNode(chi);
}
}
示例8: ApplyRulesToNode
private static bool ApplyRulesToNode(
RuleProcessingContext context, ReadOnlyCollection<ReadOnlyCollection<Rule>> rules, Node currentNode, out Node newNode)
{
newNode = currentNode;
// Apply any pre-rule delegates
context.PreProcess(currentNode);
foreach (var r in rules[(int)currentNode.Op.OpType])
{
if (!r.Match(currentNode))
{
continue;
}
// Did the rule modify the subtree?
if (r.Apply(context, currentNode, out newNode))
{
// The node has changed; don't try to apply any more rules
context.PostProcess(newNode, r);
return true;
}
else
{
Debug.Assert(newNode == currentNode, "Liar! This rule should have returned 'true'");
}
}
context.PostProcess(currentNode, null);
return false;
}
示例9: VisitChildrenReverse
/// <summary>
/// Visit the children of this Node. but in reverse order
/// </summary>
/// <param name="n"> The current node </param>
protected virtual void VisitChildrenReverse(Node n)
{
for (var i = n.Children.Count - 1; i >= 0; i--)
{
VisitNode(n.Children[i]);
}
}
示例10: ReMap
internal Node ReMap(Node node, Dictionary<Var, Node> varMap)
{
PlanCompiler.Assert(node.Op.IsScalarOp, "Expected a scalarOp: Found " + Dump.AutoString.ToString(node.Op.OpType));
// Replace varRefOps by the corresponding expression in the map, if any
if (node.Op.OpType
== OpType.VarRef)
{
var varRefOp = node.Op as VarRefOp;
Node newNode = null;
if (varMap.TryGetValue(varRefOp.Var, out newNode))
{
newNode = Copy(newNode);
return newNode;
}
else
{
return node;
}
}
// Simply process the result of the children.
for (var i = 0; i < node.Children.Count; i++)
{
node.Children[i] = ReMap(node.Children[i], varMap);
}
// We may have changed something deep down
Command.RecomputeNodeInfo(node);
return node;
}
示例11: Copy
internal static Node Copy(Command cmd, Node n, out VarMap varMap)
{
var oc = new OpCopier(cmd);
var newNode = oc.CopyNode(n);
varMap = oc.m_varMap;
return newNode;
}
示例12: ProcessDistinctOpOfKeys
/// <summary>
/// If the DistinctOp includes all all the keys of the input, than it is unnecessary.
/// Distinct (X, distinct_keys) -> Project( X, distinct_keys) where distinct_keys includes all keys of X.
/// </summary>
/// <param name="context"> Rule processing context </param>
/// <param name="n"> current subtree </param>
/// <param name="newNode"> transformed subtree </param>
/// <returns> transformation status </returns>
private static bool ProcessDistinctOpOfKeys(RuleProcessingContext context, Node n, out Node newNode)
{
var command = context.Command;
var nodeInfo = command.GetExtendedNodeInfo(n.Child0);
var op = (DistinctOp)n.Op;
//If we know the keys of the input and the list of distinct keys includes them all, omit the distinct
if (!nodeInfo.Keys.NoKeys
&& op.Keys.Subsumes(nodeInfo.Keys.KeyVars))
{
var newOp = command.CreateProjectOp(op.Keys);
//Create empty vardef list
var varDefListOp = command.CreateVarDefListOp();
var varDefListNode = command.CreateNode(varDefListOp);
newNode = command.CreateNode(newOp, n.Child0, varDefListNode);
return true;
}
//Otherwise return the node as is
newNode = n;
return false;
}
示例13: ProcessSingleRowOpOverAnything
// <summary>
// Convert a
// SingleRowOp(X) => X
// if X produces at most one row
// </summary>
// <param name="context"> Rule Processing context </param>
// <param name="singleRowNode"> Current subtree </param>
// <param name="newNode"> transformed subtree </param>
// <returns> Transformation status </returns>
private static bool ProcessSingleRowOpOverAnything(RuleProcessingContext context, Node singleRowNode, out Node newNode)
{
newNode = singleRowNode;
var trc = (TransformationRulesContext)context;
var childNodeInfo = context.Command.GetExtendedNodeInfo(singleRowNode.Child0);
// If the input to this Op can produce at most one row, then we don't need the
// singleRowOp - simply return the input
if (childNodeInfo.MaxRows
<= RowCount.One)
{
newNode = singleRowNode.Child0;
return true;
}
//
// if the current node is a FilterOp, then try and determine if the FilterOp
// produces one row at most
//
if (singleRowNode.Child0.Op.OpType
== OpType.Filter)
{
var predicate = new Predicate(context.Command, singleRowNode.Child0.Child1);
if (predicate.SatisfiesKey(childNodeInfo.Keys.KeyVars, childNodeInfo.Definitions))
{
childNodeInfo.MaxRows = RowCount.One;
newNode = singleRowNode.Child0;
return true;
}
}
// we couldn't do anything
return false;
}
示例14: Visit
// <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]);
}
}
}
}
示例15: ComputeHashValue
/// <summary>
/// Compute the hash value for this node
/// </summary>
internal override void ComputeHashValue(Command cmd, Node n)
{
base.ComputeHashValue(cmd, n);
m_hashValue = (m_hashValue << 4) ^ GetHashValue(Definitions);
m_hashValue = (m_hashValue << 4) ^ GetHashValue(Keys.KeyVars);
return;
}