Ejemplo n.º 1
0
        protected override bool IsEqualTo(Constant right)
        {
            ScalarConstant rightScalarConstant = right as ScalarConstant;

            if (rightScalarConstant == null)
            {
                return(false);
            }

            return(ByValueEqualityComparer.Default.Equals(m_scalar, rightScalarConstant.m_scalar));
        }
Ejemplo n.º 2
0
        internal override DomainBoolExpr FixRange(Set <Constant> range, MemberDomainMap memberDomainMap)
        {
            Debug.Assert(range.Count == 1, "For BoolLiterals, there should be precisely one value - true or false");
            ScalarConstant scalar = (ScalarConstant)range.First();
            DomainBoolExpr expr   = GetDomainBoolExpression(memberDomainMap);

            if ((bool)scalar.Value == false)
            {
                // The range of the variable was "inverted". Return a NOT of
                // the expression
                expr = new DomainNotExpr(expr);
            }
            return(expr);
        }
Ejemplo n.º 3
0
        // effect: returns the default value for the member
        // if the member is nullable and has no default, changes default value to CellConstant.NULL and returns true
        // if the mebmer is not nullable and has no default, returns false
        // CHANGE_Microsoft_FEATURE_DEFAULT_VALUES: return the right default once metadata supports it
        internal static bool TryGetDefaultValueForMemberPath(MemberPath memberPath, out Constant defaultConstant)
        {
            object defaultValue = memberPath.DefaultValue;

            defaultConstant = Constant.Null;
            if (defaultValue != null)
            {
                defaultConstant = new ScalarConstant(defaultValue);
                return(true);
            }
            else if (memberPath.IsNullable || memberPath.IsComputed)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 4
0
 // effect: returns the default value for the member
 // if the member is nullable and has no default, changes default value to CellConstant.NULL and returns true
 // if the mebmer is not nullable and has no default, returns false
 // CHANGE_[....]_FEATURE_DEFAULT_VALUES: return the right default once metadata supports it
 internal static bool TryGetDefaultValueForMemberPath(MemberPath memberPath, out Constant defaultConstant)
 {
     object defaultValue = memberPath.DefaultValue;
     defaultConstant = Constant.Null;
     if (defaultValue != null)
     {
         defaultConstant = new ScalarConstant(defaultValue);
         return true;
     }
     else if (memberPath.IsNullable || memberPath.IsComputed)
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Given a cell, a member and a boolean condition on that member, creates additional cell
        /// which with the specified restriction on the member in addition to original condition.
        /// e.i conjunction of original condition AND member in newCondition
        /// 
        /// Creation fails when the original condition contradicts new boolean condition
        /// 
        /// ViewTarget tells whether MemberPath is in Cquery or SQuery
        /// </summary>
        private bool TryCreateAdditionalCellWithCondition(
            Cell originalCell, MemberPath memberToExpand, bool conditionValue, ViewTarget viewTarget, out Cell result)
        {
            Debug.Assert(originalCell != null);
            Debug.Assert(memberToExpand != null);
            result = null;

            //Create required structures
            var leftExtent = originalCell.GetLeftQuery(viewTarget).SourceExtentMemberPath;
            var rightExtent = originalCell.GetRightQuery(viewTarget).SourceExtentMemberPath;

            //Now for the given left-side projected member, find corresponding right-side member that it is mapped to 
            var indexOfBooLMemberInProjection =
                originalCell.GetLeftQuery(viewTarget).GetProjectedMembers().TakeWhile(path => !path.Equals(memberToExpand)).Count();
            var rightConditionMemberSlot =
                ((MemberProjectedSlot)originalCell.GetRightQuery(viewTarget).ProjectedSlotAt(indexOfBooLMemberInProjection));
            var rightSidePath = rightConditionMemberSlot.MemberPath;

            var leftSlots = new List<ProjectedSlot>();
            var rightSlots = new List<ProjectedSlot>();

            //Check for impossible conditions (otehrwise we get inaccurate pre-validation errors)
            var negatedCondition = new ScalarConstant(!conditionValue);

            if (originalCell.GetLeftQuery(viewTarget).Conditions
                    .Where(restriction => restriction.RestrictedMemberSlot.MemberPath.Equals(memberToExpand))
                    .Where(restriction => restriction.Domain.Values.Contains(negatedCondition)).Any()
                || originalCell.GetRightQuery(viewTarget).Conditions
                       .Where(restriction => restriction.RestrictedMemberSlot.MemberPath.Equals(rightSidePath))
                       .Where(restriction => restriction.Domain.Values.Contains(negatedCondition)).Any())
            {
                return false;
            }
            //End check

            //Create Projected Slots
            // Map all slots in original cell (not just keys) because some may be required (non nullable and no default)
            // and others may have not_null condition so MUST be projected. Rely on the user doing the right thing, otherwise
            // they will get the error message anyway
            for (var i = 0; i < originalCell.GetLeftQuery(viewTarget).NumProjectedSlots; i++)
            {
                leftSlots.Add(originalCell.GetLeftQuery(viewTarget).ProjectedSlotAt(i));
            }

            for (var i = 0; i < originalCell.GetRightQuery(viewTarget).NumProjectedSlots; i++)
            {
                rightSlots.Add(originalCell.GetRightQuery(viewTarget).ProjectedSlotAt(i));
            }

            //Create condition boolena expressions
            var leftQueryWhereClause =
                BoolExpression.CreateLiteral(new ScalarRestriction(memberToExpand, new ScalarConstant(conditionValue)), null);
            leftQueryWhereClause = BoolExpression.CreateAnd(originalCell.GetLeftQuery(viewTarget).WhereClause, leftQueryWhereClause);

            var rightQueryWhereClause =
                BoolExpression.CreateLiteral(new ScalarRestriction(rightSidePath, new ScalarConstant(conditionValue)), null);
            rightQueryWhereClause = BoolExpression.CreateAnd(originalCell.GetRightQuery(viewTarget).WhereClause, rightQueryWhereClause);

            //Create additional Cells
            var rightQuery = new CellQuery(
                rightSlots, rightQueryWhereClause, rightExtent, originalCell.GetRightQuery(viewTarget).SelectDistinctFlag);
            var leftQuery = new CellQuery(
                leftSlots, leftQueryWhereClause, leftExtent, originalCell.GetLeftQuery(viewTarget).SelectDistinctFlag);

            Cell newCell;
            if (viewTarget == ViewTarget.UpdateView)
            {
                newCell = Cell.CreateCS(rightQuery, leftQuery, originalCell.CellLabel, m_currentCellNumber);
            }
            else
            {
                newCell = Cell.CreateCS(leftQuery, rightQuery, originalCell.CellLabel, m_currentCellNumber);
            }

            m_currentCellNumber++;
            result = newCell;
            return true;
        }