Example #1
0
        // requires: domain not have any Negated constants other than NotNull
        // Also, cellQuery contains all final oneOfConsts or all partial oneOfConsts
        // cellquery must contain a whereclause of the form "True", "OneOfConst" or "
        // "OneOfConst AND ... AND OneOfConst"
        // slot must present in cellQuery and incomingDomain is the domain for it
        // effects: Returns the set of values that slot can take as restricted by cellQuery's whereClause
        private static bool TryGetDomainRestrictedByWhereClause(
            IEnumerable <Constant> domain, MemberProjectedSlot slot, CellQuery cellQuery, out CellConstantSet result)
        {
            var conditionsForSlot = cellQuery.GetConjunctsFromWhereClause()
                                    .Where(
                restriction =>
                MemberPath.EqualityComparer.Equals(
                    restriction.RestrictedMemberSlot.MemberPath, slot.MemberPath))
                                    .Select(
                restriction => new CellConstantSet(restriction.Domain.Values, Constant.EqualityComparer));

            //Debug.Assert(!conditionsForSlot.Skip(1).Any(), "More than one Clause with the same path");

            if (!conditionsForSlot.Any())
            {
                // If the slot was not mentioned in the query return the domain without restricting it
                result = new CellConstantSet(domain);
                return(false);
            }

            // Now get all the possible values from domain and conditionValues
            var possibleValues = DeterminePossibleValues(conditionsForSlot.SelectMany(m => m.Select(c => c)), domain);

            var restrictedDomain = new Domain(domain, possibleValues);

            foreach (var conditionValues in conditionsForSlot)
            {
                // Domain derived from Edm-Type INTERSECTED with Conditions
                restrictedDomain = restrictedDomain.Intersect(new Domain(conditionValues, possibleValues));
            }

            result = new CellConstantSet(restrictedDomain.Values, Constant.EqualityComparer);
            return(!domain.SequenceEqual(result));
        }
Example #2
0
        // effects: Given a set of values in domain1 and domain2,
        // Returns all possible positive values that are present in domain1 and domain2
        private static CellConstantSet DeterminePossibleValues(IEnumerable <Constant> domain1, IEnumerable <Constant> domain2)
        {
            var union  = new CellConstantSet(domain1, Constant.EqualityComparer).Union(domain2);
            var result = DeterminePossibleValues(union);

            return(result);
        }
Example #3
0
        // effects: Given a set of values in domain
        // Returns all possible values that are present in domain.
        private static CellConstantSet DeterminePossibleValues(IEnumerable <Constant> domain)
        {
            // E.g., if we have 1, 2, NOT(1) --> Result = 1, 2
            // 1, NOT(1, 2) --> Result = 1, 2
            // 1, 2, NOT(NULL) --> Result = 1, 2, NULL
            // 1, 2, NOT(2), NOT(3, 4) --> Result = 1, 2, 3, 4

            var result = new CellConstantSet(Constant.EqualityComparer);

            foreach (var constant in domain)
            {
                var negated = constant as NegatedConstant;

                if (negated != null)
                {
                    // Go through all the constants in negated and add them to domain
                    // We add them to possible values also even if (say) Null is not allowed because we want the complete
                    // partitioning of the space, e.g., if the values specified by the caller are 1, NotNull -> we want 1, Null
                    foreach (var constElement in negated.Elements)
                    {
                        Debug.Assert(constElement as NegatedConstant == null, "Negated cell constant inside NegatedCellConstant");
                        result.Add(constElement);
                    }
                }
                else
                {
                    result.Add(constant);
                }
            }

            return(result);
        }
        // effects: For member, adds domainValues as the set of values that
        // member can take. Merges them with any existing values if present
        private void AddToDomainMap(MemberPath member, IEnumerable <Constant> domainValues)
        {
            CellConstantSet possibleValues;

            if (false == m_conditionDomainMap.TryGetValue(member, out possibleValues))
            {
                possibleValues = new CellConstantSet(Constant.EqualityComparer);
            }
            possibleValues.Unite(domainValues);
            // Add the normalized domain to the map so that later uses of the
            // domain are consistent
            m_conditionDomainMap[member] = Domain.ExpandNegationsInDomain(possibleValues, possibleValues);
        }
Example #5
0
        // effects: Given a type, determines all possible values that can be created from Metadata
        private static CellConstantSet DeriveDomainFromType(EdmType type, EdmItemCollection edmItemCollection, bool leaveDomainUnbounded)
        {
            CellConstantSet domain = null;

            if (Helper.IsScalarType(type))
            {
                // Get the domain for scalars -- for booleans, we special case.
                if (MetadataHelper.HasDiscreteDomain(type))
                {
                    Debug.Assert(
                        Helper.AsPrimitive(type).PrimitiveTypeKind == PrimitiveTypeKind.Boolean, "Only boolean type has discrete domain.");

                    // Closed domain
                    domain = new Set <Constant>(CreateList(true, false), Constant.EqualityComparer);
                }
                else
                {
                    // Unbounded domain
                    domain = new Set <Constant>(Constant.EqualityComparer);
                    if (leaveDomainUnbounded)
                    {
                        domain.Add(Constant.NotNull);
                    }
                }
            }
            else //Type Constants - Domain is all possible concrete subtypes
            {
                Debug.Assert(
                    Helper.IsEntityType(type) || Helper.IsComplexType(type) || Helper.IsRefType(type) || Helper.IsAssociationType(type));

                // Treat ref types as their referenced entity types
                if (Helper.IsRefType(type))
                {
                    type = ((RefType)type).ElementType;
                }

                var types = new List <Constant>();
                foreach (var derivedType in MetadataHelper.GetTypeAndSubtypesOf(type, edmItemCollection, false /*includeAbstractTypes*/))
                {
                    var derivedTypeConstant = new TypeConstant(derivedType);
                    types.Add(derivedTypeConstant);
                }
                domain = new Set <Constant>(types, Constant.EqualityComparer);
            }

            Debug.Assert(domain != null, "Domain not set up for some type");
            return(domain);
        }
 // effects: For member, adds domainValues as the set of values that
 // member can take. Merges them with any existing values if present
 private void AddToDomainMap(MemberPath member, IEnumerable<Constant> domainValues)
 {
     CellConstantSet possibleValues;
     if (false == m_conditionDomainMap.TryGetValue(member, out possibleValues))
     {
         possibleValues = new CellConstantSet(Constant.EqualityComparer);
     }
     possibleValues.Unite(domainValues);
     // Add the normalized domain to the map so that later uses of the
     // domain are consistent
     m_conditionDomainMap[member] = Domain.ExpandNegationsInDomain(possibleValues, possibleValues);
 }
