Beispiel #1
0
            internal override StringBuilder VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                literal.ToCompactString(m_builder);
                return(m_builder);
            }
Beispiel #2
0
            // The real work happens here in the literal's RemapBool
            internal override DomainBoolExpr VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral literal    = BoolExpression.GetBoolLiteral(expression);
                BoolLiteral newLiteral = literal.RemapBool(m_remap);

                return(newLiteral.GetDomainBoolExpression(m_memberDomainMap));
            }
Beispiel #3
0
            // The real work happends here - the slots are obtained from the literal
            internal override DomainBoolExpr VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                literal.GetRequiredSlots(m_projectedSlotMap, m_requiredSlots);
                return(expression);
            }
Beispiel #4
0
        // requires: caseForOuterJoins corresponds the slot "slotNum"
        // effects: Adds a WhenThen corresponding to child to caseForOuterJoins.
        private void AddCaseForOuterJoins(CaseStatement caseForOuterJoins, CqlBlock child, int slotNum, CqlIdentifiers identifiers)
        {
            // Determine the cells that the slot comes from
            // and make an OR expression, e.g., WHEN _from0 or _from2 or ... THEN child[slotNum]

            ProjectedSlot         childSlot    = child.SlotValue(slotNum);
            ConstantProjectedSlot constantSlot = childSlot as ConstantProjectedSlot;

            if (constantSlot != null && constantSlot.CellConstant.IsNull())
            {
                // NULL being generated by a child - don't need to project
                return;
            }

            BoolExpression originBool = BoolExpression.False;

            for (int i = 0; i < NumBoolSlots; i++)
            {
                int boolSlotNum = BoolIndexToSlot(i);
                if (child.IsProjected(boolSlotNum))
                {
                    // OR it to the expression
                    QualifiedCellIdBoolean boolExpr = new QualifiedCellIdBoolean(child, identifiers, i);
                    originBool = BoolExpression.CreateOr(originBool, BoolExpression.CreateLiteral(boolExpr, RightDomainMap));
                }
            }
            // Qualify the slotNum with the child.CqlAlias for the THEN
            QualifiedSlot slot = child.QualifySlotWithBlockAlias(slotNum);

            caseForOuterJoins.AddWhenThen(originBool, slot);
        }
Beispiel #5
0
            // The real work happens here in the literal's FixRange
            internal override DomainBoolExpr VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral    literal = BoolExpression.GetBoolLiteral(expression);
                DomainBoolExpr result  = literal.FixRange(expression.Identifier.Range, m_memberDomainMap);

                return(result);
            }
Beispiel #6
0
            // Check if the oneOfConst is complete or not
            internal override bool VisitTerm(DomainTermExpr expression)
            {
                BoolLiteral       literal     = BoolExpression.GetBoolLiteral(expression);
                MemberRestriction restriction = literal as MemberRestriction;
                bool result = restriction == null || restriction.IsComplete == true;

                return(result);
            }
Beispiel #7
0
        /// <summary>
        /// Adds an expression of the form "WHEN <paramref name="condition"/> THEN <paramref name="value"/>".
        /// This operation is not allowed after the <see cref="Simplify"/> call.
        /// </summary>
        internal void AddWhenThen(BoolExpression condition, ProjectedSlot value)
        {
            Debug.Assert(!m_simplified, "Attempt to modify a simplified case statement");
            Debug.Assert(value != null);

            condition.ExpensiveSimplify();
            m_clauses.Add(new WhenThen(condition, value));
        }
Beispiel #8
0
            internal override T_Return VisitTerm(DomainTermExpr expression)
            {
                // If m_skipIsNotNull is true at this point, it means that no ancestor of this
                // node is OR or NOT
                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                return(BooleanLiteralAsCql(literal, m_skipIsNotNull));
            }
