net.sf.farrago.query
Class FarragoUserDefinedRoutine

java.lang.Object
  extended by org.eigenbase.sql.SqlOperator
      extended by org.eigenbase.sql.SqlFunction
          extended by net.sf.farrago.query.FarragoUserDefinedRoutine
All Implemented Interfaces:
OJRexImplementor

public class FarragoUserDefinedRoutine
extends SqlFunction
implements OJRexImplementor

FarragoUserDefinedRoutine extends SqlFunction with a repository reference to a specific user-defined routine.

Version:
$Id: //open/dev/farrago/src/net/sf/farrago/query/FarragoUserDefinedRoutine.java#30 $
Author:
John V. Sichi

Field Summary
private  FemJar femJar
           
private  FarragoPreparingStmt preparingStmt
           
private static String RETURN_PREFIX
           
private  RelDataType returnType
           
private  FemRoutine routine
           
private  FarragoSessionStmtValidator stmtValidator
           
 
Fields inherited from class org.eigenbase.sql.SqlOperator
MaxPrec, NL
 
Constructor Summary
FarragoUserDefinedRoutine(FarragoSessionStmtValidator stmtValidator, FarragoPreparingStmt preparingStmt, FemRoutine routine, RelDataType returnType, RelDataType[] paramTypes)
           
 
Method Summary
static String addReturnPrefix(String body)
           
 boolean canImplement(RexCall call)
          Tests whether it is possible to implement a call.
private static boolean checkCompatibility(SqlTypeName t1, SqlTypeName t2)
           
 FemRoutine getFemRoutine()
           
 FemJar getJar()
           
 Method getJavaMethod()
          Uses an external Java routine definition plus reflection to find a corresponding Java method.
 FarragoPreparingStmt getPreparingStmt()
           
 RelDataType getReturnType()
           
private static List<String> getRoutineParamNames(FemRoutine femRoutine)
           
 boolean hasDefinition()
           
static boolean hasReturnPrefix(String body)
           
 Expression implement(RexToOJTranslator translator, RexCall call, Expression[] operands)
          Implements a single RexCall.
 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 isDeterministic()
           
 boolean isDynamicFunction()
           
 boolean isTableFunction()
           
protected  void preValidateCall(SqlValidator validator, SqlValidatorScope scope, SqlCall call)
          Receives notification that validation of a call to this operator is beginning.
static String removeReturnPrefix(String body)
           
 boolean requiresDecimalExpansion()
          Method to check if call requires expansion when it has decimal operands.
private  Expression translateOperand(FarragoRexToOJTranslator farragoTranslator, FemRoutineParameter param, Expression argExpr, Class javaParamClass, RelDataType paramType)
           
private  boolean validateListParams(Method javaMethod, Class[] javaParamClasses)
          Examines parameters corresponding to List parameters and ensures that they are List<String> types
 
Methods inherited from class org.eigenbase.sql.SqlFunction
deriveType, getFunctionType, getNameAsId, getParamTypes, getSqlIdentifier, getSyntax, isQuantifierAllowed, unparse, validateCall, validateQuantifier
 
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, isAggregator, isName, leftPrec, rewriteCall, rightPrec, toString, unparseListClause, unparseListClause, validateOperands
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RETURN_PREFIX

private static final String RETURN_PREFIX
See Also:
Constant Field Values

routine

private final FemRoutine routine

stmtValidator

private final FarragoSessionStmtValidator stmtValidator

preparingStmt

private final FarragoPreparingStmt preparingStmt

femJar

private FemJar femJar

returnType

private RelDataType returnType
Constructor Detail

FarragoUserDefinedRoutine

public FarragoUserDefinedRoutine(FarragoSessionStmtValidator stmtValidator,
                                 FarragoPreparingStmt preparingStmt,
                                 FemRoutine routine,
                                 RelDataType returnType,
                                 RelDataType[] paramTypes)
Method Detail

getRoutineParamNames

private static List<String> getRoutineParamNames(FemRoutine femRoutine)

getPreparingStmt

public FarragoPreparingStmt getPreparingStmt()

getFemRoutine

public FemRoutine getFemRoutine()

preValidateCall

protected void preValidateCall(SqlValidator validator,
                               SqlValidatorScope scope,
                               SqlCall call)
Description copied from class: SqlOperator
Receives notification that validation of a call to this operator is beginning. Subclasses can supply custom behavior; default implementation does nothing.

Overrides:
preValidateCall in class SqlOperator
Parameters:
validator - invoking validator
scope - validation scope
call - the call being validated

getReturnType

public RelDataType getReturnType()

isTableFunction

public boolean isTableFunction()

getJar

public FemJar getJar()

getJavaMethod

public Method getJavaMethod()
                     throws SqlValidatorException
Uses an external Java routine definition plus reflection to find a corresponding Java method.

Returns:
Java method
Throws:
SqlValidatorException - if matching Java method could not be found

checkCompatibility

private static boolean checkCompatibility(SqlTypeName t1,
                                          SqlTypeName t2)

validateListParams

private boolean validateListParams(Method javaMethod,
                                   Class[] javaParamClasses)
Examines parameters corresponding to List parameters and ensures that they are List<String> types

Parameters:
javaMethod - the java method containing the parameters
javaParamClasses - classes of the parameter
Returns:
true if List parameters are List<String> parameters

implement

public Expression implement(RexToOJTranslator translator,
                            RexCall call,
                            Expression[] operands)
Description copied from interface: OJRexImplementor
Implements a single RexCall.

Specified by:
implement in interface OJRexImplementor
Parameters:
translator - provides translation context
call - the call to be translated
operands - call's operands, which have already been translated independently

canImplement

public boolean canImplement(RexCall call)
Description copied from interface: OJRexImplementor
Tests whether it is possible to implement a call.

Specified by:
canImplement in interface OJRexImplementor
Parameters:
call - the call for which translation is being considered
Returns:
whether the call can be implemented

translateOperand

private Expression translateOperand(FarragoRexToOJTranslator farragoTranslator,
                                    FemRoutineParameter param,
                                    Expression argExpr,
                                    Class javaParamClass,
                                    RelDataType paramType)

hasDefinition

public boolean hasDefinition()

requiresDecimalExpansion

public boolean requiresDecimalExpansion()
Description copied from class: SqlOperator
Method to check if call requires expansion when it has decimal operands. The default implementation is to return true.

Overrides:
requiresDecimalExpansion in class SqlOperator

removeReturnPrefix

public static String removeReturnPrefix(String body)

addReturnPrefix

public static String addReturnPrefix(String body)

hasReturnPrefix

public static boolean hasReturnPrefix(String body)

isDynamicFunction

public boolean isDynamicFunction()
Overrides:
isDynamicFunction in class SqlOperator
Returns:
true iff it is unsafe to cache query plans referencing this operator; false is assumed by default

isDeterministic

public boolean isDeterministic()
Overrides:
isDeterministic in class SqlOperator
Returns:
true iff a call to this operator is guaranteed to always return the same result given the same operands; true is assumed by default

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