Example #1
0
        private void VisitPropertyOp(Op op, System.Data.Entity.Core.Query.InternalTrees.Node n, PropertyRef propertyRef)
        {
            PropertyRefList propertyRefs = new PropertyRefList();

            if (!TypeUtils.IsStructuredType(op.Type))
            {
                propertyRefs.Add(propertyRef);
            }
            else
            {
                PropertyRefList propertyRefList = this.GetPropertyRefList(n);
                if (propertyRefList.AllProperties)
                {
                    propertyRefs = propertyRefList;
                }
                else
                {
                    foreach (PropertyRef property in propertyRefList.Properties)
                    {
                        propertyRefs.Add(property.CreateNestedPropertyRef(propertyRef));
                    }
                }
            }
            this.AddPropertyRefs(n.Child0, propertyRefs);
            this.VisitChildren(n);
        }
Example #2
0
        private static PropertyRefList GetIdentityProperties(EntityType type)
        {
            PropertyRefList keyProperties = PropertyPushdownHelper.GetKeyProperties(type);

            keyProperties.Add((PropertyRef)EntitySetIdPropertyRef.Instance);
            return(keyProperties);
        }
Example #3
0
 protected override void VisitSetOp(SetOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
 {
     foreach (Dictionary <Var, Var> var in op.VarMap)
     {
         foreach (KeyValuePair <Var, Var> keyValuePair in var)
         {
             if (TypeUtils.IsStructuredType(keyValuePair.Key.Type))
             {
                 PropertyRefList propertyRefList = this.GetPropertyRefList(keyValuePair.Key);
                 PropertyRefList propertyRefs;
                 if (op.OpType == OpType.Intersect || op.OpType == OpType.Except)
                 {
                     propertyRefs = PropertyRefList.All;
                     this.AddPropertyRefs(keyValuePair.Key, propertyRefs);
                 }
                 else
                 {
                     propertyRefs = propertyRefList.Clone();
                 }
                 this.AddPropertyRefs(keyValuePair.Value, propertyRefs);
             }
         }
     }
     this.VisitChildren(n);
 }
Example #4
0
        /// <summary>
        ///     SoftCastOp:
        ///     If the input is
        ///     Ref - ask for all properties
        ///     Entity, ComplexType - ask for the same properties I've been asked for
        ///     Record - ask for all properties (Note: This should be more optimized in the future
        ///     since we can actually "remap" the properties)
        /// </summary>
        /// <param name="op"> </param>
        /// <param name="n"> </param>
        public override void Visit(SoftCastOp op, Node n)
        {
            PropertyRefList childProps = null;

            if (md.TypeSemantics.IsReferenceType(op.Type))
            {
                childProps = PropertyRefList.All;
            }
            else if (md.TypeSemantics.IsNominalType(op.Type))
            {
                var myProps = m_nodePropertyRefMap[n];
                childProps = myProps.Clone();
            }
            else if (md.TypeSemantics.IsRowType(op.Type))
            {
                //
                // Note: We should do a better job here (by translating
                // our PropertyRefs to the equivalent property refs on the child
                //
                childProps = PropertyRefList.All;
            }

            if (childProps != null)
            {
                AddPropertyRefs(n.Child0, childProps);
            }
            VisitChildren(n);
        }
Example #5
0
        public override void Visit(TreatOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            PropertyRefList propertyRefs = this.GetPropertyRefList(n).Clone();

            propertyRefs.Add((PropertyRef)TypeIdPropertyRef.Instance);
            this.AddPropertyRefs(n.Child0, propertyRefs);
            this.VisitChildren(n);
        }
Example #6
0
 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);
 }
Example #7
0
        public override void Visit(ScanViewOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(op.Table.Columns.Count == 1, "ScanViewOp with multiple columns?");
            PropertyRefList propertyRefList = this.GetPropertyRefList(op.Table.Columns[0]);
            Var             singletonVar    = NominalTypeEliminator.GetSingletonVar(n.Child0);

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(singletonVar != null, "cannot determine single Var from ScanViewOp's input");
            this.AddPropertyRefs(singletonVar, propertyRefList.Clone());
            this.VisitChildren(n);
        }
Example #8
0
        public override void Visit(VarRefOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            if (!TypeUtils.IsStructuredType(op.Var.Type))
            {
                return;
            }
            PropertyRefList propertyRefList = this.GetPropertyRefList(n);

            this.AddPropertyRefs(op.Var, propertyRefList);
        }
Example #9
0
        public override void Visit(GetEntityRefOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            ScalarOp op1 = n.Child0.Op as ScalarOp;

            System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(op1 != null, "input to GetEntityRefOp is not a ScalarOp?");
            PropertyRefList identityProperties = PropertyPushdownHelper.GetIdentityProperties(TypeHelpers.GetEdmType <EntityType>(op1.Type));

            this.AddPropertyRefs(n.Child0, identityProperties);
            this.VisitNode(n.Child0);
        }
Example #10
0
        internal PropertyRefList Clone()
        {
            PropertyRefList propertyRefList = new PropertyRefList(this.m_allProperties);

            foreach (PropertyRef key in this.m_propertyReferences.Keys)
            {
                propertyRefList.Add(key);
            }
            return(propertyRefList);
        }
        // <summary>
        // Create a clone of myself
        // </summary>
        // <returns> a clone of myself </returns>
        internal PropertyRefList Clone()
        {
            var newProps = new PropertyRefList(m_allProperties);

            foreach (var p in m_propertyReferences.Keys)
            {
                newProps.Add(p);
            }
            return(newProps);
        }
Example #12
0
        /// <summary>
        ///     IsOfOp handling
        ///     Simply requests the "typeid" property from
        ///     the input. No other property is required
        /// </summary>
        /// <param name="op"> IsOf op </param>
        /// <param name="n"> Node to visit </param>
        public override void Visit(IsOfOp op, Node n)
        {
            // The only property I need from my child is the typeid property;
            var childProps = new PropertyRefList();

            childProps.Add(TypeIdPropertyRef.Instance);
            AddPropertyRefs(n.Child0, childProps);

            VisitChildren(n);
        }
Example #13
0
        /// <summary>
        ///     Get the list of propertyrefs for a node. If none exists, create an
        ///     empty structure and store it in the map
        /// </summary>
        /// <param name="node"> Specific node </param>
        /// <returns> List of properties expected from this node </returns>
        private PropertyRefList GetPropertyRefList(Node node)
        {
            PropertyRefList propRefs;

            if (!m_nodePropertyRefMap.TryGetValue(node, out propRefs))
            {
                propRefs = new PropertyRefList();
                m_nodePropertyRefMap[node] = propRefs;
            }
            return(propRefs);
        }
Example #14
0
        /// <summary>
        ///     Get the list of desired properties for a Var
        /// </summary>
        /// <param name="v"> the var </param>
        /// <returns> List of desired properties </returns>
        private PropertyRefList GetPropertyRefList(Var v)
        {
            PropertyRefList propRefs;

            if (!m_varPropertyRefMap.TryGetValue(v, out propRefs))
            {
                propRefs = new PropertyRefList();
                m_varPropertyRefMap[v] = propRefs;
            }
            return(propRefs);
        }
Example #15
0
 internal void Append(PropertyRefList propertyRefs)
 {
     if (this.m_allProperties)
     {
         return;
     }
     foreach (PropertyRef key in propertyRefs.m_propertyReferences.Keys)
     {
         this.Add(key);
     }
 }
 // <summary>
 // Append an existing list of property references to myself
 // </summary>
 // <param name="propertyRefs"> list of property references </param>
 internal void Append(PropertyRefList propertyRefs)
 {
     if (m_allProperties)
     {
         return;
     }
     foreach (var p in propertyRefs.m_propertyReferences.Keys)
     {
         Add(p);
     }
 }
 // <summary>
 // Append an existing list of property references to myself
 // </summary>
 // <param name="propertyRefs"> list of property references </param>
 internal void Append(PropertyRefList propertyRefs)
 {
     if (m_allProperties)
     {
         return;
     }
     foreach (var p in propertyRefs.m_propertyReferences.Keys)
     {
         Add(p);
     }
 }
Example #18
0
        private PropertyRefList GetPropertyRefList(Var v)
        {
            PropertyRefList propertyRefList;

            if (!this.m_varPropertyRefMap.TryGetValue(v, out propertyRefList))
            {
                propertyRefList             = new PropertyRefList();
                this.m_varPropertyRefMap[v] = propertyRefList;
            }
            return(propertyRefList);
        }
