Ejemplo n.º 1
0
        /// <summary>
        /// Build up a mapping from Vars to the corresponding property of the output row type
        /// </summary>
        /// <param name="projectOp">the physical projectOp</param>
        /// <param name="outputType">output type</param>
        /// <returns>a map from Vars to the output type member</returns>
        private static Dictionary <Var, md.EdmProperty> BuildOutputVarMap(PhysicalProjectOp projectOp, md.TypeUsage outputType)
        {
            Dictionary <Var, md.EdmProperty> outputVarMap = new Dictionary <Var, md.EdmProperty>();

            PlanCompiler.Assert(md.TypeSemantics.IsRowType(outputType), "PhysicalProjectOp result type is not a RowType?");

            IEnumerator <md.EdmProperty> propertyEnumerator = TypeHelpers.GetEdmType <md.RowType>(outputType).Properties.GetEnumerator();
            IEnumerator <Var>            varEnumerator      = projectOp.Outputs.GetEnumerator();

            while (true)
            {
                bool foundProp = propertyEnumerator.MoveNext();
                bool foundVar  = varEnumerator.MoveNext();
                if (foundProp != foundVar)
                {
                    throw EntityUtil.InternalError(EntityUtil.InternalErrorCode.ColumnCountMismatch, 1);
                }
                if (!foundProp)
                {
                    break;
                }
                outputVarMap[varEnumerator.Current] = propertyEnumerator.Current;
            }
            return(outputVarMap);
        }
Ejemplo n.º 2
0
        private static Dictionary <Var, EdmProperty> BuildOutputVarMap(
            PhysicalProjectOp projectOp,
            TypeUsage outputType)
        {
            Dictionary <Var, EdmProperty> dictionary = new Dictionary <Var, EdmProperty>();

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(TypeSemantics.IsRowType(outputType), "PhysicalProjectOp result type is not a RowType?");
            IEnumerator <EdmProperty> enumerator1 = (IEnumerator <EdmProperty>)TypeHelpers.GetEdmType <RowType>(outputType).Properties.GetEnumerator();
            IEnumerator <Var>         enumerator2 = (IEnumerator <Var>)projectOp.Outputs.GetEnumerator();

            while (true)
            {
                bool flag1 = enumerator1.MoveNext();
                bool flag2 = enumerator2.MoveNext();
                if (flag1 == flag2)
                {
                    if (flag1)
                    {
                        dictionary[enumerator2.Current] = enumerator1.Current;
                    }
                    else
                    {
                        goto label_5;
                    }
                }
                else
                {
                    break;
                }
            }
            throw EntityUtil.InternalError(EntityUtil.InternalErrorCode.ColumnCountMismatch, 1, (object)null);
label_5:
            return(dictionary);
        }
Ejemplo n.º 3
0
        public override void Visit(PhysicalProjectOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            this.VisitPhysicalOpDefault((PhysicalOp)op, n);
            this.Map(op.Outputs);
            SimpleCollectionColumnMap columnMap = (SimpleCollectionColumnMap)ColumnMapTranslator.Translate((ColumnMap)op.ColumnMap, this.m_varMap);

            n.Op = (Op)this.m_command.CreatePhysicalProjectOp(op.Outputs, columnMap);
        }
Ejemplo n.º 4
0
        private ColumnMap BuildResultColumnMap(PhysicalProjectOp projectOp)
        {
            // convert the column map into a real column map
            // build up a dictionary mapping Vars to their real positions in the commands
            var varMap        = BuildVarMap();
            var realColumnMap = ColumnMapTranslator.Translate(projectOp.ColumnMap, varMap);

            return(realColumnMap);
        }
Ejemplo n.º 5
0
        private ColumnMap BuildResultColumnMap(PhysicalProjectOp projectOp)
        {
            // convert the column map into a real column map
            // build up a dictionary mapping Vars to their real positions in the commands
            var varMap = BuildVarMap();
            var realColumnMap = ColumnMapTranslator.Translate(projectOp.ColumnMap, varMap);

            return realColumnMap;
        }