Beispiel #9
0
 /// <summary>
 /// Copy Constructor
 /// </summary>
 internal CellQuery(CellQuery source)
 {
     this.m_basicCellRelation   = source.m_basicCellRelation;
     this.m_boolExprs           = source.m_boolExprs;
     this.m_selectDistinct      = source.m_selectDistinct;
     this.m_extentMemberPath    = source.m_extentMemberPath;
     this.m_originalWhereClause = source.m_originalWhereClause;
     this.m_projectedSlots      = source.m_projectedSlots;
     this.m_whereClause         = source.m_whereClause;
 }
Beispiel #10
0
 // effects: Given all the fields, just sets them.
 internal CellQuery(ProjectedSlot[] projectedSlots,
                    BoolExpression whereClause,
                    List <BoolExpression> boolExprs,
                    SelectDistinct elimDupl, MemberPath rootMember)
 {
     m_boolExprs           = boolExprs;
     m_projectedSlots      = projectedSlots;
     m_whereClause         = whereClause;
     m_originalWhereClause = whereClause;
     m_selectDistinct      = elimDupl;
     m_extentMemberPath    = rootMember;
 }
Beispiel #11
0
        internal BoolExpression RemapLiterals(Dictionary <BoolLiteral, BoolLiteral> remap)
        {
            var rewriter = new BooleanExpressionTermRewriter <BoolDomainConstraint, BoolDomainConstraint>(
                //                term => remap[BoolExpression.GetBoolLiteral(term)].GetDomainBoolExpression(m_memberDomainMap));
                delegate(DomainTermExpr term)
            {
                BoolLiteral newLiteral;
                return(remap.TryGetValue(BoolExpression.GetBoolLiteral(term), out newLiteral) ?
                       newLiteral.GetDomainBoolExpression(m_memberDomainMap) : term);
            });

            return(new BoolExpression(m_tree.Accept(rewriter), m_memberDomainMap));
        }
Beispiel #12
0
 private IEnumerable <MemberRestriction> GetConjunctsFromWhereClause(BoolExpression whereClause)
 {
     foreach (BoolExpression boolExpr in whereClause.Atoms)
     {
         if (boolExpr.IsTrue)
         {
             continue;
         }
         MemberRestriction result = boolExpr.AsLiteral as MemberRestriction;
         Debug.Assert(result != null, "Atom must be restriction");
         yield return(result);
     }
 }
Beispiel #13
0
            internal override StringBuilder VisitTerm(DomainTermExpr expression)
            {
                // If m_skipIsNotNull is true at this point, it means that no ancestor of this
                // node is OR or NOT

                BoolLiteral literal = BoolExpression.GetBoolLiteral(expression);

                if (literal is ScalarRestriction || literal is TypeRestriction)
                {
                    return(literal.AsUserString(m_builder, Strings.ViewGen_EntityInstanceToken, m_skipIsNotNull));
                }

                return(literal.AsUserString(m_builder, m_blockAlias, m_skipIsNotNull));
            }
Beispiel #14
0
        // effects: Given a list of bools, returns a list of boolean expressions where each
        // boolean in bools has been ANDed with conjunct
        // CHANGE_Microsoft_IMPROVE: replace with lambda pattern
        internal static List <BoolExpression> AddConjunctionToBools(List <BoolExpression> bools,
                                                                    BoolExpression conjunct)
        {
            List <BoolExpression> result = new List <BoolExpression>();

            // Go through the list -- AND each non-null boolean with conjunct
            foreach (BoolExpression b in bools)
            {
                if (null == b)
                { // unused boolean -- leave as it is
                    result.Add(null);
                }
                else
                {
                    result.Add(CreateAnd(b, conjunct));
                }
            }
            return(result);
        }
Beispiel #15
0
        // requires: The CellConstantDomains in the OneOfConsts of the where
        // clause are partially done
        // effects: Given the domains of different variables in domainMap,
        // fixes the whereClause of this such that all the
        // CellConstantDomains in OneOfConsts are complete
        internal void UpdateWhereClause(MemberDomainMap domainMap)
        {
            List <BoolExpression> atoms = new List <BoolExpression>();

            foreach (BoolExpression atom in WhereClause.Atoms)
            {
                BoolLiteral       literal     = atom.AsLiteral;
                MemberRestriction restriction = literal as MemberRestriction;
                Debug.Assert(restriction != null, "All bool literals must be OneOfConst at this point");
                // The oneOfConst needs to be fixed with the new possible values from the domainMap.
                IEnumerable <Constant> possibleValues = domainMap.GetDomain(restriction.RestrictedMemberSlot.MemberPath);
                MemberRestriction      newOneOf       = restriction.CreateCompleteMemberRestriction(possibleValues);

                // Prevent optimization of single constraint e.g: "300 in (300)"
                // But we want to optimize type constants e.g: "category in (Category)"
                // To prevent optimization of bool expressions we add a Sentinel OneOF

                ScalarRestriction scalarConst = restriction as ScalarRestriction;
                bool addSentinel =
                    scalarConst != null &&
                    !scalarConst.Domain.Contains(Constant.Null) &&
                    !scalarConst.Domain.Contains(Constant.NotNull) &&
                    !scalarConst.Domain.Contains(Constant.Undefined);

                if (addSentinel)
                {
                    domainMap.AddSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }

                atoms.Add(BoolExpression.CreateLiteral(newOneOf, domainMap));

                if (addSentinel)
                {
                    domainMap.RemoveSentinel(newOneOf.RestrictedMemberSlot.MemberPath);
                }
            }
            // We create a new whereClause that has the memberDomainMap set
            if (atoms.Count > 0)
            {
                m_whereClause = BoolExpression.CreateAnd(atoms.ToArray());
            }
        }
Beispiel #16
0
            internal override StringBuilder VisitNot(DomainNotExpr expression)
            {
                m_skipIsNotNull = false; // Cannot skip in NOTs

                DomainTermExpr termExpr = expression.Child as DomainTermExpr;

                if (termExpr != null)
                {
                    BoolLiteral literal = BoolExpression.GetBoolLiteral(termExpr);
                    return(literal.AsNegatedUserString(m_builder, m_blockAlias, m_skipIsNotNull));
                }
                else
                {
                    m_builder.Append("NOT(");
                    // We do not need the returned StringBuilder -- it is the same as m_builder
                    expression.Child.Accept(this);
                    m_builder.Append(")");
                }
                return(m_builder);
            }
Beispiel #17
0
 internal static BoolExpression CreateAndNot(BoolExpression e1, BoolExpression e2)
 {
     return(CreateAnd(e1, CreateNot(e2)));
 }
Beispiel #18
0
 // effects: Create a boolean expression of the form "NOT expression"
 internal static BoolExpression CreateNot(BoolExpression expression)
 {
     return(new BoolExpression(ExprType.Not, new BoolExpression[] { expression }));
 }
Beispiel #19
0
        internal BoolExpression MakeCopy()
        {
            BoolExpression copy = Create(m_tree.Accept(CopyVisitorInstance));

            return(copy);
        }
Beispiel #20
0
 /// <summary>
 /// Creates WHEN condition THEN value.
 /// </summary>
 internal WhenThen(BoolExpression condition, ProjectedSlot value)
 {
     m_condition = condition;
     m_value     = value;
 }
        internal override CqlBlock ToCqlBlock(bool[] requiredSlots, CqlIdentifiers identifiers, ref int blockAliasNum, ref List <WithRelationship> withRelationships)
        {
            // Get the projected slots and the boolean expressions
            int       totalSlots = requiredSlots.Length;
            CellQuery cellQuery  = LeftCellWrapper.RightCellQuery;

            SlotInfo[] projectedSlots = new SlotInfo[totalSlots];
            Debug.Assert(cellQuery.NumProjectedSlots + cellQuery.NumBoolVars == totalSlots,
                         "Wrong number of projected slots in node");

            Debug.Assert(cellQuery.NumProjectedSlots == ProjectedSlotMap.Count,
                         "Different number of slots in cell query and what we have mappings for");
            // Add the regular fields
            for (int i = 0; i < cellQuery.NumProjectedSlots; i++)
            {
                ProjectedSlot slot = cellQuery.ProjectedSlotAt(i);
                // If the slot is not null, we will project it
                // For extents, we say that all requiredlots are the only the
                // ones that are CLR non-null. Recall that "real" nulls are
                // handled by having a CellConstant.Null in ConstantSlot
                if (requiredSlots[i] && slot == null)
                {
                    MemberPath            memberPath   = ProjectedSlotMap[i];
                    ConstantProjectedSlot defaultValue = new ConstantProjectedSlot(Domain.GetDefaultValueForMemberPath(memberPath, GetLeaves(), ViewgenContext.Config), memberPath);
                    cellQuery.FixMissingSlotAsDefaultConstant(i, defaultValue);
                    slot = defaultValue;
                }
                SlotInfo slotInfo = new SlotInfo(requiredSlots[i], slot != null,
                                                 slot, ProjectedSlotMap[i]);
                projectedSlots[i] = slotInfo;
            }

            // Add the boolean fields
            for (int boolNum = 0; boolNum < cellQuery.NumBoolVars; boolNum++)
            {
                BoolExpression       expr = cellQuery.GetBoolVar(boolNum);
                BooleanProjectedSlot boolSlot;
                if (expr != null)
                {
                    boolSlot = new BooleanProjectedSlot(expr, identifiers, boolNum);
                }
                else
                {
                    boolSlot = new BooleanProjectedSlot(BoolExpression.False, identifiers, boolNum);
                }
                int      slotIndex = BoolIndexToSlot(boolNum);
                SlotInfo slotInfo  = new SlotInfo(requiredSlots[slotIndex], expr != null,
                                                  boolSlot, null);
                projectedSlots[slotIndex] = slotInfo;
            }

            // See if we are generating a query view and whether there are any colocated foreign keys for which
            // we have to add With statements.
            IEnumerable <SlotInfo> totalProjectedSlots = projectedSlots;

            if ((cellQuery.Extent.EntityContainer.DataSpace == DataSpace.SSpace) &&
                (this.m_cellWrapper.LeftExtent.BuiltInTypeKind == BuiltInTypeKind.EntitySet))
            {
                IEnumerable <StorageAssociationSetMapping> associationSetMaps =
                    this.ViewgenContext.EntityContainerMapping.GetRelationshipSetMappingsFor(this.m_cellWrapper.LeftExtent, cellQuery.Extent);
                List <SlotInfo> foreignKeySlots = new List <SlotInfo>();
                foreach (StorageAssociationSetMapping colocatedAssociationSetMap in associationSetMaps)
                {
                    WithRelationship withRelationship;
                    if (TryGetWithRelationship(colocatedAssociationSetMap, this.m_cellWrapper.LeftExtent, cellQuery.SourceExtentMemberPath, ref foreignKeySlots, out withRelationship))
                    {
                        withRelationships.Add(withRelationship);
                        totalProjectedSlots = projectedSlots.Concat(foreignKeySlots);
                    }
                }
            }
            ExtentCqlBlock result = new ExtentCqlBlock(cellQuery.Extent, cellQuery.SelectDistinctFlag, totalProjectedSlots.ToArray(),
                                                       cellQuery.WhereClause, identifiers, ++blockAliasNum);

            return(result);
        }
Beispiel #22
0
 // effects: Creates a cell query with the given projection (slots),
 // from part (joinTreeRoot) and the predicate (whereClause)
 // Used for cell creation
 internal CellQuery(List <ProjectedSlot> slots, BoolExpression whereClause, MemberPath rootMember, SelectDistinct eliminateDuplicates)
     : this(slots.ToArray(), whereClause, new List <BoolExpression>(), eliminateDuplicates, rootMember)
 {
 }