Top Description Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class OrderByColumn

extends OrderedColumn
Class Inheritance
Imports
org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.Visitor

An OrderByColumn is a column in the ORDER BY clause. An OrderByColumn can be ordered ascending or descending. We need to make sure that the named columns are columns in that query, and that positions are within range.

Field Summary

Modifier and TypeField and Description
private int
addedColumnOffset

If this sort key is added to the result column list then it is at result column position 1 + resultColumnList.size() - resultColumnList.getOrderBySelect() + addedColumnOffset If the sort key is already in the result column list then addedColumnOffset < 0.

private boolean
private ValueNode
private OrderByList
private boolean
private ResultColumn
Inherited from org.apache.derby.impl.sql.compile.OrderedColumn:
columnPositionUNMATCHEDPOSITION

Constructor Summary

AccessConstructor and Description
pack-priv
OrderByColumn(ValueNode
Expression of this column
expression
,
ContextManager
The context manager
cm
)

Constructor.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.acceptChildren.

Accept the visitor for all visitable children of this node.

pack-priv void
bindOrderByColumn(ResultSetNode
The result set being selected from
target
,
OrderByList
OrderByList which contains this column
oblist
)

Bind this column.

pack-priv void
clearAddedColumnOffset()

Reset addedColumnOffset to indicate that column is no longer added An added column is one which was artificially added to the result column list due to its presence in the ORDER BY clause, as opposed to having been explicitly selected by the user.

pack-priv void
collapseAddedColumnGap(int
offset of the column which has just been removed from list
gap
)

Adjust addedColumnOffset to reflect that a column has been removed This routine is called when a previously-added result column has been removed due to being detected as a duplicate.

private boolean

Returns:

whether a match found or not
columnMatchFound
(ResultSetNode
result set
target
,
ColumnReference
the CR to be checked
crOfExpression
)

This method checks a ColumnReference of this OrderByColumn against the ColumnReferences of the select clause of the query.

pack-priv boolean
constantColumn(PredicateList whereClause)

Is this OrderByColumn constant, according to the given predicate list?

private boolean

Returns:

boolean: whether any expression match found
expressionMatch
(ResultSetNode
Result set
target
)

Checks whether the whole expression (OrderByColumn) itself found in the select clause.

pack-priv ValueNode
pack-priv ValueNode
getNonRedundantExpression()

Get the underlying expression, skipping over ResultColumns that are marked redundant.

pack-priv ResultColumn

Returns:

The underlying ResultColumn.
getResultColumn
()

Get the underlying ResultColumn.

pack-priv boolean

Returns:

true if ascending, false if descending
isAscending
()

Overrides org.apache.derby.impl.sql.compile.OrderedColumn.isAscending.

Get the column order.

pack-priv boolean

Returns:

true if NULLs ordered low, false if NULLs ordered high
isNullsOrderedLow
()

Overrides org.apache.derby.impl.sql.compile.OrderedColumn.isNullsOrderedLow.

Get the column NULL ordering.

private static boolean
pack-priv void
printSubNodes(int
The depth of this node in the tree
depth
)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.printSubNodes.

Prints the sub-nodes of this object.

pack-priv void
pullUpOrderByColumn(ResultSetNode
The result set being selected from
target
)

Pull up this orderby column if it doesn't appear in the resultset

pack-priv void
remapColumnReferencesToExpressions()

Remap all the column references under this OrderByColumn to their expressions.

pack-priv void
resetToSourceRC()

Order by columns now point to the PRN above the node of interest.

private void
resolveAddedColumn(ResultSetNode target)

Assuming this OrderByColumn was "pulled" into the received target's ResultColumnList (because it wasn't there to begin with), use this.addedColumnOffset to figure out which of the target's result columns is the one corresponding to "this".

private ResultColumn
pack-priv void
setDescending()

Mark the column as descending order

pack-priv void
setNullsOrderedLow()

Mark the column as ordered NULL values lower than non-NULL values.

public String

Returns:

This object as a String
toString
()

Overrides org.apache.derby.impl.sql.compile.OrderedColumn.toString.

