org.eigenbase.sql.fun
Class SqlBetweenOperator

java.lang.Object
  extended by org.eigenbase.sql.SqlOperator
      extended by org.eigenbase.sql.SqlSpecialOperator
          extended by org.eigenbase.sql.SqlInfixOperator
              extended by org.eigenbase.sql.fun.SqlBetweenOperator

public class SqlBetweenOperator
extends SqlInfixOperator

Defines the BETWEEN operator.

Syntax:

X [NOT] BETWEEN [ASYMMETRIC | SYMMETRIC] Y AND Z

If the asymmetric/symmeteric keywords are left out ASYMMETRIC is default.

This operator is always expanded (into something like Y <= X AND X <= Z) before being converted into Rex nodes.

Since:
Jun 9, 2004
Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/fun/SqlBetweenOperator.java#15 $
Author:
Wael Chatila

Nested Class Summary
private static class SqlBetweenOperator.AndFinder
          Finds an AND operator in an expression.
static class SqlBetweenOperator.Flag
          Defines the "SYMMETRIC" and "ASYMMETRIC" keywords.
 
Field Summary
private static SqlWriter.FrameType BetweenFrameType
           
private static String[] betweenNames
           
private  SqlBetweenOperator.Flag flag
          todo: Use a wrapper 'class SqlTempCall(SqlOperator,SqlParserPos) extends SqlNode' to store extra flags (neg and asymmetric) to calls to BETWEEN.
static int LOWER_OPERAND
          Ordinal of the 'lower' operand.
private  boolean negated
          If true the call represents 'NOT BETWEEN'.
private static String[] notBetweenNames
           
private static SqlOperandTypeChecker otcCustom
          Custom operand-type checking strategy.
static int SYMFLAG_OPERAND
          Ordinal of the 'symmetric' operand.
static int UPPER_OPERAND
          Ordinal of the 'upper' operand.
static int VALUE_OPERAND
          Ordinal of the 'value' operand.
 
Fields inherited from class org.eigenbase.sql.SqlOperator
MaxPrec, NL
 
Constructor Summary
SqlBetweenOperator(SqlBetweenOperator.Flag flag, boolean negated)
           
 
Method Summary
private  RelDataType[] collectOperandTypes(SqlValidator validator, SqlValidatorScope scope, SqlCall call)
           
 SqlOperandCountRange getOperandCountRange()
          Returns a constraint on the number of operands expected by this operator.
 String getSignatureTemplate(int operandsCount)
          Returns a template describing how the operator signature is to be built.
 RelDataType inferReturnType(SqlOperatorBinding opBinding)
          Infers the return type of an invocation of this operator; only called after the number and types of operands have already been validated.
 boolean isNegated()
           
 int reduceExpr(int opOrdinal, List<Object> list)
          Reduces a list of operators and arguments according to the rules of precedence and associativity.
 void unparse(SqlWriter writer, SqlNode[] operands, int leftPrec, int rightPrec)
          Writes a SQL representation of a call to this operator to a writer, including parentheses if the operators on either side are of greater precedence.
 
Methods inherited from class org.eigenbase.sql.SqlInfixOperator
getSyntax
 
Methods inherited from class org.eigenbase.sql.SqlOperator
acceptCall, acceptCall, adjustType, argumentMustBeScalar, checkOperandCount, checkOperandTypes, createCall, createCall, createCall, createCall, deriveType, equals, getAllowedSignatures, getAllowedSignatures, getKind, getLeftPrec, getMonotonicity, getName, getOperandTypeChecker, getOperandTypeInference, getReturnTypeInference, getRightPrec, hashCode, inferReturnType, isAggregator, isDeterministic, isDynamicFunction, isName, leftPrec, preValidateCall, requiresDecimalExpansion, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateCall, validateOperands
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

betweenNames

private static final String[] betweenNames

notBetweenNames

private static final String[] notBetweenNames

VALUE_OPERAND

