Package mondrian.rolap
Class SqlConstraintUtils
- java.lang.Object
-
- mondrian.rolap.SqlConstraintUtils
-
public class SqlConstraintUtils extends Object
Utility class used by implementations ofSqlConstraint, used to generate constraints intoSqlQuery.- Since:
- Nov 21, 2005
- Author:
- av
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddContextConstraint(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 voidaddMemberConstraint(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 voidaddMemberConstraint(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, RolapMember parent, boolean restrictMemberTypes)Creates a "WHERE parent = value" constraint.static StringconstrainLevel(RolapLevel level, SqlQuery query, RolapCube baseCube, AggStar aggStar, String[] columnValue, boolean caseSensitive)Generates a sql expression constraining a level by some valuestatic StringconstrainLevel(RolapLevel level, SqlQuery query, RolapCube baseCube, AggStar aggStar, String columnValue, boolean caseSensitive)static StringconstrainLevel2(SqlQuery query, MondrianDef.Expression exp, Dialect.Datatype datatype, Comparable columnValue)Generates a sql expression constraining a level by some valuestatic booleancontainsCalculatedMember(List<Member> members)static booleancontainsCalculatedMember(List<Member> members, boolean allowExpandableMembers)static booleancontainsValidMeasure(Exp... expressions)static voidexpandExpressions(Member member, Exp expression, Evaluator evaluator, TupleConstraintStruct expandedSet)protected static Member[]expandMultiPositionSlicerMembers(Member[] members, Evaluator evaluator)static voidexpandSetFromCalculatedMember(Evaluator evaluator, Member member, TupleConstraintStruct expandedSet)static voidexpandSupportedCalculatedMember(Member member, Evaluator evaluator, boolean disjointSlicerTuples, TupleConstraintStruct expandedSet)static voidexpandSupportedCalculatedMember(Member member, Evaluator evaluator, TupleConstraintStruct expandedSet)static TupleConstraintStructexpandSupportedCalculatedMembers(List<Member> members, Evaluator evaluator)static TupleConstraintStructexpandSupportedCalculatedMembers(List<Member> members, Evaluator evaluator, boolean disjointSlicerTuples)static StringgetColumnExpr(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 Fromstatic Set<Member>getMembersNestedInMeasures(Set<Member> measures)static Map<Level,List<RolapMember>>getRoleConstraintMembers(SchemaReader schemaReader, Member[] members)static Map<RolapLevel,List<RolapMember>>getRolesConstraints(Evaluator evaluator)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 RolapEvaluatorstatic booleanhasMultipleLevelSlicer(Evaluator evaluator)static booleanhasMultiPositionSlicer(List<Member> slicerMembers)static booleanisDisjointTuple(TupleList tupleList)static booleanisSupportedCalculatedMember(Member member)Check to see if this is in a list of supported calculated members.static booleanisSupportedExpressionForCalculatedMember(Exp expression)static voidjoinLevelTableToFactTable(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, Evaluator e, RolapCubeLevel level)Ensures that the table oflevelis joined to the fact tablestatic booleanmeasuresConflictWithMembers(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 booleanmeasuresConflictWithMembers(Set<Member> measuresMembers, CrossJoinArg[] cjArgs)static booleanuseTupleSlicer(RolapEvaluator evaluator)
-
-
-
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 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
public static boolean useTupleSlicer(RolapEvaluator evaluator)
-
getRolesConstraints
public static Map<RolapLevel,List<RolapMember>> getRolesConstraints(Evaluator 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
-
getRoleConstraintMembers
public static Map<Level,List<RolapMember>> getRoleConstraintMembers(SchemaReader schemaReader, Member[] members)
-
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
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)
-
expandSetFromCalculatedMember
public static void expandSetFromCalculatedMember(Evaluator evaluator, Member member, TupleConstraintStruct expandedSet)
-
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, boolean allowExpandableMembers)
-
joinLevelTableToFactTable
public static void joinLevelTableToFactTable(SqlQuery sqlQuery, RolapCube baseCube, AggStar aggStar, Evaluator e, RolapCubeLevel level)
Ensures that the table oflevelis 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 ifparentis 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 ifparentscontains 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
public static String constrainLevel(RolapLevel level, SqlQuery query, RolapCube baseCube, AggStar aggStar, String columnValue, boolean caseSensitive)
-
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
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)
-
-