Example #7
0
        //True = domain is restricted, False = domain is not restricted (because there is no condition)
        private static bool GetRestrictedOrUnrestrictedDomain(
            MemberProjectedSlot slot, CellQuery cellQuery, EdmItemCollection edmItemCollection, out CellConstantSet domain)
        {
            var domainValues = DeriveDomainFromMemberPath(slot.MemberPath, edmItemCollection, true /* leaveDomainUnbounded */);

            //Note, out domain is set even in the case where method call returns false
            return(TryGetDomainRestrictedByWhereClause(domainValues, slot, cellQuery, out domain));
        }
Example #8
0
 // effects: Given a set of values in domain1 and domain2,
 // Returns all possible positive values that are present in domain1 and domain2
 private static CellConstantSet DeterminePossibleValues(IEnumerable<Constant> domain1, IEnumerable<Constant> domain2)
 {
     var union = new CellConstantSet(domain1, Constant.EqualityComparer).Union(domain2);
     var result = DeterminePossibleValues(union);
     return result;
 }
Example #9
0
        // requires: domain not have any Negated constants other than NotNull
        // Also, cellQuery contains all final oneOfConsts or all partial oneOfConsts
        // cellquery must contain a whereclause of the form "True", "OneOfConst" or "
        // "OneOfConst AND ... AND OneOfConst"
        // slot must present in cellQuery and incomingDomain is the domain for it
        // effects: Returns the set of values that slot can take as restricted by cellQuery's whereClause
        private static bool TryGetDomainRestrictedByWhereClause(
            IEnumerable<Constant> domain, MemberProjectedSlot slot, CellQuery cellQuery, out CellConstantSet result)
        {
            var conditionsForSlot = cellQuery.GetConjunctsFromWhereClause()
                                             .Where(
                                                 restriction =>
                                                 MemberPath.EqualityComparer.Equals(
                                                     restriction.RestrictedMemberSlot.MemberPath, slot.MemberPath))
                                             .Select(
                                                 restriction => new CellConstantSet(restriction.Domain.Values, Constant.EqualityComparer));

            //Debug.Assert(!conditionsForSlot.Skip(1).Any(), "More than one Clause with the same path");

            if (!conditionsForSlot.Any())
            {
                // If the slot was not mentioned in the query return the domain without restricting it 
                result = new CellConstantSet(domain);
                return false;
            }

            // Now get all the possible values from domain and conditionValues
            var possibleValues = DeterminePossibleValues(conditionsForSlot.SelectMany(m => m.Select(c => c)), domain);

            var restrictedDomain = new Domain(domain, possibleValues);
            foreach (var conditionValues in conditionsForSlot)
            {
                // Domain derived from Edm-Type INTERSECTED with Conditions
                restrictedDomain = restrictedDomain.Intersect(new Domain(conditionValues, possibleValues));
            }

            result = new CellConstantSet(restrictedDomain.Values, Constant.EqualityComparer);
            return !domain.SequenceEqual(result);
        }
Example #10
0
        //True = domain is restricted, False = domain is not restricted (because there is no condition)
        private static bool GetRestrictedOrUnrestrictedDomain(
            MemberProjectedSlot slot, CellQuery cellQuery, EdmItemCollection edmItemCollection, out CellConstantSet domain)
        {
            var domainValues = DeriveDomainFromMemberPath(slot.MemberPath, edmItemCollection, true /* leaveDomainUnbounded */);

            //Note, out domain is set even in the case where method call returns false
            return TryGetDomainRestrictedByWhereClause(domainValues, slot, cellQuery, out domain);
        }
Example #11
0
        // effects: Given a set of values in domain
        // Returns all possible values that are present in domain. 
        private static CellConstantSet DeterminePossibleValues(IEnumerable<Constant> domain)
        {
            // E.g., if we have 1, 2, NOT(1) --> Result = 1, 2
            // 1, NOT(1, 2) --> Result = 1, 2
            // 1, 2, NOT(NULL) --> Result = 1, 2, NULL
            // 1, 2, NOT(2), NOT(3, 4) --> Result = 1, 2, 3, 4

            var result = new CellConstantSet(Constant.EqualityComparer);

            foreach (var constant in domain)
            {
                var negated = constant as NegatedConstant;

                if (negated != null)
                {
                    // Go through all the constants in negated and add them to domain
                    // We add them to possible values also even if (say) Null is not allowed because we want the complete 
                    // partitioning of the space, e.g., if the values specified by the caller are 1, NotNull -> we want 1, Null
                    foreach (var constElement in negated.Elements)
                    {
                        Debug.Assert(constElement as NegatedConstant == null, "Negated cell constant inside NegatedCellConstant");
                        result.Add(constElement);
                    }
                }
                else
                {
                    result.Add(constant);
                }
            }

            return result;
        }