Class SqlConstraintUtils


  • public class SqlConstraintUtils
    extends Object
    Utility class used by implementations of SqlConstraint, used to generate constraints into SqlQuery.
    Since:
    Nov 21, 2005
    Author:
    av
    • Method Detail

      • addContextConstraint

        public static void addContextConstraint​(SqlQuery sqlQuery,
                                                AggStar aggStar,
                                                Evaluator evaluator,
                                                RolapCube baseCube,
                                                boolean restrictMemberTypes)
        For every restricting member in the current context, generates a WHERE condition and a join to the fact table.
        Parameters:
        sqlQuery - the query to modify
        aggStar - Aggregate table, or null if query is against fact table
        restrictMemberTypes - defines the behavior if the current context contains calculated members. If true, thows an exception.
        evaluator - Evaluator
      • useTupleSlicer

        public static boolean useTupleSlicer​(RolapEvaluator evaluator)
      • isDisjointTuple

        public static boolean isDisjointTuple​(TupleList tupleList)
      • hasMultipleLevelSlicer

        public static boolean hasMultipleLevelSlicer​(Evaluator evaluator)
      • getColumnExpr

        public static String getColumnExpr​(SqlQuery sqlQuery,
                                           AggStar aggStar,
                                           RolapStar.Column column)
        Get the column expression from the AggStar if provided or the regular table if not, and ensure table is in From
      • hasMultiPositionSlicer

        public static boolean hasMultiPositionSlicer​(List<Member> slicerMembers)
      • expandSupportedCalculatedMember

        public static void expandSupportedCalculatedMember​(Member member,
                                                           Evaluator evaluator,
                                                           boolean disjointSlicerTuples,
                                                           TupleConstraintStruct expandedSet)
      • isSupportedCalculatedMember

        public static boolean isSupportedCalculatedMember​(Member member)
        Check to see if this is in a list of supported calculated members. Currently, only the Aggregate and the + function is supported.
        Returns:
        true if the calculated member is supported for native evaluation
      • isSupportedExpressionForCalculatedMember

        public static boolean isSupportedExpressionForCalculatedMember​(Exp expression)
      • getUniqueOrdinalMembers

        protected static List<Member> getUniqueOrdinalMembers​(List<Member> members)
        Gets a list of unique ordinal cube members to make sure our cell request isn't unsatisfiable, following the same logic as RolapEvaluator
        Returns:
        Unique ordinal cube members
      • expandMultiPositionSlicerMembers

        protected static Member[] expandMultiPositionSlicerMembers​(Member[] members,
                                                                   Evaluator evaluator)
      • containsCalculatedMember

        public static boolean containsCalculatedMember​(List<Member> members)
      • containsCalculatedMember

        public static boolean containsCalculatedMember​(List<Member> members,
                                                       boolean allowExpandableMembers)
      • joinLevelTableToFactTable

        public static void joinLevelTableToFactTable​(SqlQuery sqlQuery,
                                                     RolapCube baseCube,
                                                     AggStar aggStar,
                                                     Evaluator e,
                                                     RolapCubeLevel level)
        Ensures that the table of level is joined to the fact table
        Parameters:
        sqlQuery - sql query under construction
        aggStar - The aggStar to use, if any.
        e - evaluator corresponding to query
        level - level to be added to query
      • addMemberConstraint

        public static void addMemberConstraint​(SqlQuery sqlQuery,
                                               RolapCube baseCube,
                                               AggStar aggStar,
                                               RolapMember parent,
                                               boolean restrictMemberTypes)
        Creates a "WHERE parent = value" constraint.
        Parameters:
        sqlQuery - the query to modify
        baseCube - base cube if virtual
        aggStar - Definition of the aggregate table, or null
        parent - the list of parent members
        restrictMemberTypes - defines the behavior if parent is a calculated member. If true, an exception is thrown
      • addMemberConstraint

        public static void addMemberConstraint​(SqlQuery sqlQuery,
                                               RolapCube baseCube,
                                               AggStar aggStar,
                                               List<RolapMember> members,
                                               boolean restrictMemberTypes,
                                               boolean crossJoin,
                                               boolean exclude)
        Creates a "WHERE exp IN (...)" condition containing the values of all parents. All parents must belong to the same level.

        If this constraint is part of a native cross join, there are multiple constraining members, and the members comprise the cross product of all unique member keys referenced at each level, then generating IN expressions would result in incorrect results. In that case, "WHERE ((level1 = val1a AND level2 = val2a AND ...) OR (level1 = val1b AND level2 = val2b AND ...) OR ..." is generated instead.

        Parameters:
        sqlQuery - the query to modify
        baseCube - base cube if virtual
        aggStar - (not used)
        members - the list of members for this constraint
        restrictMemberTypes - defines the behavior if parents contains calculated members. If true, and one of the members is calculated, an exception is thrown.
        crossJoin - true if constraint is being generated as part of a native crossjoin
        exclude - whether to exclude the members in the SQL predicate. e.g. not in { member list}.
      • constrainLevel

        public static String constrainLevel​(RolapLevel level,
                                            SqlQuery query,
                                            RolapCube baseCube,
                                            AggStar aggStar,
                                            String[] columnValue,
                                            boolean caseSensitive)
        Generates a sql expression constraining a level by some value
        Parameters:
        level - the level
        query - the query that the sql expression will be added to
        baseCube - base cube for virtual levels
        aggStar - aggregate star if available
        columnValue - value constraining the level
        caseSensitive - if true, need to handle case sensitivity of the member value
        Returns:
        generated string corresponding to the expression
      • constrainLevel2

        public static String constrainLevel2​(SqlQuery query,
                                             MondrianDef.Expression exp,
                                             Dialect.Datatype datatype,
                                             Comparable columnValue)
        Generates a sql expression constraining a level by some value
        Parameters:
        exp - Key expression
        datatype - Key datatype
        query - the query that the sql expression will be added to
        columnValue - value constraining the level
        Returns:
        generated string corresponding to the expression
      • measuresConflictWithMembers

        public static boolean measuresConflictWithMembers​(Set<Member> measures,
                                                          Member[] members)
        Returns true if any measure calculations in the first arg references a dimension member with corresponding members in the second arg which conflict with that member. A member "conflicts" if the member referenced by the measure is not equal to or children of the corresponding dimension member. For example, given ( [unit sales], [Time].[1997].Q1 ) in the measures set, if the member [Time].[1997].[Q2] is in the members set this would conflict, since Q1 is not equal to or a child of Q2. This method is used in native evaluation to determine whether any measures in the query could conflict with the SQL constraint being constructed.
      • getMembersNestedInMeasures

        public static Set<Member> getMembersNestedInMeasures​(Set<Member> measures)
      • measuresConflictWithMembers

        public static boolean measuresConflictWithMembers​(Set<Member> measuresMembers,
                                                          CrossJoinArg[] cjArgs)
      • containsValidMeasure

        public static boolean containsValidMeasure​(Exp... expressions)