public static final int VALUE_OPERAND
Ordinal of the 'value' operand.

See Also:
Constant Field Values

LOWER_OPERAND

public static final int LOWER_OPERAND
Ordinal of the 'lower' operand.

See Also:
Constant Field Values

UPPER_OPERAND

public static final int UPPER_OPERAND
Ordinal of the 'upper' operand.

See Also:
Constant Field Values

SYMFLAG_OPERAND

public static final int SYMFLAG_OPERAND
Ordinal of the 'symmetric' operand.

See Also:
Constant Field Values

otcCustom

private static final SqlOperandTypeChecker otcCustom
Custom operand-type checking strategy.


BetweenFrameType

private static final SqlWriter.FrameType BetweenFrameType

flag

private final SqlBetweenOperator.Flag flag
todo: Use a wrapper 'class SqlTempCall(SqlOperator,SqlParserPos) extends SqlNode' to store extra flags (neg and asymmetric) to calls to BETWEEN. Then we can obsolete flag. SqlTempCall would never have any SqlNodes as children, but it can have flags.


negated

private final boolean negated
If true the call represents 'NOT BETWEEN'.

Constructor Detail

SqlBetweenOperator

public SqlBetweenOperator(SqlBetweenOperator.Flag flag,
                          boolean negated)
Method Detail

isNegated

public boolean isNegated()

collectOperandTypes

private RelDataType[] collectOperandTypes(SqlValidator validator,
                                          SqlValidatorScope scope,
                                          SqlCall call)

inferReturnType

public RelDataType inferReturnType(SqlOperatorBinding opBinding)
Description copied from class: SqlOperator
Infers the return type of an invocation of this operator; only called after the number and types of operands have already been validated. Subclasses must either override this method or supply an instance of SqlReturnTypeInference to the constructor.

Overrides:
inferReturnType in class SqlOperator
Parameters:
opBinding - description of invocation (not necessarily a SqlCall)
Returns:
inferred return type

getSignatureTemplate

public String getSignatureTemplate(int operandsCount)
Description copied from class: SqlOperator
Returns a template describing how the operator signature is to be built. E.g for the binary + operator the template looks like "{1} {0} {2}" {0} is the operator, subsequent numbers are operands.

Overrides:
getSignatureTemplate in class SqlOperator
Parameters:
operandsCount - is used with functions that can take a variable number of operands
Returns:
signature template, or null to indicate that a default template will suffice

getOperandCountRange

public SqlOperandCountRange getOperandCountRange()
Description copied from class: SqlOperator
Returns a constraint on the number of operands expected by this operator. Subclasses may override this method; when they don't, the range is derived from the SqlOperandTypeChecker associated with this operator.

Overrides:
getOperandCountRange in class SqlOperator
Returns:
acceptable range

unparse

public void unparse(SqlWriter writer,
                    SqlNode[] operands,
                    int leftPrec,
                    int rightPrec)
Description copied from class: SqlOperator
Writes a SQL representation of a call to this operator to a writer, including parentheses if the operators on either side are of greater precedence.

The default implementation of this method delegates to SqlSyntax.unparse(org.eigenbase.sql.SqlWriter, org.eigenbase.sql.SqlOperator, org.eigenbase.sql.SqlNode[], int, int).

Overrides:
unparse in class SqlInfixOperator

reduceExpr

public int reduceExpr(int opOrdinal,
                      List<Object> list)
Description copied from class: SqlSpecialOperator
Reduces a list of operators and arguments according to the rules of precedence and associativity. Returns the ordinal of the node which replaced the expression.

The default implementation throws UnsupportedOperationException.

Overrides:
reduceExpr in class SqlSpecialOperator
Parameters:
opOrdinal - indicating the ordinal of the current operator in the list on which a possible reduction can be made
list - List of alternating SqlParserUtil.ToTreeListItem and SqlNode
Returns:
ordinal of the node which replaced the expression