Package mondrian.olap
Class Query
java.lang.Object
mondrian.olap.QueryPart
mondrian.olap.Query
Query
is an MDX query.
It is created by calling Connection.parseQuery(java.lang.String)
, and executed by calling Connection.execute(mondrian.olap.Query)
, to return
a Result
.
Query control
Most queries are model citizens, executing quickly (often using cached results from previous queries), but som queries take more time, or more database resources, or more results, than is reasonable. Mondrian offers three ways to control rogue queries:
- You can set a query timeout by setting the
MondrianProperties.QueryTimeout
parameter. If the query takes longer to execute than the value of this parameter, the system will kill it. - The
MondrianProperties.QueryLimit
parameter limits the number of cells returned by a query. - At any time while a query is executing, another thread can cancel the query by calling
getStatement()
.cancel()
. The call toConnection.execute(Query)
will throw an exception.
- Author:
- jhyde, 20 January, 1999
-
Nested Class Summary
-
Field Summary
-
Constructor Summary
ConstructorDescriptionQuery
(Statement statement, Cube mdxCube, Formula[] formulas, QueryAxis[] axes, QueryAxis slicerAxis, QueryPart[] cellProps, Parameter[] parameters, boolean strictValidation) Creates a Query.Query
(Statement statement, Formula[] formulas, QueryAxis[] axes, String cube, QueryAxis slicerAxis, QueryPart[] cellProps, boolean strictValidation) Creates a Query. -
Method Summary
Modifier and TypeMethodDescriptionaccept
(MdxVisitor visitor) void
addFormula
(Formula formula) Adds a new formula specifying a member or a set to an existing query; resolve is called after the formula has been added.void
addFormula
(Id id, Exp exp) Adds a new formula specifying a set to an existing query.void
addFormula
(Id id, Exp exp, MemberProperty[] memberProperties) Adds a new formula specifying a member to an existing query.void
addFormulas
(Formula... additions) Adds some number of new formulas specifying members or sets to an existing query; resolve is only called once, after all the new members have been added to the query.void
addLevelToAxis
(AxisOrdinal axis, Level level) Adds a level to an axis expression.void
addMeasuresMembers
(OlapElement olapElement) Keeps track of references to members of the measures dimensionvoid
cancel()
Deprecated.This method is deprecated and will be removed in mondrian-4.0boolean
canRemoveFormula
(String uniqueName) Returns whether a formula can safely be removed from the query.void
Deprecated.This method will be removed in mondrian-4.0void
Remove all entries in the evaluation cacheclone()
void
close()
Deprecated.This method will be removed in mondrian-4.0.compileExpression
(Exp exp, boolean scalar, ResultStyle resultStyle) Compiles an expression, using a cached compiled expression if available.createScopedNamedSet
(String name, QueryPart scope, Exp expr) Creates a named set defined by an alias.Creates a validator for this query.createValidator
(Map<QueryPart, QueryPart> resolvedIdentifiers) createValidator
(FunTable functionTable, boolean alwaysResolveFunDef) Creates a validator for this query that uses a given function table and function validation policy.createValidator
(FunTable functionTable, boolean alwaysResolveFunDef, Map<QueryPart, QueryPart> resolvedIdentifiers) void
explain
(PrintWriter pw) Returns the plan that Mondrian intends to use to execute this query.findFormula
(String uniqueName) Looks up a calculated member or set defined in this Query.getAxes()
Returns an array of this query's axes.return the set of base cubes associated with the virtual cube referenced in this queryObject[]
getCube()
getEvalCache
(String key) Gets the Object associated with the value.Formula[]
Returns an array of the formulas used in this query.ReturnsHierarchy[]
used onaxis
.Returns the parameters defined in this query.long
Deprecated.getSchemaReader
(boolean accessControlled) Returns a schema reader.boolean
hasCellProperty
(String propertyName) Checks whether the property name is present in the query.boolean
boolean
Checks whether any cell property present in the querylookupMemberFromCache
(String memberUniqueName) Looks up a member whose unique name ismemberUniqueName
from cache.boolean
void
putEvalCache
(String key, Object value) Put an Object value into the evaluation cache with given key.void
removeFormula
(String uniqueName, boolean failIfUsedInQuery) Remove a formula from the query.void
renameFormula
(String uniqueName, String newName) Finds formula by name and renames it to new name.void
resolve()
Performs type-checking and validates internal consistency of a query, using the default resolver.void
Performs type-checking and validates internal consistency of a query.Deprecated.Please useclone()
; this method will be removed in mondrian-4.0void
setAxisShowEmptyCells
(int axis, boolean showEmpty) Finds axis by index and sets flag to show empty cells on that axis.void
setBaseCubes
(List<RolapCube> baseCubes) Saves away the base cubes related to the virtual cube referenced in this queryvoid
setOwnStatement
(boolean ownStatement) Sets that the query owns its statement; therefore it will need to close it when the query is closed.void
setParameter
(String parameterName, Object value) Assigns a value to the parameter with a given name.void
setQueryTimeoutMillis
(long queryTimeoutMillis) Deprecated.This method will be removed in mondrian-4.0void
setResultStyle
(ResultStyle resultStyle) A Query's ResultStyle can only be one of the following: ResultStyle.ITERABLE ResultStyle.LIST ResultStyle.MUTABLE_LISTvoid
setSlicerAxis
(QueryAxis axis) void
Indicates that the query cannot use native cross joins to process this virtual cubeboolean
shouldAlertForNonNative
(FunDef funDef) Determines whether an alert for non-native evaluation needs to be posted.void
swapAxes()
Swaps the x- and y- axes.toString()
Returns the MDX query string.void
unparse
(PrintWriter pw) Writes a string representation of this parse tree node to the given writer.
-
Field Details
-
axes
public-private: This must be public because it is still accessed in rolap.RolapConnection -
axisCalcs
-
slicerCalc
-
-
Constructor Details
-
Query
public Query(Statement statement, Formula[] formulas, QueryAxis[] axes, String cube, QueryAxis slicerAxis, QueryPart[] cellProps, boolean strictValidation) Creates a Query. -
Query
public Query(Statement statement, Cube mdxCube, Formula[] formulas, QueryAxis[] axes, QueryAxis slicerAxis, QueryPart[] cellProps, Parameter[] parameters, boolean strictValidation) Creates a Query.
-
-
Method Details
-
setQueryTimeoutMillis
public void setQueryTimeoutMillis(long queryTimeoutMillis) Deprecated.This method will be removed in mondrian-4.0Sets the timeout in milliseconds of this Query.Zero means no timeout.
- Parameters:
queryTimeoutMillis
- Timeout in milliseconds
-
hasCellProperty
Checks whether the property name is present in the query. -
isCellPropertyEmpty
public boolean isCellPropertyEmpty()Checks whether any cell property present in the query -
addFormula
Adds a new formula specifying a set to an existing query. -
addFormula
Adds a new formula specifying a member to an existing query.- Parameters:
id
- Name of memberexp
- Expression for membermemberProperties
- Properties of member
-
addFormula
Adds a new formula specifying a member or a set to an existing query; resolve is called after the formula has been added.- Parameters:
formula
- Formula to add to query
-
addFormulas
Adds some number of new formulas specifying members or sets to an existing query; resolve is only called once, after all the new members have been added to the query.- Parameters:
additions
- Formulas to add to query
-
createValidator
Creates a validator for this query.- Returns:
- Validator
-
createValidator
-
createValidator
Creates a validator for this query that uses a given function table and function validation policy.- Parameters:
functionTable
- Function tablealwaysResolveFunDef
- Whether to always resolve function definitions (seeValidator.alwaysResolveFunDef()
)- Returns:
- Validator
-
createValidator
-
safeClone
Deprecated.Please useclone()
; this method will be removed in mondrian-4.0 -
clone
-
getConnection
-
cancel
public void cancel()Deprecated.This method is deprecated and will be removed in mondrian-4.0Issues a cancel request on this Query object. Once the thread running the query detects the cancel request, the query execution will throw an exception. SeeBasicQueryTest.testCancel
for an example of usage of this method. -
checkCancelOrTimeout
public void checkCancelOrTimeout()Deprecated.This method will be removed in mondrian-4.0Checks if either a cancel request has been issued on the query or the execution time has exceeded the timeout value (if one has been set). Exceptions are raised if either of these two conditions are met. This method should be called periodically during query execution to ensure timely detection of these events, particularly before/after any potentially long running operations. -
getQueryStartTime
public long getQueryStartTime()Deprecated.UseExecution.getStartTime()
. This method is deprecated and will be removed in mondrian-4.0Gets the query start time- Returns:
- start time
-
shouldAlertForNonNative
Determines whether an alert for non-native evaluation needs to be posted.- Parameters:
funDef
- function type to alert for- Returns:
- true if alert should be raised
-
resolve
public void resolve()Performs type-checking and validates internal consistency of a query, using the default resolver.This method is called automatically when a query is created; you need to call this method manually if you have modified the query's expression tree in any way.
-
ignoreInvalidMembers
public boolean ignoreInvalidMembers()- Returns:
- true if the relevant property for ignoring invalid members is set to true for this query's environment (a different property is checked depending on whether environment is schema load vs query validation)
-
setResultStyle
A Query's ResultStyle can only be one of the following: ResultStyle.ITERABLE ResultStyle.LIST ResultStyle.MUTABLE_LIST -
getResultStyle
-
resolve
Performs type-checking and validates internal consistency of a query.- Parameters:
validator
- Validator
-
explain
Description copied from class:QueryPart
Returns the plan that Mondrian intends to use to execute this query. -
unparse
Description copied from class:QueryPart
Writes a string representation of this parse tree node to the given writer. -
toString
Returns the MDX query string. -
getChildren
- Overrides:
getChildren
in classQueryPart
-
getSlicerAxis
-
setSlicerAxis
-
addLevelToAxis
Adds a level to an axis expression. -
setParameter
Assigns a value to the parameter with a given name.- Throws:
RuntimeException
- if there is not parameter with the given name
-
swapAxes
public void swapAxes()Swaps the x- and y- axes. Does nothing if the number of axes != 2. -
getParameters
Returns the parameters defined in this query. -
getCube
-
getSchemaReader
Returns a schema reader.- Parameters:
accessControlled
- If true, schema reader returns only elements which are accessible to the statement's current role- Returns:
- schema reader
-
lookupMemberFromCache
Looks up a member whose unique name ismemberUniqueName
from cache. If the member is not in cache, returns null. -
createScopedNamedSet
Creates a named set defined by an alias. -
getFormulas
Returns an array of the formulas used in this query. -
getAxes
Returns an array of this query's axes. -
removeFormula
Remove a formula from the query. IffailIfUsedInQuery
is true, checks and throws an error if formula is used somewhere in the query. -
canRemoveFormula
Returns whether a formula can safely be removed from the query. It can be removed if the member or set it defines it not used anywhere else in the query, including in another formula.- Parameters:
uniqueName
- Unique name of the member or set defined by the formula- Returns:
- whether the formula can safely be removed
-
findFormula
Looks up a calculated member or set defined in this Query.- Parameters:
uniqueName
- Unique name of calculated member or set- Returns:
- formula defining calculated member, or null if not found
-
renameFormula
Finds formula by name and renames it to new name. -
setAxisShowEmptyCells
public void setAxisShowEmptyCells(int axis, boolean showEmpty) Finds axis by index and sets flag to show empty cells on that axis. -
getMdxHierarchiesOnAxis
ReturnsHierarchy[]
used onaxis
. It callscollectHierarchies(mondrian.olap.Exp)
. -
compileExpression
Compiles an expression, using a cached compiled expression if available.- Parameters:
exp
- Expressionscalar
- Whether expression is scalarresultStyle
- Preferred result style; if null, use query's default result style; ignored if expression is scalar- Returns:
- compiled expression
-
createCompiler
-
addMeasuresMembers
Keeps track of references to members of the measures dimension- Parameters:
olapElement
- potential measure member
-
getMeasuresMembers
- Returns:
- set of members from the measures dimension referenced within this query
-
setVirtualCubeNonNativeCrossJoin
public void setVirtualCubeNonNativeCrossJoin()Indicates that the query cannot use native cross joins to process this virtual cube -
nativeCrossJoinVirtualCube
public boolean nativeCrossJoinVirtualCube()- Returns:
- true if the query can use native cross joins on a virtual cube
-
setBaseCubes
Saves away the base cubes related to the virtual cube referenced in this query- Parameters:
baseCubes
- set of base cubes
-
getBaseCubes
return the set of base cubes associated with the virtual cube referenced in this query- Returns:
- set of base cubes
-
accept
-
putEvalCache
Put an Object value into the evaluation cache with given key. This is used by Calc's to store information between iterations (rather than re-generate each time).- Parameters:
key
- the cache keyvalue
- the cache value
-
getEvalCache
Gets the Object associated with the value.- Parameters:
key
- the cache key- Returns:
- the cached value or null.
-
clearEvalCache
public void clearEvalCache()Remove all entries in the evaluation cache -
close
public void close()Deprecated.This method will be removed in mondrian-4.0.Closes this query.Releases any resources held. Writes statistics to log if profiling is enabled.
This method is idempotent.
-
getStatement
-
setOwnStatement
public void setOwnStatement(boolean ownStatement) Sets that the query owns its statement; therefore it will need to close it when the query is closed.- Parameters:
ownStatement
- Whether the statement belongs to the query
-