Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        private static PropertyRefList GetIdentityProperties(EntityType type)
        {
            PropertyRefList keyProperties = PropertyPushdownHelper.GetKeyProperties(type);

            keyProperties.Add((PropertyRef)EntitySetIdPropertyRef.Instance);
            return(keyProperties);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 11
0
        // <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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 15
0
 internal void Append(PropertyRefList propertyRefs)
 {
     if (this.m_allProperties)
     {
         return;
     }
     foreach (PropertyRef key in propertyRefs.m_propertyReferences.Keys)
     {
         this.Add(key);
     }
 }
Ejemplo n.º 16
0
 // <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);
     }
 }
Ejemplo n.º 17
0
 // <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);
     }
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 27
0
 // <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;
 }
Ejemplo n.º 28
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);
        }
Ejemplo n.º 29
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);
        }
Ejemplo n.º 30
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);
 }
Ejemplo n.º 31
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;
 }
Ejemplo n.º 32
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);
 }
Ejemplo n.º 33
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;
 }
Ejemplo n.º 34
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;
 }
Ejemplo n.º 35
0
 private void AddPropertyRefs(System.Data.Entity.Core.Query.InternalTrees.Node node, PropertyRefList propertyRefs)
 {
     this.GetPropertyRefList(node).Append(propertyRefs);
 }
Ejemplo n.º 36
0
 private void AddPropertyRefs(Var v, PropertyRefList propertyRefs)
 {
     this.GetPropertyRefList(v).Append(propertyRefs);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }