Top Description Fields Constructors Methods
org.h2.expression

public abstract Class Expression

extends Object
implements HasSQL, Typed
Class Inheritance
All Implemented Interfaces
org.h2.value.Typed, org.h2.util.HasSQL
Known Direct Subclasses
org.h2.expression.ExpressionColumn, org.h2.expression.ExpressionList, org.h2.expression.Operation1, org.h2.expression.Operation1_2, org.h2.expression.Operation2, org.h2.expression.OperationN, org.h2.expression.SimpleCase, org.h2.expression.Subquery, org.h2.expression.Wildcard, org.h2.expression.analysis.DataAnalysisOperation, org.h2.expression.condition.Condition, org.h2.expression.function.Function0_1, org.h2.expression.function.JavaFunction, org.h2.expression.Operation0, org.h2.expression.Alias, org.h2.expression.ArrayConstructorByQuery
Imports
java.util.List, org.h2.api.ErrorCode, org.h2.engine.Constants, .SessionLocal, org.h2.expression.function.NamedExpression, org.h2.message.DbException, org.h2.table.Column, .ColumnResolver, .TableFilter, org.h2.util.HasSQL, .StringUtils, org.h2.value.TypeInfo, .Typed, .Value

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

Field Summary

Modifier and TypeField and Description
private boolean
public static final int
AUTO_PARENTHESES

Wrap expression in parentheses only if it can't be safely included into other expressions without them.

public static final int
MAP_IN_AGGREGATE

State for expressions inside an aggregate for mapColumns(ColumnResolver, int, int).

public static final int
MAP_IN_WINDOW

State for expressions inside a window function for mapColumns(ColumnResolver, int, int).

public static final int
public static final int
WITH_PARENTHESES

Wrap expression in parentheses unconditionally.

public static final int
WITHOUT_PARENTHESES

Do not wrap expression in parentheses.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addFilterConditions(TableFilter
the table filter
filter
)

Add conditions to a table filter if they can be evaluated.

public void
createIndexConditions(SessionLocal
the session
session
,
TableFilter
the table filter
filter
)

Create index conditions if possible and attach them to the table filter.

public String

Returns:

the alias name
getAlias
(SessionLocal
the session
session
,
int
0-based column index
columnIndex
)

Get the alias name of a column or SQL expression if it is not an aliased expression.

public boolean

Returns:

the result
getBooleanValue
(SessionLocal
the session
session
)

Get the value in form of a boolean expression.

public String

Returns:

the column name
getColumnName
(SessionLocal
the session
session
,
int
0-based column index
columnIndex
)

Get the column name or alias name of this expression.

public String

Returns:

the column name for a view
getColumnNameForView
(SessionLocal
the session
session
,
int
0-based column index
columnIndex
)

Get the column name of this expression for a view.

public abstract int

Returns:

the estimated cost
getCost
()

Estimate the cost to process the expression.

public final StringBuilder

Returns:

the specified string builder
getEnclosedSQL
(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Get the SQL statement of this expression.

public Expression

Returns:

the expression
getNonAliasExpression
()

Returns the main expression, skipping aliases.

public Expression

Returns:

the negated expression, or null
getNotIfPossible
(SessionLocal
the session
session
)

If it is possible, return the negated expression.

public int

Returns:

whether NULL is allowed
getNullable
()

Check whether this expression is a column and can store NULL.

public String

Returns:

the schema name
getSchemaName
()

Get the schema name, or null

public final String
getSQL(int
formatting flags
sqlFlags
)

Overrides default org.h2.util.HasSQL.getSQL.

Get the SQL statement of this expression.

public final StringBuilder
getSQL(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Implements org.h2.util.HasSQL.getSQL.

Appends the SQL statement of this object to the specified builder.

public final String

Returns:

the SQL statement
getSQL
(int
formatting flags
sqlFlags
,
int
parentheses mode
parentheses
)

Get the SQL statement of this expression.

public final StringBuilder

Returns:

the specified string builder
getSQL
(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
,
int
parentheses mode
parentheses
)

Get the SQL statement of this expression.

public Expression

Returns:

subexpression with specified index, may be null
getSubexpression
(int
0-based index
index
)

Returns subexpression with specified index.

public int

Returns:

count of subexpressions
getSubexpressionCount
()

Returns count of subexpressions.

public String

Returns:

the table alias name
getTableAlias
()

Get the table alias name or null if this expression does not represent a column.

public String

Returns:

the table name
getTableName
()

Get the table name, or null

public abstract TypeInfo

Returns:

the data type
getType
()

Redeclares org.h2.value.Typed.getType.

Returns the data type.

public TypeInfo

Returns:

data type or null
getTypeIfStaticallyKnown
(SessionLocal
the session
session
)

Returns data type of this expression if it is statically known.

public abstract StringBuilder

Returns:

the specified string builder
getUnenclosedSQL
(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Get the SQL statement of this expression.

public abstract Value

Returns:

the result
getValue
(SessionLocal
the session
session
)

Return the resulting value for the current row.

public StringBuilder

Returns:

the specified string builder
getWhenSQL
(StringBuilder
string builder
builder
,
int
formatting flags
sqlFlags
)

Appends the SQL statement of this when operand to the specified builder.

public boolean

Returns:

the result
getWhenValue
(SessionLocal
the session
session
,
Value
value on the left side
left
)

Return the resulting value of when operand for the current row.

public boolean

Returns:

if the expression is constant
isConstant
()

Check if this expression will always return the same value.

public abstract boolean

Returns:

if the criteria can be fulfilled
isEverything
(ExpressionVisitor
the visitor
visitor
)

Check if this expression and all sub-expressions can fulfill a criteria.

public boolean

Returns:

true if it is an identity column
isIdentity
()

Check if this is an identity column.

public boolean

Returns:

if the expression is constant NULL value
isNullConstant
()

Check if this expression will always return the NULL value.

public boolean

Returns:

true if set
isValueSet
()

Is the value of a parameter set.

public boolean

Returns:

true if it is, false otherwise
isWhenConditionOperand
()

Returns whether this expression is a right side of condition in a when operand.

public abstract void
mapColumns(ColumnResolver
the column resolver
resolver
,
int
the subquery nesting level
level
,
int
current state for nesting checks, initial value is MAP_INITIAL
state
)

Map the columns of the resolver to expression columns.

public boolean

Returns:

true if it is
needParentheses
()

Returns whether this expressions needs to be wrapped in parentheses when it is used as an argument of other expressions.

public abstract Expression

Returns:

the optimized expression
optimize
(SessionLocal
the session
session
)

Try to optimize the expression.

public final Expression

Returns:

the optimized condition, or null
optimizeCondition
(SessionLocal
the session
session
)

Try to optimize or remove the condition.

public abstract void
setEvaluatable(TableFilter
the table filter
tableFilter
,
boolean
true if the table filter can return value
value
)

Tell the expression columns whether the table filter can return values now.

public String

Returns:

the string representation
toString
()

Overrides java.lang.Object.toString.

Convert this expression to a String.

public abstract void
updateAggregate(SessionLocal
the session
session
,
int
select stage
stage
)

Update an aggregate value.

public static StringBuilder

Returns:

the specified string builder
writeExpressions
(StringBuilder
the builder to append the SQL to
builder
,
List<? extends Expression>
the list of expressions
expressions
,
int
formatting flags
sqlFlags
)

Get the SQL snippet for a list of expressions.

public static StringBuilder

Returns:

the specified string builder
writeExpressions
(StringBuilder
the builder to append the SQL to
builder
,
Expression[]
the list of expressions
expressions
,
int
formatting flags
sqlFlags
)

Get the SQL snippet for an array of expressions.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

addedToFilterback to summary
private boolean addedToFilter
AUTO_PARENTHESESback to summary
public static final int AUTO_PARENTHESES

Wrap expression in parentheses only if it can't be safely included into other expressions without them.

MAP_IN_AGGREGATEback to summary
public static final int MAP_IN_AGGREGATE

State for expressions inside an aggregate for mapColumns(ColumnResolver, int, int).

MAP_IN_WINDOWback to summary
public static final int MAP_IN_WINDOW

State for expressions inside a window function for mapColumns(ColumnResolver, int, int).

MAP_INITIALback to summary
public static final int MAP_INITIAL

Initial state for mapColumns(ColumnResolver, int, int).

WITH_PARENTHESESback to summary
public static final int WITH_PARENTHESES

Wrap expression in parentheses unconditionally.

WITHOUT_PARENTHESESback to summary
public static final int WITHOUT_PARENTHESES

Do not wrap expression in parentheses.

Constructor Detail

Expressionback to summary
public Expression()

Method Detail

addFilterConditionsback to summary
public void addFilterConditions(TableFilter filter)

Add conditions to a table filter if they can be evaluated.

Parameters
filter:TableFilter

the table filter

createIndexConditionsback to summary
public void createIndexConditions(SessionLocal session, TableFilter filter)

Create index conditions if possible and attach them to the table filter.

Parameters
session:SessionLocal

the session

filter:TableFilter

the table filter

Annotations
@SuppressWarnings:unused
getAliasback to summary
public String getAlias(SessionLocal session, int columnIndex)

Get the alias name of a column or SQL expression if it is not an aliased expression.

Parameters
session:SessionLocal

the session

columnIndex:int

0-based column index

Returns:String

the alias name

getBooleanValueback to summary
public boolean getBooleanValue(SessionLocal session)

Get the value in form of a boolean expression. Returns true or false. In this database, everything can be a condition.

Parameters
session:SessionLocal

the session

Returns:boolean

the result

getColumnNameback to summary
public String getColumnName(SessionLocal session, int columnIndex)

Get the column name or alias name of this expression.

Parameters
session:SessionLocal

the session

columnIndex:int

0-based column index

Returns:String

the column name

getColumnNameForViewback to summary
public String getColumnNameForView(SessionLocal session, int columnIndex)

Get the column name of this expression for a view.

Parameters
session:SessionLocal

the session

columnIndex:int

0-based column index

Returns:String

the column name for a view

getCostback to summary
public abstract 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:int

the estimated cost

getEnclosedSQLback to summary
public final StringBuilder getEnclosedSQL(StringBuilder builder, int sqlFlags)

Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are always appended.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

getNonAliasExpressionback to summary
public Expression getNonAliasExpression()

Returns the main expression, skipping aliases.

Returns:Expression

the expression

getNotIfPossibleback to summary
public Expression getNotIfPossible(SessionLocal 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:SessionLocal

the session

Returns:Expression

the negated expression, or null

getNullableback to summary
public int getNullable()

Check whether this expression is a column and can store NULL.

Returns:int

whether NULL is allowed

getSchemaNameback to summary
public String getSchemaName()

Get the schema name, or null

Returns:String

the schema name

getSQLback to summary
public final String getSQL(int sqlFlags)

Overrides default org.h2.util.HasSQL.getSQL.

Doc from org.h2.util.HasSQL.getSQL.

Get the SQL statement of this expression. This may not always be the original SQL statement, specially after optimization.

Parameters
sqlFlags:int

formatting flags

Returns:String

the SQL statement

Annotations
@Override
getSQLback to summary
public final StringBuilder getSQL(StringBuilder builder, int sqlFlags)

Implements org.h2.util.HasSQL.getSQL.

Doc from org.h2.util.HasSQL.getSQL.

Appends the SQL statement of this object to the specified builder.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

Annotations
@Override
getSQLback to summary
public final String getSQL(int sqlFlags, int parentheses)

Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization.

Parameters
sqlFlags:int

formatting flags

parentheses:int

parentheses mode

Returns:String

the SQL statement

getSQLback to summary
public final StringBuilder getSQL(StringBuilder builder, int sqlFlags, int parentheses)

Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

parentheses:int

parentheses mode

Returns:StringBuilder

the specified string builder

getSubexpressionback to summary
public Expression getSubexpression(int index)

Returns subexpression with specified index.

Parameters
index:int

0-based index

Returns:Expression

subexpression with specified index, may be null

Exceptions
IndexOutOfBoundsException:
if specified index is not valid
getSubexpressionCountback to summary
public int getSubexpressionCount()

Returns count of subexpressions.

Returns:int

count of subexpressions

getTableAliasback to summary
public String getTableAlias()

Get the table alias name or null if this expression does not represent a column.

Returns:String

the table alias name

getTableNameback to summary
public String getTableName()

Get the table name, or null

Returns:String

the table name

getTypeback to summary
public abstract TypeInfo getType()

Redeclares org.h2.value.Typed.getType.

Returns the data type. The data type may be unknown before the optimization phase.

Returns:TypeInfo

the data type

Annotations
@Override
getTypeIfStaticallyKnownback to summary
public TypeInfo getTypeIfStaticallyKnown(SessionLocal session)

Returns data type of this expression if it is statically known.

Parameters
session:SessionLocal

the session

Returns:TypeInfo

data type or null

getUnenclosedSQLback to summary
public abstract StringBuilder getUnenclosedSQL(StringBuilder builder, int sqlFlags)

Get the SQL statement of this expression. This may not always be the original SQL statement, especially after optimization. Enclosing '(' and ')' are never appended.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

getValueback to summary
public abstract Value getValue(SessionLocal session)

Return the resulting value for the current row.

Parameters
session:SessionLocal

the session

Returns:Value

the result

getWhenSQLback to summary
public StringBuilder getWhenSQL(StringBuilder builder, int sqlFlags)

Appends the SQL statement of this when operand to the specified builder.

Parameters
builder:StringBuilder

string builder

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

getWhenValueback to summary
public boolean getWhenValue(SessionLocal session, Value left)

Return the resulting value of when operand for the current row.

Parameters
session:SessionLocal

the session

left:Value

value on the left side

Returns:boolean

the result

isConstantback to summary
public boolean isConstant()

Check if this expression will always return the same value.

Returns:boolean

if the expression is constant

isEverythingback to summary
public abstract 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:ExpressionVisitor

the visitor

Returns:boolean

if the criteria can be fulfilled

isIdentityback to summary
public boolean isIdentity()

Check if this is an identity column.

Returns:boolean

true if it is an identity column

isNullConstantback to summary
public boolean isNullConstant()

Check if this expression will always return the NULL value.

Returns:boolean

if the expression is constant NULL value

isValueSetback to summary
public boolean isValueSet()

Is the value of a parameter set.

Returns:boolean

true if set

isWhenConditionOperandback to summary
public boolean isWhenConditionOperand()

Returns whether this expression is a right side of condition in a when operand.

Returns:boolean

true if it is, false otherwise

mapColumnsback to summary
public abstract void mapColumns(ColumnResolver resolver, int level, int state)

Map the columns of the resolver to expression columns.

Parameters
resolver:ColumnResolver

the column resolver

level:int

the subquery nesting level

state:int

current state for nesting checks, initial value is MAP_INITIAL

needParenthesesback to summary
public boolean needParentheses()

Returns whether this expressions needs to be wrapped in parentheses when it is used as an argument of other expressions.

Returns:boolean

true if it is

optimizeback to summary
public abstract Expression optimize(SessionLocal session)

Try to optimize the expression.

Parameters
session:SessionLocal

the session

Returns:Expression

the optimized expression

optimizeConditionback to summary
public final Expression optimizeCondition(SessionLocal session)

Try to optimize or remove the condition.

Parameters
session:SessionLocal

the session

Returns:Expression

the optimized condition, or null

setEvaluatableback to summary
public abstract 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:TableFilter

the table filter

value:boolean

true if the table filter can return value

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Convert this expression to a String.

Returns:String

the string representation

Annotations
@Override
updateAggregateback to summary
public abstract void updateAggregate(SessionLocal session, int stage)

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:SessionLocal

the session

stage:int

select stage

writeExpressionsback to summary
public static StringBuilder writeExpressions(StringBuilder builder, List<? extends Expression> expressions, int sqlFlags)

Get the SQL snippet for a list of expressions.

Parameters
builder:StringBuilder

the builder to append the SQL to

expressions:List<? extends Expression>

the list of expressions

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder

writeExpressionsback to summary
public static StringBuilder writeExpressions(StringBuilder builder, Expression[] expressions, int sqlFlags)

Get the SQL snippet for an array of expressions.

Parameters
builder:StringBuilder

the builder to append the SQL to

expressions:Expression[]

the list of expressions

sqlFlags:int

formatting flags

Returns:StringBuilder

the specified string builder