Convert this object to a String.

Inherited from org.apache.derby.impl.sql.compile.OrderedColumn:
getColumnPositionsetColumnPosition

Field Detail

addedColumnOffsetback to summary
private int addedColumnOffset

If this sort key is added to the result column list then it is at result column position 1 + resultColumnList.size() - resultColumnList.getOrderBySelect() + addedColumnOffset If the sort key is already in the result column list then addedColumnOffset < 0.

ascendingback to summary
private boolean ascending
expressionback to summary
private ValueNode expression
listback to summary
private OrderByList list
nullsOrderedLowback to summary
private boolean nullsOrderedLow
resultColback to summary
private ResultColumn resultCol

Constructor Detail

OrderByColumnback to summary
pack-priv OrderByColumn(ValueNode expression, ContextManager cm)

Constructor.

Parameters
expression:ValueNode

Expression of this column

cm:ContextManager

The context manager

Method Detail

acceptChildrenback to summary
pack-priv void acceptChildren(Visitor v) throws StandardException

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.acceptChildren.

Accept the visitor for all visitable children of this node.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on error
bindOrderByColumnback to summary
pack-priv void bindOrderByColumn(ResultSetNode target, OrderByList oblist) throws StandardException

Bind this column. During binding, we may discover that this order by column was pulled up into the result column list, but is now a duplicate, because the actual result column was expanded into the result column list when "*" expressions were replaced with the list of the table's columns. In such a situation, we will end up calling back to the OrderByList to adjust the addedColumnOffset values of the columns; the "oblist" parameter exists to allow that callback to be performed.

Parameters
target:ResultSetNode

The result set being selected from

oblist:OrderByList

OrderByList which contains this column

Exceptions
StandardException:
  • Thrown on error
  • Thrown when column not found
clearAddedColumnOffsetback to summary
pack-priv void clearAddedColumnOffset()

Reset addedColumnOffset to indicate that column is no longer added An added column is one which was artificially added to the result column list due to its presence in the ORDER BY clause, as opposed to having been explicitly selected by the user. Since * is not expanded until after the ORDER BY columns have been pulled up, we may add a column, then later decide it is a duplicate of an explicitly selected column. In that case, this method is called, and it does the following: - resets addedColumnOffset to -1 to indicate this is not an added col - calls back to the OrderByList to adjust any other added cols

collapseAddedColumnGapback to summary
pack-priv void collapseAddedColumnGap(int gap)

Adjust addedColumnOffset to reflect that a column has been removed This routine is called when a previously-added result column has been removed due to being detected as a duplicate. If that added column had a lower offset than our column, we decrement our offset to reflect that we have just been moved down one slot in the result column list.

Parameters
gap:int

offset of the column which has just been removed from list

columnMatchFoundback to summary
private boolean columnMatchFound(ResultSetNode target, ColumnReference crOfExpression) throws StandardException

This method checks a ColumnReference of this OrderByColumn against the ColumnReferences of the select clause of the query.

Parameters
target:ResultSetNode

result set

crOfExpression:ColumnReference

the CR to be checked

Returns:boolean

whether a match found or not

constantColumnback to summary
pack-priv boolean constantColumn(PredicateList whereClause)

Is this OrderByColumn constant, according to the given predicate list? A constant column is one where all the column references it uses are compared equal to constants.

expressionMatchback to summary
private boolean expressionMatch(ResultSetNode target) throws StandardException

Checks whether the whole expression (OrderByColumn) itself found in the select clause.

Parameters
target:ResultSetNode

Result set

Returns:boolean

boolean: whether any expression match found

getExpressionback to summary
pack-priv ValueNode getExpression()
getNonRedundantExpressionback to summary
pack-priv ValueNode getNonRedundantExpression()

Get the underlying expression, skipping over ResultColumns that are marked redundant.

getResultColumnback to summary
pack-priv ResultColumn getResultColumn()

Get the underlying ResultColumn.

Returns:ResultColumn

The underlying ResultColumn.