Example #19
0
        private PropertyRefList GetPropertyRefList(System.Data.Entity.Core.Query.InternalTrees.Node node)
        {
            PropertyRefList propertyRefList;

            if (!this.m_nodePropertyRefMap.TryGetValue(node, out propertyRefList))
            {
                propertyRefList = new PropertyRefList();
                this.m_nodePropertyRefMap[node] = propertyRefList;
            }
            return(propertyRefList);
        }
Example #20
0
        public override void Visit(CaseOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            PropertyRefList propertyRefList = this.GetPropertyRefList(n);

            for (int index = 1; index < n.Children.Count - 1; index += 2)
            {
                PropertyRefList propertyRefs = propertyRefList.Clone();
                this.AddPropertyRefs(n.Children[index], propertyRefs);
            }
            this.AddPropertyRefs(n.Children[n.Children.Count - 1], propertyRefList.Clone());
            this.VisitChildren(n);
        }
Example #21
0
        private static PropertyRefList GetKeyProperties(EntityType entityType)
        {
            PropertyRefList propertyRefList = new PropertyRefList();

            foreach (EdmMember keyMember in entityType.KeyMembers)
            {
                EdmProperty edmProperty = keyMember as EdmProperty;
                System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(edmProperty != null, "EntityType had non-EdmProperty key member?");
                SimplePropertyRef simplePropertyRef = new SimplePropertyRef((EdmMember)edmProperty);
                propertyRefList.Add((PropertyRef)simplePropertyRef);
            }
            return(propertyRefList);
        }
Example #22
0
        private static PropertyRefList GetKeyProperties(md.EntityType entityType)
        {
            var desiredProperties = new PropertyRefList();

            foreach (var p in entityType.KeyMembers)
            {
                var edmP = p as md.EdmProperty;
                PlanCompiler.Assert(edmP != null, "EntityType had non-EdmProperty key member?");
                var pRef = new SimplePropertyRef(edmP);
                desiredProperties.Add(pRef);
            }
            return(desiredProperties);
        }
Example #23
0
        /// <summary>
        ///     Common handler for RelPropertyOp and PropertyOp.
        ///     Simply pushes down the desired set of properties to the child
        /// </summary>
        /// <param name="op"> the *propertyOp </param>
        /// <param name="n"> node tree corresponding to the Op </param>
        /// <param name="propertyRef"> the property reference </param>
        private void VisitPropertyOp(Op op, Node n, PropertyRef propertyRef)
        {
            var cdProps = new PropertyRefList();

            if (!TypeUtils.IsStructuredType(op.Type))
            {
                cdProps.Add(propertyRef);
            }
            else
            {
                // Get the list of properties my parent expects from me.
                var pdProps = GetPropertyRefList(n);

                // Ask my child (which is really my container type) for each of these
                // properties

                // If I've been asked for all my properties, then get the
                // corresponding flat list of properties from my children.
                // For now, however, simply ask for all properties in this case
                // What we really need to do is to get the "flattened" list of
                // properties from the input, and prepend each of these with
                // our property name. We don't have that info available, so
                // I'm taking the easier route.
                if (pdProps.AllProperties)
                {
                    cdProps = pdProps;
                }
                else
                {
                    foreach (var p in pdProps.Properties)
                    {
                        cdProps.Add(p.CreateNestedPropertyRef(propertyRef));
                    }
                }
            }

            // push down my expectations
            AddPropertyRefs(n.Child0, cdProps);
            VisitChildren(n);
        }
Example #24
0
        public override void Visit(SoftCastOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            PropertyRefList propertyRefs = (PropertyRefList)null;

            if (TypeSemantics.IsReferenceType(op.Type))
            {
                propertyRefs = PropertyRefList.All;
            }
            else if (TypeSemantics.IsNominalType(op.Type))
            {
                propertyRefs = this.m_nodePropertyRefMap[n].Clone();
            }
            else if (TypeSemantics.IsRowType(op.Type))
            {
                propertyRefs = PropertyRefList.All;
            }
            if (propertyRefs != null)
            {
                this.AddPropertyRefs(n.Child0, propertyRefs);
            }
            this.VisitChildren(n);
        }
