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

public abstract Class BinaryComparisonOperatorNode

extends BinaryOperatorNode
Class Inheritance
Known Direct Subclasses
org.apache.derby.impl.sql.compile.BinaryRelationalOperatorNode
Imports
java.util.List, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.ClassName, .SQLState, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.types.DataTypeDescriptor, .TypeId

This node is the superclass for all binary comparison operators, such as =, <>, <, etc.

Field Summary

Modifier and TypeField and Description
private boolean
private boolean
Inherited from org.apache.derby.impl.sql.compile.BinaryOperatorNode:
ANDBinaryArgTypesBinaryMethodNamesBinaryOperatorsBinaryResultTypesCONCATENATEDIVIDEEQGEGTK_BASEK_XMLEXISTSK_XMLQUERYkindLEleftInterfaceTypeleftOperandLIKELTmethodNameMINUSNEoperatorORPLUSreceiverresultInterfaceTyperightInterfaceTyperightOperandTIMES

Constructor Summary

AccessConstructor and Description
pack-priv
BinaryComparisonOperatorNode(ValueNode
The left operand of the comparison
leftOperand
,
ValueNode
The right operand of the comparison
rightOperand
,
String
The name of the operator
operator
,
String
The name of the method to call in the generated class
methodName
,
boolean
Can be true only if if this node has been added by an internal rewrite of the query. This allows binding to be more liberal when checking it against allowed syntax. This parameter will be passed FALSE when a new instance of the node is being created(which is the majority of the cases). But when an existing node is getting cloned, the value of this parameter should be passed as the originalNode.getForQueryRewrite(). Examples of this can be found in Predicate.Java and PredicateList.java
forQueryRewrite
,
ContextManager
The context manager
cm
)

Constructor for a BinaryComparisonOperatorNode

Method Summary

Modifier and TypeMethod and Description
pack-priv void
bindComparisonOperator()

Test the type compatability of the operands and set the type info for this node.

pack-priv ValueNode

Returns:

The new top of the expression tree.
bindExpression
(FromList
The query's FROM list
fromList
,
SubqueryList
The subquery list being built as we find SubqueryNodes
subqueryList
,
List<AggregateNode>
The aggregate list being built as we find AggregateNodes
aggregates
)

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression.

Bind this comparison operator.

pack-priv ValueNode

Returns:

The modified expression
changeToCNF
(boolean
Whether or not we are under a top level AndNode.
underTopAndNode
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.changeToCNF.

Finish putting an expression into conjunctive normal form.

pack-priv ValueNode

Returns:

The modified expression
eliminateNots
(boolean
Whether or not we are under a NotNode.
underNotNode
)

Overrides org.apache.derby.impl.sql.compile.ValueNode.eliminateNots.

Eliminate NotNodes in the current query block.

pack-priv ValueNode
genSQLJavaSQLTree()

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.genSQLJavaSQLTree.

generate a SQL->Java->SQL conversion tree above the left and right operand of this Binary Operator Node if needed.

pack-priv boolean

Returns:

Whether or not to use the between selectivity for this node.
getBetweenSelectivity
()

Return whether or not to use the between selectivity for this node.

pack-priv boolean

Returns:

true if it was generated in a query rewrite.
getForQueryRewrite
()

Was this node generated in a query rewrite?

pack-priv abstract BinaryOperatorNode

Returns:

BinaryOperatorNode The negated expression
getNegation
(ValueNode
The left operand of the comparison operator
leftOperand
,
ValueNode
The right operand of the comparison operator
rightOperand
)

Negate the comparison.

pack-priv abstract BinaryOperatorNode

Returns:

an equivalent expression with the operands swapped
getSwappedEquivalent
()

Return a node equivalent to this node, but with the left and right operands swapped.

pack-priv ValueNode

Returns:

The modified expression
preprocess
(int
Number of tables in the DML Statement
numTables
,
FromList
FromList from outer query block
outerFromList
,
SubqueryList
SubqueryList from outer query block
outerSubqueryList
,
PredicateList
PredicateList from outer query block
outerPredicateList
)

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.preprocess.

Preprocess an expression tree.

pack-priv void
setBetweenSelectivity()

Use between selectivity when calculating the selectivity.

pack-priv void
setForQueryRewrite(boolean
true if this was for a query rewrite
val
)

This node was generated as part of a query rewrite.

Inherited from org.apache.derby.impl.sql.compile.BinaryOperatorNode:
acceptChildrenbindXMLQuerycategorizeconstantExpressiongenerateExpressiongetLeftOperandgetOrderableVariantTypegetReceiverInterfaceNamegetRightOperandisConstantExpressionisEquivalentisSameNodeKindprintSubNodesremapColumnReferencesToExpressionssetLeftOperandsetLeftRightInterfaceTypesetMethodNamesetOperatorsetRightOperandtoString

Field Detail

betweenSelectivityback to summary
private boolean betweenSelectivity
forQueryRewriteback to summary
private boolean forQueryRewrite

Constructor Detail

BinaryComparisonOperatorNodeback to summary
pack-priv BinaryComparisonOperatorNode(ValueNode leftOperand, ValueNode rightOperand, String operator, String methodName, boolean forQueryRewrite, ContextManager cm) throws StandardException

Constructor for a BinaryComparisonOperatorNode

Parameters
leftOperand:ValueNode

The left operand of the comparison

rightOperand:ValueNode

The right operand of the comparison

operator:String

The name of the operator

methodName:String

The name of the method to call in the generated class

forQueryRewrite:boolean

Can be true only if if this node has been added by an internal rewrite of the query. This allows binding to be more liberal when checking it against allowed syntax. This parameter will be passed FALSE when a new instance of the node is being created(which is the majority of the cases). But when an existing node is getting cloned, the value of this parameter should be passed as the originalNode.getForQueryRewrite(). Examples of this can be found in Predicate.Java and PredicateList.java

cm:ContextManager

The context manager

Method Detail

bindComparisonOperatorback to summary
pack-priv void bindComparisonOperator() throws StandardException

Test the type compatability of the operands and set the type info for this node. This method is useful both during binding and when we generate nodes within the language module outside of the parser.

Exceptions
StandardException:
Thrown on error
bindExpressionback to summary
pack-priv ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.bindExpression.

Bind this comparison operator. All that has to be done for binding a comparison operator is to bind the operands, check the compatibility of the types, and set the result type to SQLBoolean.

Parameters
fromList:FromList

The query's FROM list

subqueryList:SubqueryList

The subquery list being built as we find SubqueryNodes

aggregates:List<AggregateNode>

The aggregate list being built as we find AggregateNodes

Returns:ValueNode

The new top of the expression tree.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
changeToCNFback to summary
pack-priv ValueNode changeToCNF(boolean underTopAndNode) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.changeToCNF.

Finish putting an expression into conjunctive normal form. An expression tree in conjunctive normal form meets the following criteria: o If the expression tree is not null, the top level will be a chain of AndNodes terminating in a true BooleanConstantNode. o The left child of an AndNode will never be an AndNode. o Any right-linked chain that includes an AndNode will be entirely composed of AndNodes terminated by a true BooleanConstantNode. o The left child of an OrNode will never be an OrNode. o Any right-linked chain that includes an OrNode will be entirely composed of OrNodes terminated by a false BooleanConstantNode. o ValueNodes other than AndNodes and OrNodes are considered leaf nodes for purposes of expression normalization. In other words, we won't do any normalization under those nodes. In addition, we track whether or not we are under a top level AndNode. SubqueryNodes need to know this for subquery flattening.

Parameters
underTopAndNode:boolean

Whether or not we are under a top level AndNode.

Returns:ValueNode

The modified expression

Annotations
@Override
Exceptions
StandardException:
Thrown on error
eliminateNotsback to summary
pack-priv ValueNode eliminateNots(boolean underNotNode) throws StandardException

Overrides org.apache.derby.impl.sql.compile.ValueNode.eliminateNots.

Eliminate NotNodes in the current query block. We traverse the tree, inverting ANDs and ORs and eliminating NOTs as we go. We stop at ComparisonOperators and boolean expressions. We invert ComparisonOperators and replace boolean expressions with boolean expression = false.

Note

Since we do not recurse under ComparisonOperators, there still could be NotNodes left in the tree.

Parameters
underNotNode:boolean

Whether or not we are under a NotNode.

Returns:ValueNode

The modified expression

Annotations
@Override
Exceptions
StandardException:
Thrown on error
genSQLJavaSQLTreeback to summary
pack-priv ValueNode genSQLJavaSQLTree() throws StandardException

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.genSQLJavaSQLTree.

Doc from org.apache.derby.impl.sql.compile.BinaryOperatorNode.genSQLJavaSQLTree.

generate a SQL->Java->SQL conversion tree above the left and right operand of this Binary Operator Node if needed. Subclasses can override the default behavior.

Returns:ValueNode

Doc from org.apache.derby.impl.sql.compile.ValueNode.genSQLJavaSQLTree.

ValueNode The new tree.

Annotations
@Override
Exceptions
StandardException:

Doc from org.apache.derby.impl.sql.compile.ValueNode.genSQLJavaSQLTree.

Thrown on error

See Also
BinaryOperatorNode#genSQLJavaSQLTree
getBetweenSelectivityback to summary
pack-priv boolean getBetweenSelectivity()

Return whether or not to use the between selectivity for this node.

Returns:boolean

Whether or not to use the between selectivity for this node.

getForQueryRewriteback to summary
pack-priv boolean getForQueryRewrite()

Was this node generated in a query rewrite?

Returns:boolean

true if it was generated in a query rewrite.

getNegationback to summary
pack-priv abstract BinaryOperatorNode getNegation(ValueNode leftOperand, ValueNode rightOperand) throws StandardException

Negate the comparison.

Parameters
leftOperand:ValueNode

The left operand of the comparison operator

rightOperand:ValueNode

The right operand of the comparison operator

Returns:BinaryOperatorNode

BinaryOperatorNode The negated expression

Exceptions
StandardException:
Thrown on error
getSwappedEquivalentback to summary
pack-priv abstract BinaryOperatorNode getSwappedEquivalent() throws StandardException

Return a node equivalent to this node, but with the left and right operands swapped. The node type may also be changed if the operator is not symmetric.

This method may for instance be used to normalize a predicate by moving constants to the right-hand side of the comparison. Example: 1 = A will be transformed to A = 1, and 10 < B will be transformed to B > 10.

Returns:BinaryOperatorNode

an equivalent expression with the operands swapped

Exceptions
StandardException:
if an error occurs
preprocessback to summary
pack-priv ValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList) throws StandardException

Overrides org.apache.derby.impl.sql.compile.BinaryOperatorNode.preprocess.

Preprocess an expression tree. We do a number of transformations here (including subqueries, IN lists, LIKE and BETWEEN) plus subquery flattening.

Note

This is done before the outer ResultSetNode is preprocessed.

Parameters
numTables:int

Number of tables in the DML Statement

outerFromList:FromList

FromList from outer query block

outerSubqueryList:SubqueryList

SubqueryList from outer query block

outerPredicateList:PredicateList

PredicateList from outer query block

Returns:ValueNode

The modified expression

Annotations
@Override
Exceptions
StandardException:
Thrown on error
setBetweenSelectivityback to summary
pack-priv void setBetweenSelectivity()

Use between selectivity when calculating the selectivity.

setForQueryRewriteback to summary
pack-priv void setForQueryRewrite(boolean val)

This node was generated as part of a query rewrite. Bypass the normal comparability checks.

Parameters
val:boolean

true if this was for a query rewrite