Package org.apache.drill.exec.expr.fn
Class DrillFuncHolder
java.lang.Object
org.apache.drill.exec.expr.fn.AbstractFuncHolder
org.apache.drill.exec.expr.fn.DrillFuncHolder
- All Implemented Interfaces:
FuncHolder
- Direct Known Subclasses:
DrillComplexWriterAggFuncHolder
,DrillSimpleFuncHolder
-
Constructor Summary
ConstructorDescriptionDrillFuncHolder
(FunctionAttributes attributes, FunctionInitializer initializer) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addProtectedBlock
(ClassGenerator<?> g, com.sun.codemodel.JBlock sub, String body, ClassGenerator.HoldingContainer[] inputVariables, com.sun.codemodel.JVar[] workspaceJVars, boolean workspaceOnly) Generate the function block itself, without surrounding comments, and whether or not the method is empty.protected void
assignInjectableValue
(ClassGenerator<?> g, com.sun.codemodel.JVar variable, WorkspaceReference ref) protected void
checkNullHandling
(FunctionTemplate.NullHandling nullHandling) Check if function type supports provided null handling strategy.boolean
protected com.sun.codemodel.JAssignmentTarget
declare
(com.sun.codemodel.JBlock jBlock, ValueReference parameter, com.sun.codemodel.JType paramClass, com.sun.codemodel.JExpression paramExpression, int currentIndex) Declares specifiedparamExpression
in specifiedjBlock
and assigns it to the array component if required and / or returns declared expression.protected void
declareInputVariable
(com.sun.codemodel.JCodeModel model, com.sun.codemodel.JBlock jBlock, ClassGenerator.HoldingContainer inputVariable, int currentIndex) Generate the top part of a function call which simulates passing parameters into the function.protected void
declareVarArgArray
(com.sun.codemodel.JCodeModel model, com.sun.codemodel.JBlock jBlock, ClassGenerator.HoldingContainer[] inputVariables) Declares array for storing vararg function arguments.protected com.sun.codemodel.JVar[]
protected void
generateBody
(ClassGenerator<?> g, ClassGenerator.BlockType bt, String body, ClassGenerator.HoldingContainer[] inputVariables, com.sun.codemodel.JVar[] workspaceJVars, boolean workspaceOnly) Generate the body of a Drill function by copying the source code of the corresponding function method into the generated output.getAttributeParameter
(int i) Returns i-th function attribute parameter.int
getExpr
(String name, List<LogicalExpression> args, ExpressionPosition pos) Return a reference to this function given a function alias and a list of actual arguments.Generates string representation of function input parameters: PARAMETER_TYPE_1-PARAMETER_MODE_1,PARAMETER_TYPE_2-PARAMETER_MODE_2 Example: VARCHAR-REQUIRED,VARCHAR-OPTIONAL Returns empty string if function has no input parameters.int
Number of defined input parameters.getParamMajorType
(int i) Drill SQL type of an input parameter.String[]
getReturnType
(List<LogicalExpression> logicalExpressions) boolean
boolean
isConstant
(int i) boolean
boolean
isFieldReader
(int i) boolean
boolean
boolean
isVarArg()
boolean
matches
(TypeProtos.MajorType returnType, List<TypeProtos.MajorType> argTypes) protected String
protected String
com.sun.codemodel.JVar[]
renderStart
(ClassGenerator<?> g, ClassGenerator.HoldingContainer[] inputVariables, FieldReference fieldReference) toString()
int
Methods inherited from class org.apache.drill.exec.expr.fn.AbstractFuncHolder
isComplexWriterFuncHolder, isNested, renderEnd, renderMiddle
-
Constructor Details
-
DrillFuncHolder
-
-
Method Details
-
checkNullHandling
Check if function type supports provided null handling strategy.Keep in mind that this method is invoked in
DrillFuncHolder(FunctionAttributes, FunctionInitializer)
constructor so make sure not to use any state fields when overriding the method to avoid uninitialized state.- Parameters:
nullHandling
- null handling strategy defined for a function- Throws:
IllegalArgumentException
- if providednullHandling
is not supported
-
meth
-
meth
-
renderStart
public com.sun.codemodel.JVar[] renderStart(ClassGenerator<?> g, ClassGenerator.HoldingContainer[] inputVariables, FieldReference fieldReference) - Specified by:
renderStart
in classAbstractFuncHolder
-
getExpr
public FunctionHolderExpression getExpr(String name, List<LogicalExpression> args, ExpressionPosition pos) Description copied from interface:FuncHolder
Return a reference to this function given a function alias and a list of actual arguments.- Parameters:
name
- alias used in this specific callargs
- expressions of the actual function arguments- Returns:
- an expression that holds the function definition (this object), actual parameters and related information
-
isAggregating
public boolean isAggregating() -
isDeterministic
public boolean isDeterministic() -
isNiladic
public boolean isNiladic() -
isInternal
public boolean isInternal() -
isVarArg
public boolean isVarArg() -
getInputParameters
Generates string representation of function input parameters: PARAMETER_TYPE_1-PARAMETER_MODE_1,PARAMETER_TYPE_2-PARAMETER_MODE_2 Example: VARCHAR-REQUIRED,VARCHAR-OPTIONAL Returns empty string if function has no input parameters.- Returns:
- string representation of function input parameters
-
getClassLoader
- Returns:
- instance of class loader used to load function
-
declareWorkspaceVariables
-
assignInjectableValue
protected void assignInjectableValue(ClassGenerator<?> g, com.sun.codemodel.JVar variable, WorkspaceReference ref) -
generateBody
protected void generateBody(ClassGenerator<?> g, ClassGenerator.BlockType bt, String body, ClassGenerator.HoldingContainer[] inputVariables, com.sun.codemodel.JVar[] workspaceJVars, boolean workspaceOnly) Generate the body of a Drill function by copying the source code of the corresponding function method into the generated output. For this to work, all symbol references must be absolute (they cannot refer to imports), or they must refer to local variables or class fields marked with an annotation.To make this work, the function body is wrapped in a code block that simulates the class fields by declaring local variables of the same name, and assigning those variables based on the input and workspace variables provided.
This version is used for blocks other than the main eval block.
- Parameters:
g
- code generatorbt
- type of the block to be addedbody
- source code of the block. Optional. Block will be omitted if the method body is null or emptyinputVariables
- list of input variable bindings which match up to declared@Param
member variables in order. The input variables have the same name as the parameters that they representworkspaceJVars
- list of workspace variables, structures the same as input variablesworkspaceOnly
-true
if this is a setup block and we should declare only constant workspace variables,false
to declare all variables
-
addProtectedBlock
protected void addProtectedBlock(ClassGenerator<?> g, com.sun.codemodel.JBlock sub, String body, ClassGenerator.HoldingContainer[] inputVariables, com.sun.codemodel.JVar[] workspaceJVars, boolean workspaceOnly) Generate the function block itself, without surrounding comments, and whether or not the method is empty. -
declareVarArgArray
protected void declareVarArgArray(com.sun.codemodel.JCodeModel model, com.sun.codemodel.JBlock jBlock, ClassGenerator.HoldingContainer[] inputVariables) Declares array for storing vararg function arguments.- Parameters:
model
- code model to generate the codejBlock
- block of code to be populatedinputVariables
- array of input variables for current function
-
declareInputVariable
protected void declareInputVariable(com.sun.codemodel.JCodeModel model, com.sun.codemodel.JBlock jBlock, ClassGenerator.HoldingContainer inputVariable, int currentIndex) Generate the top part of a function call which simulates passing parameters into the function. Given the following declaration:public static class UnionIsBigInt implements DrillSimpleFunc {
- Parameters:
model
- code model to generate the codejBlock
- block of code to be populatedinputVariable
- input variable for current functioncurrentIndex
- index of current parameter
-
declare
protected com.sun.codemodel.JAssignmentTarget declare(com.sun.codemodel.JBlock jBlock, ValueReference parameter, com.sun.codemodel.JType paramClass, com.sun.codemodel.JExpression paramExpression, int currentIndex) Declares specifiedparamExpression
in specifiedjBlock
and assigns it to the array component if required and / or returns declared expression.- Parameters:
jBlock
- target block where declaration is addedparameter
- function parameter which should be declaredparamClass
- type of the declared variableparamExpression
- expression to be declaredcurrentIndex
- index of current parameter- Returns:
- declared expression
-
matches
-
getParamMajorType
Description copied from interface:FuncHolder
Drill SQL type of an input parameter. -
getParamCount
public int getParamCount()Description copied from interface:FuncHolder
Number of defined input parameters. -
isConstant
public boolean isConstant(int i) -
getAttributeParameter
Returns i-th function attribute parameter. For the case when current function is vararg and specified index is greater than or equals to the attributes count, the last function attribute parameter is returned.- Parameters:
i
- index of function attribute parameter to be returned- Returns:
- i-th function attribute parameter
-
isFieldReader
public boolean isFieldReader(int i) -
getReturnType
-
getOutputWidthCalculator
-
variableOutputSizeEstimate
public int variableOutputSizeEstimate() -
getNullHandling
-
getRegisteredNames
-
getCostCategory
public int getCostCategory() -
getParameters
-
checkPrecisionRange
public boolean checkPrecisionRange() -
getReturnType
-
getReturnValue
-
getWorkspaceVars
-
toString
-