org.eigenbase.sql
Class SqlFunction

java.lang.Object
  extended by org.eigenbase.sql.SqlOperator
      extended by org.eigenbase.sql.SqlFunction
Direct Known Subclasses:
FarragoRngNextRandomIntOperator, FarragoUserDefinedRoutine, SqlAbstractTimeFunction, SqlAggFunction, SqlCastFunction, SqlCeilFunction, SqlCoalesceFunction, SqlConvertFunction, SqlCurrentDateFunction, SqlExtractFunction, SqlFloorFunction, SqlJdbcFunctionCall, SqlMonotonicUnaryFunction, SqlNullifFunction, SqlOverlayFunction, SqlPositionFunction, SqlStringContextVariable, SqlSubstringFunction, SqlTrimFunction

public class SqlFunction
extends SqlOperator

A SqlFunction is a type of operator which has conventional function-call syntax.

Version:
$Id: //open/dev/farrago/src/org/eigenbase/sql/SqlFunction.java#28 $
Author:
jhyde

Field Summary
private  SqlFunctionCategory functionType
           
private  RelDataType[] paramTypes
           
private  SqlIdentifier sqlIdentifier
           
 
Fields inherited from class org.eigenbase.sql.SqlOperator
MaxPrec, NL
 
Constructor Summary
SqlFunction(SqlIdentifier sqlIdentifier, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, RelDataType[] paramTypes, SqlFunctionCategory funcType)
          Creates a placeholder SqlFunction for an invocation of a function with a possibly qualified name.
SqlFunction(String name, SqlKind kind, SqlReturnTypeInference returnTypeInference, SqlOperandTypeInference operandTypeInference, SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory funcType)
          Creates a new SqlFunction for a call to a builtin function.
 
Method Summary
 RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call)
          Derives the type of a call to this operator.
private  RelDataType deriveType(SqlValidator validator, SqlValidatorScope scope, SqlCall call, boolean convertRowArgToColumnList)
           
 SqlFunctionCategory getFunctionType()
           
 SqlIdentifier getNameAsId()
           
 RelDataType[] getParamTypes()
           
 SqlIdentifier getSqlIdentifier()
           
 SqlSyntax getSyntax()
          Returns the syntactic type of this operator.
 boolean isQuantifierAllowed()
          Returns whether this function allows a DISTINCT or ALL quantifier.
 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.
 void validateCall(SqlCall call, SqlValidator validator, SqlValidatorScope scope, SqlValidatorScope operandScope)
          Validates a call to this operator.
protected  void validateQuantifier(SqlValidator validator, SqlCall call)
          Throws a validation error if a DISTINCT or ALL quantifier is present but not allowed.
 
Methods inherited from class org.eigenbase.sql.SqlOperator
acceptCall, acceptCall, adjustType, argumentMustBeScalar, checkOperandCount, checkOperandTypes, createCall, createCall, createCall, createCall, equals, getAllowedSignatures, getAllowedSignatures, getKind, getLeftPrec, getMonotonicity, getName, getOperandCountRange, getOperandTypeChecker, getOperandTypeInference, getReturnTypeInference, getRightPrec, getSignatureTemplate, hashCode, inferReturnType, inferReturnType, isAggregator, isDeterministic, isDynamicFunction, isName, leftPrec, preValidateCall, requiresDecimalExpansion, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateOperands
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

functionType

private final SqlFunctionCategory functionType

sqlIdentifier

private final SqlIdentifier sqlIdentifier

paramTypes

private final RelDataType[] paramTypes
Constructor Detail

SqlFunction

public SqlFunction(String name,
                   SqlKind kind,
                   SqlReturnTypeInference returnTypeInference,
                   SqlOperandTypeInference operandTypeInference,
                   SqlOperandTypeChecker operandTypeChecker,
                   SqlFunctionCategory funcType)
Creates a new SqlFunction for a call to a builtin function.

Parameters:
name - of builtin function
kind - kind of operator implemented by function
returnTypeInference - strategy to use for return type inference
operandTypeInference - strategy to use for parameter type inference
operandTypeChecker - strategy to use for parameter type checking
funcType - categorization for function

SqlFunction

public SqlFunction(SqlIdentifier sqlIdentifier,
                   SqlReturnTypeInference returnTypeInference,
                   SqlOperandTypeInference operandTypeInference,
                   SqlOperandTypeChecker operandTypeChecker,
                   RelDataType[] paramTypes,
                   SqlFunctionCategory funcType)
Creates a placeholder SqlFunction for an invocation of a function with a possibly qualified name. This name must be resolved into either a builtin function or a user-defined function.

Parameters:
sqlIdentifier - possibly qualified identifier for function
returnTypeInference - strategy to use for return type inference
operandTypeInference - strategy to use for parameter type inference
operandTypeChecker - strategy to use for parameter type checking
paramTypes - array of parameter types
funcType - function category
Method Detail

getSyntax

public SqlSyntax getSyntax()
Description copied from class: SqlOperator
Returns the syntactic type of this operator.

Specified by:
getSyntax in class SqlOperator

getSqlIdentifier

public SqlIdentifier getSqlIdentifier()
Returns:
fully qualified name of function, or null for a builtin function

getNameAsId

public SqlIdentifier getNameAsId()
Returns:
fully qualified name of function

getParamTypes

public RelDataType[] getParamTypes()
Returns:
array of parameter types, or null for builtin function

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 SqlOperator

getFunctionType

public SqlFunctionCategory getFunctionType()
Returns:
function category

isQuantifierAllowed

public boolean isQuantifierAllowed()
Returns whether this function allows a DISTINCT or ALL quantifier. The default is false; some aggregate functions return true.


validateCall

public void validateCall(SqlCall call,
                         SqlValidator validator,
                         SqlValidatorScope scope,
                         SqlValidatorScope operandScope)
Description copied from class: SqlOperator
Validates a call to this operator.

This method should not perform type-derivation or perform validation related related to types. That is done later, by SqlOperator.deriveType(SqlValidator, SqlValidatorScope, SqlCall). This method should focus on structural validation.

A typical implementation of this method first validates the operands, then performs some operator-specific logic. The default implementation just validates the operands.

This method is the default implementation of SqlCall.validate(org.eigenbase.sql.validate.SqlValidator, org.eigenbase.sql.validate.SqlValidatorScope); but note that some sub-classes of SqlCall never call this method.

Overrides:
validateCall in class SqlOperator
Parameters:
call - the call to this operator
validator - the active validator
scope - validator scope
operandScope - validator scope in which to validate operands to this call; usually equal to scope, but not always because some operators introduce new scopes
See Also:
SqlNode.validateExpr(SqlValidator, SqlValidatorScope), SqlOperator.deriveType(SqlValidator, SqlValidatorScope, SqlCall)

validateQuantifier

protected void validateQuantifier(SqlValidator validator,
                                  SqlCall call)
Throws a validation error if a DISTINCT or ALL quantifier is present but not allowed.


deriveType

public RelDataType deriveType(SqlValidator validator,
                              SqlValidatorScope scope,
                              SqlCall call)
Description copied from class: SqlOperator
Derives the type of a call to this operator.

This method is an intrinsic part of the validation process so, unlike SqlOperator.inferReturnType(org.eigenbase.sql.SqlOperatorBinding), specific operators would not typically override this method.

Overrides:
deriveType in class SqlOperator
Parameters:
validator - Validator
scope - Scope of validation
call - Call to this operator
Returns:
Type of call

deriveType

private RelDataType deriveType(SqlValidator validator,
                               SqlValidatorScope scope,
                               SqlCall call,
                               boolean convertRowArgToColumnList)