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

public abstract class DrillFuncHolder extends AbstractFuncHolder
  • Constructor Details

  • Method Details

    • checkNullHandling

      protected void checkNullHandling(FunctionTemplate.NullHandling nullHandling)
      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 provided nullHandling is not supported
    • meth

      protected String meth(String methodName)
    • meth

      protected String meth(String methodName, boolean required)
    • renderStart

      public com.sun.codemodel.JVar[] renderStart(ClassGenerator<?> g, ClassGenerator.HoldingContainer[] inputVariables, FieldReference fieldReference)
      Specified by:
      renderStart in class AbstractFuncHolder
    • getExpr

      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 call
      args - 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

      public String 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

      public ClassLoader getClassLoader()
      Returns:
      instance of class loader used to load function
    • declareWorkspaceVariables

      protected com.sun.codemodel.JVar[] declareWorkspaceVariables(ClassGenerator<?> g)
    • 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 generator
      bt - type of the block to be added
      body - source code of the block. Optional. Block will be omitted if the method body is null or empty
      inputVariables - 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 represent
      workspaceJVars - list of workspace variables, structures the same as input variables
      workspaceOnly - 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 code
      jBlock - block of code to be populated
      inputVariables - 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 code
      jBlock - block of code to be populated
      inputVariable - input variable for current function
      currentIndex - 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 specified paramExpression in specified jBlock and assigns it to the array component if required and / or returns declared expression.
      Parameters:
      jBlock - target block where declaration is added
      parameter - function parameter which should be declared
      paramClass - type of the declared variable
      paramExpression - expression to be declared
      currentIndex - index of current parameter
      Returns:
      declared expression
    • matches

      public boolean matches(TypeProtos.MajorType returnType, List<TypeProtos.MajorType> argTypes)
    • getParamMajorType

      public TypeProtos.MajorType getParamMajorType(int i)
      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

      public ValueReference getAttributeParameter(int i)
      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

      public TypeProtos.MajorType getReturnType(List<LogicalExpression> logicalExpressions)
    • getOutputWidthCalculator

      public OutputWidthCalculator getOutputWidthCalculator()
    • variableOutputSizeEstimate

      public int variableOutputSizeEstimate()
    • getNullHandling

      public FunctionTemplate.NullHandling getNullHandling()
    • getRegisteredNames

      public String[] getRegisteredNames()
    • getCostCategory

      public int getCostCategory()
    • getParameters

      public ValueReference[] getParameters()
    • checkPrecisionRange

      public boolean checkPrecisionRange()
    • getReturnType

      public TypeProtos.MajorType getReturnType()
    • getReturnValue

      public ValueReference getReturnValue()
    • getWorkspaceVars

      public WorkspaceReference[] getWorkspaceVars()
    • toString

      public String toString()
      Overrides:
      toString in class Object