Example #25
0
        public override void Visit(ComparisonOp op, System.Data.Entity.Core.Query.InternalTrees.Node n)
        {
            TypeUsage type = (n.Child0.Op as ScalarOp).Type;

            if (!TypeUtils.IsStructuredType(type))
            {
                this.VisitChildren(n);
            }
            else if (TypeSemantics.IsRowType(type) || TypeSemantics.IsReferenceType(type))
            {
                this.VisitDefault(n);
            }
            else
            {
                System.Data.Entity.Core.Query.PlanCompiler.PlanCompiler.Assert(TypeSemantics.IsEntityType(type), "unexpected childOpType?");
                PropertyRefList identityProperties = PropertyPushdownHelper.GetIdentityProperties(TypeHelpers.GetEdmType <EntityType>(type));
                foreach (System.Data.Entity.Core.Query.InternalTrees.Node child in n.Children)
                {
                    this.AddPropertyRefs(child, identityProperties);
                }
                this.VisitChildren(n);
            }
        }
        /// <summary>
        ///     Flattens a CaseOp - Specifically, if the CaseOp returns a structuredtype,
        ///     then the CaseOp is broken up so that we build up a "flat" record constructor
        ///     for that structured type, with each argument to the record constructor being
        ///     a (scalar) CaseOp.  For example:
        ///     Case when b1 then e1 else e2 end
        ///     gets translated into:
        ///     RecordOp(case when b1 then e1.a else e2.a end,
        ///     case when b1 then e1.b else e2.b end,
        ///     ...)
        ///     The property extraction is optimized by producing only those properties
        ///     that have actually been requested.
        /// </summary>
        /// <param name="n"> Node corresponding to the CaseOp </param>
        /// <param name="typeInfo"> Information about the type </param>
        /// <param name="desiredProperties"> Set of properties desired </param>
        /// <returns> </returns>
        private Node FlattenCaseOp(Node n, TypeInfo typeInfo, PropertyRefList desiredProperties)
        {
            // Build up a type constructor - with only as many fields filled in 
            // as are desired. 
            var fieldTypes = new List<md.EdmProperty>();
            var fieldValues = new List<Node>();

            foreach (var pref in typeInfo.PropertyRefList)
            {
                // Is this property desired later?
                if (!desiredProperties.Contains(pref))
                {
                    continue;
                }
                var property = typeInfo.GetNewProperty(pref);

                // Build up an accessor for this property across each when/then clause
                var caseChildren = new List<Node>();
                for (var i = 0; i < n.Children.Count - 1;)
                {
                    var whenNode = Copy(n.Children[i]);
                    caseChildren.Add(whenNode);
                    i++;

                    var propNode = BuildAccessorWithNulls(n.Children[i], property);
                    caseChildren.Add(propNode);
                    i++;
                }
                var elseNode = BuildAccessorWithNulls(n.Children[n.Children.Count - 1], property);
                caseChildren.Add(elseNode);

                var caseNode = m_command.CreateNode(m_command.CreateCaseOp(md.Helper.GetModelTypeUsage(property)), caseChildren);

                fieldTypes.Add(property);
                fieldValues.Add(caseNode);
            }

            var newRec = m_command.CreateNewRecordOp(typeInfo.FlattenedTypeUsage, fieldTypes);
            return m_command.CreateNode(newRec, fieldValues);
        }
 // <summary>
 // Create a clone of myself
 // </summary>
 // <returns> a clone of myself </returns>
 internal PropertyRefList Clone()
 {
     var newProps = new PropertyRefList(m_allProperties);
     foreach (var p in m_propertyReferences.Keys)
     {
         newProps.Add(p);
     }
     return newProps;
 }
        /// <summary>
        ///     IsOfOp handling
        /// 
        ///     Simply requests the "typeid" property from
        ///     the input. No other property is required
        /// </summary>
        /// <param name="op"> IsOf op </param>
        /// <param name="n"> Node to visit </param>
        public override void Visit(IsOfOp op, Node n)
        {
            // The only property I need from my child is the typeid property;
            var childProps = new PropertyRefList();
            childProps.Add(TypeIdPropertyRef.Instance);
            AddPropertyRefs(n.Child0, childProps);

            VisitChildren(n);
        }
        /// <summary>
        ///     Common handler for RelPropertyOp and PropertyOp. 
        ///     Simply pushes down the desired set of properties to the child
        /// </summary>
        /// <param name="op"> the *propertyOp </param>
        /// <param name="n"> node tree corresponding to the Op </param>
        /// <param name="propertyRef"> the property reference </param>
        private void VisitPropertyOp(Op op, Node n, PropertyRef propertyRef)
        {
            var cdProps = new PropertyRefList();
            if (!TypeUtils.IsStructuredType(op.Type))
            {
                cdProps.Add(propertyRef);
            }
            else
            {
                // Get the list of properties my parent expects from me. 
                var pdProps = GetPropertyRefList(n);

                // Ask my child (which is really my container type) for each of these 
                // properties

                // If I've been asked for all my properties, then get the 
                // corresponding flat list of properties from my children.
                // For now, however, simply ask for all properties in this case
                // What we really need to do is to get the "flattened" list of
                // properties from the input, and prepend each of these with
                // our property name. We don't have that info available, so 
                // I'm taking the easier route.
                if (pdProps.AllProperties)
                {
                    cdProps = pdProps;
                }
                else
                {
                    foreach (var p in pdProps.Properties)
                    {
                        cdProps.Add(p.CreateNestedPropertyRef(propertyRef));
                    }
                }
            }

            // push down my expectations
            AddPropertyRefs(n.Child0, cdProps);
            VisitChildren(n);
        }
 /// <summary>
 ///     Add a new set of properties to a Var
 /// </summary>
 /// <param name="v"> the var </param>
 /// <param name="propertyRefs"> desired properties </param>
 private void AddPropertyRefs(Var v, PropertyRefList propertyRefs)
 {
     var currentRefs = GetPropertyRefList(v);
     currentRefs.Append(propertyRefs);
 }
 private static PropertyRefList GetKeyProperties(md.EntityType entityType)
 {
     var desiredProperties = new PropertyRefList();
     foreach (var p in entityType.KeyMembers)
     {
         var edmP = p as md.EdmProperty;
         PlanCompiler.Assert(edmP != null, "EntityType had non-EdmProperty key member?");
         var pRef = new SimplePropertyRef(edmP);
         desiredProperties.Add(pRef);
     }
     return desiredProperties;
 }
 /// <summary>
 ///     Add a list of property references for this node
 /// </summary>
 /// <param name="node"> the node </param>
 /// <param name="propertyRefs"> list of property references </param>
 private void AddPropertyRefs(Node node, PropertyRefList propertyRefs)
 {
     var refs = GetPropertyRefList(node);
     refs.Append(propertyRefs);
 }
 /// <summary>
 ///     Get the list of desired properties for a Var
 /// </summary>
 /// <param name="v"> the var </param>
 /// <returns> List of desired properties </returns>
 private PropertyRefList GetPropertyRefList(Var v)
 {
     PropertyRefList propRefs;
     if (!m_varPropertyRefMap.TryGetValue(v, out propRefs))
     {
         propRefs = new PropertyRefList();
         m_varPropertyRefMap[v] = propRefs;
     }
     return propRefs;
 }
 /// <summary>
 ///     Get the list of propertyrefs for a node. If none exists, create an 
 ///     empty structure and store it in the map
 /// </summary>
 /// <param name="node"> Specific node </param>
 /// <returns> List of properties expected from this node </returns>
 private PropertyRefList GetPropertyRefList(Node node)
 {
     PropertyRefList propRefs;
     if (!m_nodePropertyRefMap.TryGetValue(node, out propRefs))
     {
         propRefs = new PropertyRefList();
         m_nodePropertyRefMap[node] = propRefs;
     }
     return propRefs;
 }
Example #35
0
 private void AddPropertyRefs(System.Data.Entity.Core.Query.InternalTrees.Node node, PropertyRefList propertyRefs)
 {
     this.GetPropertyRefList(node).Append(propertyRefs);
 }
Example #36
0
 private void AddPropertyRefs(Var v, PropertyRefList propertyRefs)
 {
     this.GetPropertyRefList(v).Append(propertyRefs);
 }
Example #37
0
        /// <summary>
        ///     Add a list of property references for this node
        /// </summary>
        /// <param name="node"> the node </param>
        /// <param name="propertyRefs"> list of property references </param>
        private void AddPropertyRefs(Node node, PropertyRefList propertyRefs)
        {
            var refs = GetPropertyRefList(node);

            refs.Append(propertyRefs);
        }
Example #38
0
        /// <summary>
        ///     Add a new set of properties to a Var
        /// </summary>
        /// <param name="v"> the var </param>
        /// <param name="propertyRefs"> desired properties </param>
        private void AddPropertyRefs(Var v, PropertyRefList propertyRefs)
        {
            var currentRefs = GetPropertyRefList(v);

            currentRefs.Append(propertyRefs);
        }