Ejemplo n.º 6
0
        public override void Visit(PhysicalProjectOp op, Node n)
        {
            VisitPhysicalOpDefault(op, n);
            Map(op.Outputs);

            var newColumnMap = (SimpleCollectionColumnMap)ColumnMapTranslator.Translate(op.ColumnMap, m_varMap);

            n.Op = m_command.CreatePhysicalProjectOp(op.Outputs, newColumnMap);
        }
Ejemplo n.º 7
0
 public override void Visit(PhysicalProjectOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     foreach (Var output in (List <Var>)op.Outputs)
     {
         if (TypeUtils.IsStructuredType(output.Type))
         {
             this.AddPropertyRefs(output, PropertyRefList.All);
         }
     }
     this.VisitChildren(n);
 }
Ejemplo n.º 8
0
        private static bool ProcessGroupByOpOnAllInputColumnsWithAggregateOperation(
            RuleProcessingContext context,
            System.Data.Entity.Core.Query.InternalTrees.Node n,
            out System.Data.Entity.Core.Query.InternalTrees.Node newNode)
        {
            newNode = n;
            PhysicalProjectOp op1 = context.Command.Root.Op as PhysicalProjectOp;

            if (op1 == null || op1.Outputs.Count > 1 || (n.Child0.Op.OpType != OpType.ScanTable || n.Child2 == null) || (n.Child2.Child0 == null || n.Child2.Child0.Child0 == null || n.Child2.Child0.Child0.Op.OpType != OpType.Aggregate))
            {
                return(false);
            }
            GroupByOp op2     = (GroupByOp)n.Op;
            Table     table   = ((ScanTableBaseOp)n.Child0.Op).Table;
            VarList   columns = table.Columns;

            foreach (Var v in (List <Var>)columns)
            {
                if (!op2.Keys.IsSet(v))
                {
                    return(false);
                }
            }
            foreach (Var v in (List <Var>)columns)
            {
                op2.Outputs.Clear(v);
                op2.Keys.Clear(v);
            }
            Command     command     = context.Command;
            ScanTableOp scanTableOp = command.CreateScanTableOp(table.TableMetadata);

            System.Data.Entity.Core.Query.InternalTrees.Node node1 = command.CreateNode((Op)scanTableOp);
            System.Data.Entity.Core.Query.InternalTrees.Node node2 = command.CreateNode((Op)command.CreateOuterApplyOp(), node1, n);
            Var computedVar;

            System.Data.Entity.Core.Query.InternalTrees.Node varDefListNode = command.CreateVarDefListNode(command.CreateNode((Op)command.CreateVarRefOp(op2.Outputs.First)), out computedVar);
            newNode = command.CreateNode((Op)command.CreateProjectOp(computedVar), node2, varDefListNode);
            System.Data.Entity.Core.Query.InternalTrees.Node node3 = (System.Data.Entity.Core.Query.InternalTrees.Node)null;
            IEnumerator <Var> enumerator1 = scanTableOp.Table.Keys.GetEnumerator();
            IEnumerator <Var> enumerator2 = table.Keys.GetEnumerator();

            for (int index = 0; index < table.Keys.Count; ++index)
            {
                enumerator1.MoveNext();
                enumerator2.MoveNext();
                System.Data.Entity.Core.Query.InternalTrees.Node node4 = command.CreateNode((Op)command.CreateComparisonOp(OpType.EQ, false), command.CreateNode((Op)command.CreateVarRefOp(enumerator1.Current)), command.CreateNode((Op)command.CreateVarRefOp(enumerator2.Current)));
                node3 = node3 == null ? node4 : command.CreateNode((Op)command.CreateConditionalOp(OpType.And), node3, node4);
            }
            System.Data.Entity.Core.Query.InternalTrees.Node node5 = command.CreateNode((Op)command.CreateFilterOp(), n.Child0, node3);
            n.Child0 = node5;
            return(true);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Converts the reference to a TVF as following: Collect(PhysicalProject(Unnest(Func)))
        /// </summary>
        /// <param name="op">current function op</param>
        /// <param name="n">current function subtree</param>
        /// <returns>the new expression that corresponds to the TVF</returns>
        private Node VisitCollectionFunction(FunctionOp op, Node n)
        {
            PlanCompiler.Assert(TypeSemantics.IsCollectionType(op.Type), "non-TVF function?");

            Node              unnestNode  = BuildUnnest(n);
            UnnestOp          unnestOp    = unnestNode.Op as UnnestOp;
            PhysicalProjectOp projectOp   = m_command.CreatePhysicalProjectOp(unnestOp.Table.Columns[0]);
            Node              projectNode = m_command.CreateNode(projectOp, unnestNode);
            CollectOp         collectOp   = m_command.CreateCollectOp(n.Op.Type);
            Node              collectNode = m_command.CreateNode(collectOp, projectNode);

            return(collectNode);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// PhysicalProjectOp handling
        /// </summary>
        /// <param name="op"></param>
        /// <param name="n"></param>
        public override void Visit(PhysicalProjectOp op, Node n)
        {
            // Insist that we need all properties from all the outputs
            foreach (Var v in op.Outputs)
            {
                if (TypeUtils.IsStructuredType(v.Type))
                {
                    AddPropertyRefs(v, PropertyRefList.All);
                }
            }

            // simply visit the children
            VisitChildren(n);
        }
Ejemplo n.º 11
0
        internal static ProviderCommandInfo Create(Command command, System.Data.Entity.Core.Query.InternalTrees.Node node)
        {
            PhysicalProjectOp op = node.Op as PhysicalProjectOp;

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(op != null, "Expected root Op to be a physical Project");
            DbCommandTree      commandTree      = CTreeGenerator.Generate(command, node);
            DbQueryCommandTree queryCommandTree = commandTree as DbQueryCommandTree;

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(queryCommandTree != null, "null query command tree");
            CollectionType edmType = TypeHelpers.GetEdmType <CollectionType>(queryCommandTree.Query.ResultType);

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(TypeSemantics.IsRowType(edmType.TypeUsage), "command rowtype is not a record");
            ProviderCommandInfoUtils.BuildOutputVarMap(op, edmType.TypeUsage);
            return(new ProviderCommandInfo(commandTree));
        }
Ejemplo n.º 12
0
 public override System.Data.Entity.Core.Query.InternalTrees.Node Visit(
     PhysicalProjectOp op,
     System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     if (n == this.m_command.Root)
     {
         ProjectionPruner.ColumnMapVarTracker.FindVars((ColumnMap)op.ColumnMap, this.m_referencedVars);
         op.Outputs.RemoveAll(new Predicate <Var>(this.IsUnreferenced));
     }
     else
     {
         this.AddReference((IEnumerable <Var>)op.Outputs);
     }
     this.VisitChildren(n);
     return(n);
 }
Ejemplo n.º 13
0
        /// <summary>
        /// The real driver. This routine walks the tree, converts each subcommand
        /// into a CTree, and converts the columnmap into a real column map.
        /// Finally, it produces a "real" plan that can be used by the bridge execution, and
        /// returns this plan
        ///
        /// The root of the tree must be a PhysicalProjectOp. Each child of this Op
        /// represents a command to be executed, and the ColumnMap of this Op represents
        /// the eventual columnMap to be used for result assembly
        /// </summary>
        /// <param name="childCommands">CQTs for store commands</param>
        /// <param name="resultColumnMap">column map for result assembly</param>
        private void Process(out List <ProviderCommandInfo> childCommands, out ColumnMap resultColumnMap, out int columnCount)
        {
            PhysicalProjectOp projectOp = (PhysicalProjectOp)this.Command.Root.Op;

            this.m_subCommands = new List <Node>(new Node[] { this.Command.Root });
            childCommands      = new List <ProviderCommandInfo>(new ProviderCommandInfo[] {
                ProviderCommandInfoUtils.Create(
                    this.Command,
                    this.Command.Root              // input node
                    )
            });

            // Build the final column map, and count the columns we expect for it.
            resultColumnMap = BuildResultColumnMap(projectOp);

            columnCount = projectOp.Outputs.Count;
        }
Ejemplo n.º 14
0
        private void Process(
            out List <ProviderCommandInfo> childCommands,
            out ColumnMap resultColumnMap,
            out int columnCount)
        {
            PhysicalProjectOp op = (PhysicalProjectOp)this.Command.Root.Op;

            this.m_subCommands = new List <System.Data.Entity.Core.Query.InternalTrees.Node>((IEnumerable <System.Data.Entity.Core.Query.InternalTrees.Node>) new System.Data.Entity.Core.Query.InternalTrees.Node[1]
            {
                this.Command.Root
            });
            childCommands = new List <ProviderCommandInfo>((IEnumerable <ProviderCommandInfo>) new ProviderCommandInfo[1]
            {
                ProviderCommandInfoUtils.Create(this.Command, this.Command.Root)
            });
            resultColumnMap = this.BuildResultColumnMap(op);
            columnCount     = op.Outputs.Count;
        }
Ejemplo n.º 15
0
        private Dictionary <Var, KeyValuePair <int, int> > BuildVarMap()
        {
            Dictionary <Var, KeyValuePair <int, int> > dictionary = new Dictionary <Var, KeyValuePair <int, int> >();
            int key = 0;

            foreach (System.Data.Entity.Core.Query.InternalTrees.Node subCommand in this.m_subCommands)
            {
                PhysicalProjectOp op = (PhysicalProjectOp)subCommand.Op;
                int num = 0;
                foreach (Var output in (List <Var>)op.Outputs)
                {
                    KeyValuePair <int, int> keyValuePair = new KeyValuePair <int, int>(key, num);
                    dictionary[output] = keyValuePair;
                    ++num;
                }
                ++key;
            }
            return(dictionary);
        }
Ejemplo n.º 16
0
        /// <summary>
        ///     PhysicalProjectOp
        ///     Insist that all Vars in this are required
        /// </summary>
        /// <param name="op"> </param>
        /// <param name="n"> </param>
        /// <returns> </returns>
        public override Node Visit(PhysicalProjectOp op, Node n)
        {
            if (n == m_command.Root)
            {
                //
                // Walk the column map to find all the referenced vars
                //
                ColumnMapVarTracker.FindVars(op.ColumnMap, m_referencedVars);
                op.Outputs.RemoveAll(IsUnreferenced);
            }
            else
            {
                AddReference(op.Outputs);
            }
            // then visit the children
            VisitChildren(n);

            return(n);
        }
Ejemplo n.º 17
0
        internal System.Data.Entity.Core.Query.InternalTrees.Node GetInternalTree(
            Command targetIqtCommand,
            IList <System.Data.Entity.Core.Query.InternalTrees.Node> targetIqtArguments)
        {
            if (this.m_internalTreeNode == null)
            {
                DiscriminatorMap discriminatorMap;
                Command          command = ITreeGenerator.Generate(this.GenerateFunctionView(out discriminatorMap), discriminatorMap);
                System.Data.Entity.Core.Query.InternalTrees.Node root = command.Root;
                System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(root.Op.OpType == OpType.PhysicalProject, "Expected a physical projectOp at the root of the tree - found " + (object)root.Op.OpType);
                PhysicalProjectOp op = (PhysicalProjectOp)root.Op;
                System.Data.Entity.Core.Query.InternalTrees.Node child0 = root.Child0;
                command.DisableVarVecEnumCaching();
                System.Data.Entity.Core.Query.InternalTrees.Node relOpNode = child0;
                Var computedVar = op.Outputs[0];
                if (!Command.EqualTypes(op.ColumnMap.Type, this.FunctionImport.ReturnParameter.TypeUsage))
                {
                    TypeUsage typeUsage = ((CollectionType)this.FunctionImport.ReturnParameter.TypeUsage.EdmType).TypeUsage;
                    System.Data.Entity.Core.Query.InternalTrees.Node node1          = command.CreateNode((Op)command.CreateVarRefOp(computedVar));
                    System.Data.Entity.Core.Query.InternalTrees.Node node2          = command.CreateNode((Op)command.CreateSoftCastOp(typeUsage), node1);
                    System.Data.Entity.Core.Query.InternalTrees.Node varDefListNode = command.CreateVarDefListNode(node2, out computedVar);
                    ProjectOp projectOp = command.CreateProjectOp(computedVar);
                    relOpNode = command.CreateNode((Op)projectOp, relOpNode, varDefListNode);
                }
                this.m_internalTreeNode = command.BuildCollect(relOpNode, computedVar);
            }
            Dictionary <string, System.Data.Entity.Core.Query.InternalTrees.Node> viewArguments = new Dictionary <string, System.Data.Entity.Core.Query.InternalTrees.Node>(this.m_commandParameters.Length);

            for (int index = 0; index < this.m_commandParameters.Length; ++index)
            {
                DbParameterReferenceExpression commandParameter       = this.m_commandParameters[index];
                System.Data.Entity.Core.Query.InternalTrees.Node node = targetIqtArguments[index];
                if (TypeSemantics.IsEnumerationType(node.Op.Type))
                {
                    node = targetIqtCommand.CreateNode((Op)targetIqtCommand.CreateSoftCastOp(TypeHelpers.CreateEnumUnderlyingTypeUsage(node.Op.Type)), node);
                }
                viewArguments.Add(commandParameter.ParameterName, node);
            }
            return(FunctionImportMappingComposable.FunctionViewOpCopier.Copy(targetIqtCommand, this.m_internalTreeNode, viewArguments));
        }
Ejemplo n.º 18
0
        /// <summary>
        /// For each subcommand, build up a "location-map" for each top-level var that
        /// is projected out. This location map will ultimately be used to convert VarRefColumnMap
        /// into SimpleColumnMap
        /// </summary>
        private Dictionary <Var, KeyValuePair <int, int> > BuildVarMap()
        {
            Dictionary <Var, KeyValuePair <int, int> > varMap =
                new Dictionary <Var, KeyValuePair <int, int> >();

            int commandId = 0;

            foreach (Node subCommand in m_subCommands)
            {
                PhysicalProjectOp projectOp = (PhysicalProjectOp)subCommand.Op;

                int columnPos = 0;
                foreach (Var v in projectOp.Outputs)
                {
                    KeyValuePair <int, int> varLocation = new KeyValuePair <int, int>(commandId, columnPos);
                    varMap[v] = varLocation;
                    columnPos++;
                }

                commandId++;
            }
            return(varMap);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a ProviderCommandInfo for the given node.
        /// This method should be called when the keys, foreign keys and sort keys are known ahead of time.
        /// Typically it is used when the original command is factored into multiple commands.
        /// </summary>
        /// <param name="command">The owning command, used for creating VarVecs, etc</param>
        /// <param name="node">The root of the sub-command for which a ProviderCommandInfo should be generated</param>
        /// <param name="children">A list of ProviderCommandInfos that were created for the child sub-commands.</param>
        /// <returns>The resulting ProviderCommandInfo</returns>
        internal static ProviderCommandInfo Create(
            Command command,
            Node node,
            List <ProviderCommandInfo> children)
        {
            PhysicalProjectOp projectOp = node.Op as PhysicalProjectOp;

            PlanCompiler.Assert(projectOp != null, "Expected root Op to be a physical Project");

            // build up the CQT
            DbCommandTree      ctree  = CTreeGenerator.Generate(command, node);
            DbQueryCommandTree cqtree = ctree as DbQueryCommandTree;

            PlanCompiler.Assert(cqtree != null, "null query command tree");

            // Get the rowtype for the result cqt
            md.CollectionType collType = TypeHelpers.GetEdmType <md.CollectionType>(cqtree.Query.ResultType);
            PlanCompiler.Assert(md.TypeSemantics.IsRowType(collType.TypeUsage), "command rowtype is not a record");

            // Build up a mapping from Vars to the corresponding output property/column
            Dictionary <Var, md.EdmProperty> outputVarMap = BuildOutputVarMap(projectOp, collType.TypeUsage);

            return(new ProviderCommandInfo(ctree, children));
        }
        private static Dictionary<Var, md.EdmProperty> BuildOutputVarMap(PhysicalProjectOp projectOp, md.TypeUsage outputType)
        {
            var outputVarMap = new Dictionary<Var, md.EdmProperty>();

            PlanCompiler.Assert(md.TypeSemantics.IsRowType(outputType), "PhysicalProjectOp result type is not a RowType?");

            IEnumerator<md.EdmProperty> propertyEnumerator = TypeHelpers.GetEdmType<md.RowType>(outputType).Properties.GetEnumerator();
            IEnumerator<Var> varEnumerator = projectOp.Outputs.GetEnumerator();
            while (true)
            {
                var foundProp = propertyEnumerator.MoveNext();
                var foundVar = varEnumerator.MoveNext();
                if (foundProp != foundVar)
                {
                    throw EntityUtil.InternalError(EntityUtil.InternalErrorCode.ColumnCountMismatch, 1, null);
                }
                if (!foundProp)
                {
                    break;
                }
                outputVarMap[varEnumerator.Current] = propertyEnumerator.Current;
            }
            return outputVarMap;
        }
Ejemplo n.º 21
0
        public override Node Visit(PhysicalProjectOp op, Node n)
        {
            // cannot be multi-input (not at this point)
            PlanCompiler.Assert(n.Children.Count == 1, "multiple inputs to physicalProject?");

            // First visit my children
            VisitChildren(n);
            m_varRemapper.RemapNode(n);

            // Wait until we're processing the root physicalProjectNode to convert the nestOp
            // to sort/union all; it's much easier to unnest them if we don't monkey with them
            // until then.
            //
            // Also, even if we're the root physicalProjectNode and the children aren't NestOps, 
            // then there's nothing further to do.
            if (n != Command.Root
                || !IsNestOpNode(n.Child0))
            {
                return n;
            }

#if DEBUG
            var input = Dump.ToXml(n);
#endif
            //DEBUG

            var nestNode = n.Child0;

            // OK, we're now guaranteed to be processing a root physicalProjectNode with at
            // least one MultiStreamNestOp as it's input.  First step is to convert that into
            // a single SingleStreamNestOp.
            //
            // NOTE: if we ever wanted to support MARS, we would probably avoid the conversion
            //       to SingleStreamNest here, and do something to optimize this a bit 
            //       differently for MARS.  But that's a future feature.
            var varRefReplacementMap = new Dictionary<Var, ColumnMap>();

            //Dev10_579146: The parameters that are output should be retained.
            var outputVars = Command.CreateVarList(op.Outputs.Where(v => v.VarType == VarType.Parameter));
            SimpleColumnMap[] keyColumnMaps;

            nestNode = ConvertToSingleStreamNest(nestNode, varRefReplacementMap, outputVars, out keyColumnMaps);
            var ssnOp = (SingleStreamNestOp)nestNode.Op;

            // Build up the sort node (if necessary).
            var sortNode = BuildSortForNestElimination(ssnOp, nestNode);

            // Create a new column map using the columnMapPatcher that was updated by the
            // conversion to SingleStreamNest process.
            var newProjectColumnMap =
                (SimpleCollectionColumnMap)ColumnMapTranslator.Translate(((PhysicalProjectOp)n.Op).ColumnMap, varRefReplacementMap);
            newProjectColumnMap = new SimpleCollectionColumnMap(
                newProjectColumnMap.Type, newProjectColumnMap.Name, newProjectColumnMap.Element, keyColumnMaps, null);

            // Ok, build the new PhysicalProjectOp, slap the sortNode as its input
            // and we're all done.
            n.Op = Command.CreatePhysicalProjectOp(outputVars, newProjectColumnMap);
            n.Child0 = sortNode;

#if DEBUG
            var size = input.Length; // GC.KeepAlive makes FxCop Grumpy.
            var output = Dump.ToXml(n);
#endif
            //DEBUG

            return n;
        }
        /// <summary>
        ///     PhysicalProjectOp
        /// </summary>
        /// <param name="op"> </param>
        /// <param name="n"> </param>
        /// <returns> </returns>
        public override Node Visit(PhysicalProjectOp op, Node n)
        {
            // visit my children
            VisitChildren(n);

            // flatten out the varset
            var newVarList = FlattenVarList(op.Outputs);
            // reflect changes into my column map
            var newColumnMap = ExpandColumnMap(op.ColumnMap);
            var newOp = m_command.CreatePhysicalProjectOp(newVarList, newColumnMap);
            n.Op = newOp;

            return n;
        }
Ejemplo n.º 23
0
 public override void Visit(PhysicalProjectOp op, Node n)
 {
     VisitPhysicalOpDefault(op, n);
     Assert(n.Children.Count >= 1, "PhysicalProjectOp needs at least 1 arg: found {0}", n.Children.Count);
     foreach (var chi in n.Children)
     {
         AssertRelOpOrPhysicalOp(chi.Op);
     }
 }
Ejemplo n.º 24
0
        // <summary>
        // Copies a PhysicalProjectOp
        // </summary>
        public override Node Visit(PhysicalProjectOp op, Node n)
        {
            // Visit the Node's children and map their Vars
            var children = ProcessChildren(n);

            // Copy the ProjectOp's VarSet
            var newVarList = Copy(op.Outputs);

            var newColumnMap = Copy(op.ColumnMap) as SimpleCollectionColumnMap;
            Debug.Assert(newColumnMap != null, "Coping of a physical project's columnMap did not return a SimpleCollectionColumnMap");
            // Create a new ProjectOp based on the copied VarSet
            var newProject = m_destCmd.CreatePhysicalProjectOp(newVarList, newColumnMap);

            // Return a new Node that references the copied ProjectOp and has the copied child Nodes as its children
            return m_destCmd.CreateNode(newProject, children);
        }
 /// <summary>
 ///     Visitor pattern method for PhysicalProjectOp
 /// </summary>
 /// <param name="op"> The op being visited </param>
 /// <param name="n"> The Node that references the Op </param>
 public virtual void Visit(PhysicalProjectOp op, Node n)
 {
     VisitPhysicalOpDefault(op, n);
 }
Ejemplo n.º 26
0
        /// <summary>
        /// If the Subtree rooted at the collect is of the following structure:
        ///
        /// PhysicalProject(outputVar)
        /// |
        /// Project(s)
        /// |
        /// Unnest
        ///
        /// where the unnest is over the group aggregate var and the output var
        /// is either a reference to the group aggregate var or to a constant, it returns the
        /// translation of the ouput var.
        /// </summary>
        /// <param name="n"></param>
        /// <returns></returns>
        private Node VisitCollect(Node n)
        {
            //Make sure the only children are projects over unnest
            Node currentNode = n.Child0;
            Dictionary <Var, Node> constantDefinitions = new Dictionary <Var, Node>();

            while (currentNode.Child0.Op.OpType == OpType.Project)
            {
                currentNode = currentNode.Child0;
                //Visit the VarDefListOp child
                if (VisitDefault(currentNode.Child1) == null)
                {
                    return(null);
                }
                foreach (Node definitionNode in currentNode.Child1.Children)
                {
                    if (IsConstant(definitionNode.Child0))
                    {
                        constantDefinitions.Add(((VarDefOp)definitionNode.Op).Var, definitionNode.Child0);
                    }
                }
            }

            if (currentNode.Child0.Op.OpType != OpType.Unnest)
            {
                return(null);
            }

            // Handle the unnest
            UnnestOp unnestOp = (UnnestOp)currentNode.Child0.Op;
            GroupAggregateVarRefInfo groupAggregateVarRefInfo;

            if (_groupAggregateVarInfoManager.TryGetReferencedGroupAggregateVarInfo(unnestOp.Var, out groupAggregateVarRefInfo))
            {
                if (_targetGroupAggregateVarInfo == null)
                {
                    _targetGroupAggregateVarInfo = groupAggregateVarRefInfo.GroupAggregateVarInfo;
                }
                else if (_targetGroupAggregateVarInfo != groupAggregateVarRefInfo.GroupAggregateVarInfo)
                {
                    return(null);
                }
                if (!_isUnnested)
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }

            PhysicalProjectOp physicalProjectOp = (PhysicalProjectOp)n.Child0.Op;

            PlanCompiler.Assert(physicalProjectOp.Outputs.Count == 1, "PhysicalProject should only have one output at this stage");
            Var outputVar = physicalProjectOp.Outputs[0];

            Node computationTemplate = TranslateOverGroupAggregateVar(outputVar, null);

            if (computationTemplate != null)
            {
                _isUnnested = true;
                return(computationTemplate);
            }

            Node constantDefinitionNode;

            if (constantDefinitions.TryGetValue(outputVar, out constantDefinitionNode))
            {
                _isUnnested = true;
                return(constantDefinitionNode);
            }
            return(null);
        }
Ejemplo n.º 27
0
        /// <summary>
        ///     PhysicalProjectOp handling
        /// </summary>
        /// <param name="op"> </param>
        /// <param name="n"> </param>
        public override void Visit(PhysicalProjectOp op, Node n)
        {
            // Insist that we need all properties from all the outputs
            foreach (var v in op.Outputs)
            {
                if (TypeUtils.IsStructuredType(v.Type))
                {
                    AddPropertyRefs(v, PropertyRefList.All);
                }
            }

            // simply visit the children
            VisitChildren(n);
        }
Ejemplo n.º 28
0
        private System.Data.Entity.Core.Query.InternalTrees.Node VisitCollect(System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            System.Data.Entity.Core.Query.InternalTrees.Node child0 = n.Child0;
            Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node> dictionary = new Dictionary <Var, System.Data.Entity.Core.Query.InternalTrees.Node>();

            while (child0.Child0.Op.OpType == OpType.Project)
            {
                child0 = child0.Child0;
                if (this.VisitDefault(child0.Child1) == null)
                {
                    return((System.Data.Entity.Core.Query.InternalTrees.Node)null);
                }
                foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in child0.Child1.Children)
                {
                    if (GroupAggregateVarComputationTranslator.IsConstant(child.Child0))
                    {
                        dictionary.Add(((VarDefOp)child.Op).Var, child.Child0);
                    }
                }
            }
            if (child0.Child0.Op.OpType != OpType.Unnest)
            {
                return((System.Data.Entity.Core.Query.InternalTrees.Node)null);
            }
            GroupAggregateVarRefInfo groupAggregateVarRefInfo;

            if (!this._groupAggregateVarInfoManager.TryGetReferencedGroupAggregateVarInfo(((UnnestOp)child0.Child0.Op).Var, out groupAggregateVarRefInfo))
            {
                return((System.Data.Entity.Core.Query.InternalTrees.Node)null);
            }
            if (this._targetGroupAggregateVarInfo == null)
            {
                this._targetGroupAggregateVarInfo = groupAggregateVarRefInfo.GroupAggregateVarInfo;
            }
            else if (this._targetGroupAggregateVarInfo != groupAggregateVarRefInfo.GroupAggregateVarInfo)
            {
                return((System.Data.Entity.Core.Query.InternalTrees.Node)null);
            }
            if (!this._isUnnested)
            {
                return((System.Data.Entity.Core.Query.InternalTrees.Node)null);
            }
            PhysicalProjectOp op = (PhysicalProjectOp)n.Child0.Op;

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(op.Outputs.Count == 1, "Physical project should only have one output at this stage");
            Var output = op.Outputs[0];

            System.Data.Entity.Core.Query.InternalTrees.Node node1 = this.TranslateOverGroupAggregateVar(output, (EdmMember)null);
            if (node1 != null)
            {
                this._isUnnested = true;
                return(node1);
            }
            System.Data.Entity.Core.Query.InternalTrees.Node node2;
            if (!dictionary.TryGetValue(output, out node2))
            {
                return((System.Data.Entity.Core.Query.InternalTrees.Node)null);
            }
            this._isUnnested = true;
            return(node2);
        }
Ejemplo n.º 29
0
        private ColumnMap BuildResultColumnMap(PhysicalProjectOp projectOp)
        {
            Dictionary <Var, KeyValuePair <int, int> > varToCommandColumnMap = this.BuildVarMap();

            return(ColumnMapTranslator.Translate((ColumnMap)projectOp.ColumnMap, varToCommandColumnMap));
        }
Ejemplo n.º 30
0
        public override void Visit(PhysicalProjectOp op, Node n)
        {
            VisitPhysicalOpDefault(op, n);
            Map(op.Outputs);

            SimpleCollectionColumnMap newColumnMap = (SimpleCollectionColumnMap)ColumnMapTranslator.Translate(op.ColumnMap, m_varMap);
            n.Op = m_command.CreatePhysicalProjectOp(op.Outputs, newColumnMap);
        }