Expression

An expression is a operation, a value, or a function in a query.

Methods
static Expression[] getExpressionColumns(Session session, ValueArray value)
Extracts expression columns from ValueArray
static Expression[] getExpressionColumns(Session session, ValueArray value)
Extracts expression columns from ValueArray
Parameters:
session - the current session
value - the value to extract columns from
Returns:
array of expression columns
static Expression[] getExpressionColumns(Session session, ResultSet rs)
Extracts expression columns from the given result set.
static Expression[] getExpressionColumns(Session session, ResultSet rs)
Extracts expression columns from the given result set.
Parameters:
session - the session
rs - the result set
Returns:
an array of expression columns
void addFilterConditions(TableFilter filter, boolean outerJoin)
Add conditions to a table filter if they can be evaluated.
void addFilterConditions(TableFilter filter, boolean outerJoin)
Add conditions to a table filter if they can be evaluated.
Parameters:
filter - the table filter
outerJoin - if the expression is part of an outer join
void createIndexConditions(Session session, TableFilter filter)
Create index conditions if possible and attach them to the table filter.
void createIndexConditions(Session session, TableFilter filter)
Create index conditions if possible and attach them to the table filter.
Parameters:
session - the session
filter - the table filter
String getAlias()
Get the alias name of a column or SQL expression if it is not an aliased expression.
String getAlias()
Get the alias name of a column or SQL expression if it is not an aliased expression.
Returns:
the alias name
boolean getBooleanValue(Session session)
Get the value in form of a boolean expression.
boolean getBooleanValue(Session session)
Get the value in form of a boolean expression. Returns true or false. In this database, everything can be a condition.
Parameters:
session - the session
Returns:
the result
String getColumnName()
Get the column name or alias name of this expression.
String getColumnName()
Get the column name or alias name of this expression.
Returns:
the column name
int getCost()
Estimate the cost to process the expression.
int getCost()
Estimate the cost to process the expression. Used when optimizing the query, to calculate the query plan with the lowest estimated cost.
Returns:
the estimated cost
int getDisplaySize()
Get the display size of this expression.
int getDisplaySize()
Get the display size of this expression.
Returns:
the display size
Expression[] getExpressionColumns(Session session)
If this expression consists of column expressions it should return them.
Expression[] getExpressionColumns(Session session)
If this expression consists of column expressions it should return them.
Parameters:
session - the session
Returns:
array of expression columns if applicable, null otherwise
Expression getNonAliasExpression()
Returns the main expression, skipping aliases.
Expression getNonAliasExpression()
Returns the main expression, skipping aliases.
Returns:
the expression
Expression getNotIfPossible(Session session)
If it is possible, return the negated expression.
Expression getNotIfPossible(Session session)
If it is possible, return the negated expression. This is used to optimize NOT expressions: NOT ID>10 can be converted to ID<=10. Returns null if negating is not possible.
Parameters:
session - the session
Returns:
the negated expression, or null
int getNullable()
Check whether this expression is a column and can store NULL.
int getNullable()
Check whether this expression is a column and can store NULL.
Returns:
whether NULL is allowed
long getPrecision()
Get the precision of this expression.
long getPrecision()
Get the precision of this expression.
Returns:
the precision
String getSQL()
Get the SQL statement of this expression.
String getSQL()
Get the SQL statement of this expression. This may not always be the original SQL statement, specially after optimization.
Returns:
the SQL statement
int getScale()
Get the scale of this expression.
int getScale()
Get the scale of this expression.
Returns:
the scale
String getSchemaName()
Get the schema name, or null
String getSchemaName()
Get the schema name, or null
Returns:
the schema name
String getTableAlias()
Get the table alias name or null if this expression does not represent a column.
String getTableAlias()
Get the table alias name or null if this expression does not represent a column.
Returns:
the table alias name
String getTableName()
Get the table name, or null
String getTableName()
Get the table name, or null
Returns:
the table name
int getType()
Return the data type.
int getType()
Return the data type. The data type may not be known before the optimization phase.
Returns:
the type
Value getValue(Session session)
Return the resulting value for the current row.
Value getValue(Session session)
Return the resulting value for the current row.
Parameters:
session - the session
Returns:
the result
boolean isAutoIncrement()
Check if this is an auto-increment column.
boolean isAutoIncrement()
Check if this is an auto-increment column.
Returns:
true if it is an auto-increment column
boolean isConstant()
Check if this expression will always return the same value.
boolean isConstant()
Check if this expression will always return the same value.
Returns:
if the expression is constant
boolean isEverything(ExpressionVisitor visitor)
Check if this expression and all sub-expressions can fulfill a criteria.
boolean isEverything(ExpressionVisitor visitor)
Check if this expression and all sub-expressions can fulfill a criteria. If any part returns false, the result is false.
Parameters:
visitor - the visitor
Returns:
if the criteria can be fulfilled
boolean isValueSet()
Is the value of a parameter set.
boolean isValueSet()
Is the value of a parameter set.
Returns:
true if set
boolean isWildcard()
Only returns true if the expression is a wildcard.
boolean isWildcard()
Only returns true if the expression is a wildcard.
Returns:
if this expression is a wildcard
void mapColumns(ColumnResolver resolver, int level)
Map the columns of the resolver to expression columns.
void mapColumns(ColumnResolver resolver, int level)
Map the columns of the resolver to expression columns.
Parameters:
resolver - the column resolver
level - the subquery nesting level
Expression optimize(Session session)
Try to optimize the expression.
Expression optimize(Session session)
Try to optimize the expression.
Parameters:
session - the session
Returns:
the optimized expression
void setEvaluatable(TableFilter tableFilter, boolean value)
Tell the expression columns whether the table filter can return values now.
void setEvaluatable(TableFilter tableFilter, boolean value)
Tell the expression columns whether the table filter can return values now. This is used when optimizing the query.
Parameters:
tableFilter - the table filter
value - true if the table filter can return value
String toString()
Convert this expression to a String.
String toString()
Convert this expression to a String.
Returns:
the string representation
void updateAggregate(Session session)
Update an aggregate value.
void updateAggregate(Session session)
Update an aggregate value. This method is called at statement execution time. It is usually called once for each row, but if the expression is used multiple times (for example in the column list, and as part of the HAVING expression) it is called multiple times - the row counter needs to be used to make sure the internal state is only updated once.
Parameters:
session - the session