isAscendingback to summary
pack-priv boolean isAscending()

Overrides org.apache.derby.impl.sql.compile.OrderedColumn.isAscending.

Get the column order. Overrides OrderedColumn.isAscending.

Returns:boolean

true if ascending, false if descending

Annotations
@Override
isNullsOrderedLowback to summary
pack-priv boolean isNullsOrderedLow()

Overrides org.apache.derby.impl.sql.compile.OrderedColumn.isNullsOrderedLow.

Get the column NULL ordering. Overrides OrderedColumn.getIsNullsOrderedLow.

Returns:boolean

true if NULLs ordered low, false if NULLs ordered high

Annotations
@Override
isReferedColByNumback to summary
private static boolean isReferedColByNum(ValueNode expression) throws StandardException
printSubNodesback to summary
pack-priv void printSubNodes(int depth)

Overrides org.apache.derby.impl.sql.compile.QueryTreeNode.printSubNodes.

Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Parameters
depth:int

The depth of this node in the tree

Annotations
@Override
pullUpOrderByColumnback to summary
pack-priv void pullUpOrderByColumn(ResultSetNode target) throws StandardException

Pull up this orderby column if it doesn't appear in the resultset

Parameters
target:ResultSetNode

The result set being selected from

remapColumnReferencesToExpressionsback to summary
pack-priv void remapColumnReferencesToExpressions() throws StandardException

Remap all the column references under this OrderByColumn to their expressions.

Exceptions
StandardException:
Thrown on error
resetToSourceRCback to summary
pack-priv void resetToSourceRC()

Order by columns now point to the PRN above the node of interest. We need them to point to the RCL under that one. This is useful when combining sorts where we need to reorder the sorting columns.

resolveAddedColumnback to summary
private void resolveAddedColumn(ResultSetNode target)

Assuming this OrderByColumn was "pulled" into the received target's ResultColumnList (because it wasn't there to begin with), use this.addedColumnOffset to figure out which of the target's result columns is the one corresponding to "this". The desired position is w.r.t. the original, user-specified result column list--which is what "visibleSize()" gives us. I.e. To get this OrderByColumn's position in target's RCL, first subtract out all columns which were "pulled" into the RCL for GROUP BY or ORDER BY, then add "this.addedColumnOffset". As an example, if the query was: select sum(j) as s from t1 group by i, k order by k, sum(k) then we will internally add columns "K" and "SUM(K)" to the RCL for ORDER BY, *AND* we will add a generated column "I" to the RCL for GROUP BY. Thus we end up with four result columns: (1) (2) (3) (4) select sum(j) as s, K, SUM(K), I from t1 ... So when we get here and we want to find out which column "this" corresponds to, we begin by taking the total number of VISIBLE columns, which is 1 (i.e. 4 total columns minus 1 GROUP BY column minus 2 ORDER BY columns). Then we add this.addedColumnOffset in order to find the target column position. Since addedColumnOffset is 0-based, an addedColumnOffset value of "0" means we want the the first ORDER BY column added to target's RCL, "1" means we want the second ORDER BY column added, etc. So if we assume that this.addedColumnOffset is "1" in this example then we add that to the RCL's "visible size". And finally, we add 1 more to account for fact that addedColumnOffset is 0-based while column positions are 1-based. This gives: position = 1 + 1 + 1 = 3 which points to SUM(K) in the RCL. Thus an addedColumnOffset value of "1" resolves to column SUM(K) in target's RCL; similarly, an addedColumnOffset value of "0" resolves to "K". DERBY-3303.

resolveColumnReferenceback to summary
private ResultColumn resolveColumnReference(ResultSetNode target, ColumnReference cr) throws StandardException
setDescendingback to summary
pack-priv void setDescending()

Mark the column as descending order

setNullsOrderedLowback to summary
pack-priv void setNullsOrderedLow()

Mark the column as ordered NULL values lower than non-NULL values.

toStringback to summary
public String toString()

Overrides org.apache.derby.impl.sql.compile.OrderedColumn.toString.

Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Returns:String

This object as a String

Annotations
@Override