Example #1
0
        protected override bool IsEqualTo(Constant right)
        {
            ScalarConstant scalarConstant = right as ScalarConstant;

            if (scalarConstant == null)
            {
                return(false);
            }
            return(ByValueEqualityComparer.Default.Equals(this.m_scalar, scalarConstant.m_scalar));
        }
Example #2
0
        internal override BoolExpr <DomainConstraint <BoolLiteral, Constant> > FixRange(
            Set <Constant> range,
            MemberDomainMap memberDomainMap)
        {
            ScalarConstant scalarConstant = (ScalarConstant)range.First <Constant>();
            BoolExpr <DomainConstraint <BoolLiteral, Constant> > child = this.GetDomainBoolExpression(memberDomainMap);

            if (!(bool)scalarConstant.Value)
            {
                child = (BoolExpr <DomainConstraint <BoolLiteral, Constant> >) new NotExpr <DomainConstraint <BoolLiteral, Constant> >(child);
            }
            return(child);
        }
Example #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_ADYA_FEATURE_DEFAULT_VALUES: return the right default once metadata supports it
        internal static bool TryGetDefaultValueForMemberPath(MemberPath memberPath, out Constant defaultConstant)
        {
            var 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);
        }
        /// <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)
        {
            DebugCheck.NotNull(originalCell);
            DebugCheck.NotNull(memberToExpand);
            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;
        }
Example #5
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_ADYA_FEATURE_DEFAULT_VALUES: return the right default once metadata supports it
 internal static bool TryGetDefaultValueForMemberPath(MemberPath memberPath, out Constant defaultConstant)
 {
     var 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;
 }