示例#1
0
        private static bool ProcessSetOpOverEmptySet(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node setOpNode,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            bool flag1 = context.Command.GetExtendedNodeInfo(setOpNode.Child0).MaxRows == RowCount.Zero;
            bool flag2 = context.Command.GetExtendedNodeInfo(setOpNode.Child1).MaxRows == RowCount.Zero;

            if (!flag1 && !flag2)
            {
                newNode = setOpNode;
                return(false);
            }
            SetOp op    = (SetOp)setOpNode.Op;
            int   index = !flag2 && op.OpType == OpType.UnionAll || !flag1 && op.OpType == OpType.Intersect ? 1 : 0;

            newNode = setOpNode.Children[index];
            TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context;

            foreach (KeyValuePair <Var, Var> keyValuePair in (Dictionary <Var, Var>)op.VarMap[index])
            {
                transformationRulesContext.AddVarMapping(keyValuePair.Key, keyValuePair.Value);
            }
            return(true);
        }
        private static bool ProcessApplyIntoScalarSubquery(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node applyNode,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            Command          command           = context.Command;
            ExtendedNodeInfo extendedNodeInfo1 = command.GetExtendedNodeInfo(applyNode.Child1);
            OpType           opType            = applyNode.Op.OpType;

            if (!ApplyOpRules.CanRewriteApply(applyNode.Child1, extendedNodeInfo1, opType))
            {
                newNode = applyNode;
                return(false);
            }
            ExtendedNodeInfo extendedNodeInfo2 = command.GetExtendedNodeInfo(applyNode.Child0);
            Var    first  = extendedNodeInfo1.Definitions.First;
            VarVec varVec = command.CreateVarVec(extendedNodeInfo2.Definitions);
            TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context;

            transformationRulesContext.RemapSubtree(applyNode.Child1);
            ApplyOpRules.VarDefinitionRemapper.RemapSubtree(applyNode.Child1, command, first);
            System.Data.Entity.Core.Query.InternalTrees.Node node = command.CreateNode((Op)command.CreateElementOp(first.Type), applyNode.Child1);
            Var computedVar;

            System.Data.Entity.Core.Query.InternalTrees.Node varDefListNode = command.CreateVarDefListNode(node, out computedVar);
            varVec.Set(computedVar);
            newNode = command.CreateNode((Op)command.CreateProjectOp(varVec), applyNode.Child0, varDefListNode);
            transformationRulesContext.AddVarMapping(first, computedVar);
            return(true);
        }
示例#3
0
        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);
        }
示例#4
0
        private static bool ProcessProjectOpWithNullSentinel(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node n,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            newNode = n;
            ProjectOp op = (ProjectOp)n.Op;

            if (n.Child1.Children.Where <System.Data.Entity.Core.Query.InternalTrees.Node>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, bool>)(c => c.Child0.Op.OpType == OpType.NullSentinel)).Count <System.Data.Entity.Core.Query.InternalTrees.Node>() == 0)
            {
                return(false);
            }
            TransformationRulesContext transformationRulesContext = (TransformationRulesContext)context;
            Command          command           = transformationRulesContext.Command;
            ExtendedNodeInfo extendedNodeInfo  = command.GetExtendedNodeInfo(n.Child0);
            bool             flag1             = false;
            bool             nullSentinelValue = transformationRulesContext.CanChangeNullSentinelValue;
            Var int32Var;

            if (!nullSentinelValue || !TransformationRulesContext.TryGetInt32Var((IEnumerable <Var>)extendedNodeInfo.NonNullableDefinitions, out int32Var))
            {
                flag1 = true;
                if (!nullSentinelValue || !TransformationRulesContext.TryGetInt32Var(n.Child1.Children.Where <System.Data.Entity.Core.Query.InternalTrees.Node>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, bool>)(child =>
                {
                    if (child.Child0.Op.OpType != OpType.Constant)
                    {
                        return(child.Child0.Op.OpType == OpType.InternalConstant);
                    }
                    return(true);
                })).Select <System.Data.Entity.Core.Query.InternalTrees.Node, Var>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, Var>)(child => ((VarDefOp)child.Op).Var)), out int32Var))
                {
                    int32Var = n.Child1.Children.Where <System.Data.Entity.Core.Query.InternalTrees.Node>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, bool>)(child => child.Child0.Op.OpType == OpType.NullSentinel)).Select <System.Data.Entity.Core.Query.InternalTrees.Node, Var>((Func <System.Data.Entity.Core.Query.InternalTrees.Node, Var>)(child => ((VarDefOp)child.Op).Var)).FirstOrDefault <Var>();
                    if (int32Var == null)
                    {
                        return(false);
                    }
                }
            }
            bool flag2 = false;

            for (int index = n.Child1.Children.Count - 1; index >= 0; --index)
            {
                System.Data.Entity.Core.Query.InternalTrees.Node child = n.Child1.Children[index];
                if (child.Child0.Op.OpType == OpType.NullSentinel)
                {
                    if (!flag1)
                    {
                        VarRefOp varRefOp = command.CreateVarRefOp(int32Var);
                        child.Child0 = command.CreateNode((Op)varRefOp);
                        command.RecomputeNodeInfo(child);
                        flag2 = true;
                    }
                    else if (!int32Var.Equals((object)((VarDefOp)child.Op).Var))
                    {
                        op.Outputs.Clear(((VarDefOp)child.Op).Var);
                        n.Child1.Children.RemoveAt(index);
                        transformationRulesContext.AddVarMapping(((VarDefOp)child.Op).Var, int32Var);
                        flag2 = true;
                    }
                }
            }
            if (flag2)
            {
                command.RecomputeNodeInfo(n.Child1);
            }
            return(flag2);
        }