Package mondrian.rolap
Class SqlConstraintUtils
java.lang.Object
mondrian.rolap.SqlConstraintUtils
Utility class used by implementations of
SqlConstraint
, used to generate constraints into
SqlQuery
.- Since:
- Nov 21, 2005
- Author:
- av
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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.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.static void
addMemberConstraint
(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, RolapMember parent, boolean restrictMemberTypes) Creates a "WHERE parent = value" constraint.static String
constrainLevel
(RolapLevel level, SqlQuery query, RolapCube baseCube, AggStar aggStar, String[] columnValue, boolean caseSensitive) Generates a sql expression constraining a level by some valuestatic String
constrainLevel
(RolapLevel level, SqlQuery query, RolapCube baseCube, AggStar aggStar, String columnValue, boolean caseSensitive) static String
constrainLevel2
(SqlQuery query, MondrianDef.Expression exp, Dialect.Datatype datatype, Comparable columnValue) Generates a sql expression constraining a level by some valuestatic boolean
containsCalculatedMember
(List<Member> members) static boolean
containsCalculatedMember
(List<Member> members, boolean allowExpandableMembers) static boolean
containsValidMeasure
(Exp... expressions) static void
expandExpressions
(Member member, Exp expression, Evaluator evaluator, TupleConstraintStruct expandedSet) protected static Member[]
expandMultiPositionSlicerMembers
(Member[] members, Evaluator evaluator) static void
expandSetFromCalculatedMember
(Evaluator evaluator, Member member, TupleConstraintStruct expandedSet) static void
expandSupportedCalculatedMember
(Member member, Evaluator evaluator, boolean disjointSlicerTuples, TupleConstraintStruct expandedSet) static void
expandSupportedCalculatedMember
(Member member, Evaluator evaluator, TupleConstraintStruct expandedSet) static TupleConstraintStruct
expandSupportedCalculatedMembers
(List<Member> members, Evaluator evaluator) static TupleConstraintStruct
expandSupportedCalculatedMembers
(List<Member> members, Evaluator evaluator, boolean disjointSlicerTuples) 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 FromgetMembersNestedInMeasures
(Set<Member> measures) static Map<Level,
List<RolapMember>> getRoleConstraintMembers
(SchemaReader schemaReader, Member[] members) static Map<RolapLevel,
List<RolapMember>> getRolesConstraints
(Evaluator evaluator) 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 RolapEvaluatorstatic boolean
hasMultipleLevelSlicer
(Evaluator evaluator) static boolean
hasMultiPositionSlicer
(List<Member> slicerMembers) static boolean
isDisjointTuple
(TupleList tupleList) static boolean
isSupportedCalculatedMember
(Member member) Check to see if this is in a list of supported calculated members.static boolean
isSupportedExpressionForCalculatedMember
(Exp expression) static void
joinLevelTableToFactTable
(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, Evaluator e, RolapCubeLevel level) Ensures that the table oflevel
is joined to the fact tablestatic 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.static boolean
measuresConflictWithMembers
(Set<Member> measuresMembers, CrossJoinArg[] cjArgs) static boolean
useTupleSlicer
(RolapEvaluator evaluator)
-
Method Details
-
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 modifyaggStar
- Aggregate table, or null if query is against fact tablerestrictMemberTypes
- defines the behavior if the current context contains calculated members. If true, thows an exception.evaluator
- Evaluator
-
useTupleSlicer
-
getRolesConstraints
-
isDisjointTuple
-
hasMultipleLevelSlicer
-
getColumnExpr
Get the column expression from the AggStar if provided or the regular table if not, and ensure table is in From -
getRoleConstraintMembers
public static Map<Level,List<RolapMember>> getRoleConstraintMembers(SchemaReader schemaReader, Member[] members) -
hasMultiPositionSlicer
-
expandSupportedCalculatedMembers
public static TupleConstraintStruct expandSupportedCalculatedMembers(List<Member> members, Evaluator evaluator) -
expandSupportedCalculatedMembers
public static TupleConstraintStruct expandSupportedCalculatedMembers(List<Member> members, Evaluator evaluator, boolean disjointSlicerTuples) -
expandSupportedCalculatedMember
public static void expandSupportedCalculatedMember(Member member, Evaluator evaluator, TupleConstraintStruct expandedSet) -
expandSupportedCalculatedMember
public static void expandSupportedCalculatedMember(Member member, Evaluator evaluator, boolean disjointSlicerTuples, TupleConstraintStruct expandedSet) -
expandExpressions
public static void expandExpressions(Member member, Exp expression, Evaluator evaluator, TupleConstraintStruct expandedSet) -
isSupportedCalculatedMember
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
-
expandSetFromCalculatedMember
public static void expandSetFromCalculatedMember(Evaluator evaluator, Member member, TupleConstraintStruct expandedSet) -
getUniqueOrdinalMembers
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
-
containsCalculatedMember
-
containsCalculatedMember
-
joinLevelTableToFactTable
public static void joinLevelTableToFactTable(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, Evaluator e, RolapCubeLevel level) Ensures that the table oflevel
is joined to the fact table- Parameters:
sqlQuery
- sql query under constructionaggStar
- The aggStar to use, if any.e
- evaluator corresponding to querylevel
- 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 modifybaseCube
- base cube if virtualaggStar
- Definition of the aggregate table, or nullparent
- the list of parent membersrestrictMemberTypes
- defines the behavior ifparent
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 modifybaseCube
- base cube if virtualaggStar
- (not used)members
- the list of members for this constraintrestrictMemberTypes
- defines the behavior ifparents
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 crossjoinexclude
- whether to exclude the members in the SQL predicate. e.g. not in { member list}.
-
constrainLevel
-
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 levelquery
- the query that the sql expression will be added tobaseCube
- base cube for virtual levelsaggStar
- aggregate star if availablecolumnValue
- value constraining the levelcaseSensitive
- 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 expressiondatatype
- Key datatypequery
- the query that the sql expression will be added tocolumnValue
- value constraining the level- Returns:
- generated string corresponding to the expression
-
measuresConflictWithMembers
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
-
measuresConflictWithMembers
public static boolean measuresConflictWithMembers(Set<Member> measuresMembers, CrossJoinArg[] cjArgs) -
containsValidMeasure
-