Class UDFunction

All Implemented Interfaces:
AssignmentTestable, Function, ScalarFunction, SchemaElement
Direct Known Subclasses:
JavaBasedUDFunction

public abstract class UDFunction extends UserFunction implements ScalarFunction
Base class for User Defined Functions.
  • Field Details

    • logger

      protected static final org.slf4j.Logger logger
    • argNames

      protected final List<ColumnIdentifier> argNames
    • language

      protected final String language
    • body

      protected final String body
    • argumentTypes

      protected final List<UDFDataType> argumentTypes
    • resultType

      protected final UDFDataType resultType
    • calledOnNullInput

      protected final boolean calledOnNullInput
    • udfContext

      protected final UDFContext udfContext
  • Constructor Details

  • Method Details

    • newArguments

      public Arguments newArguments(ProtocolVersion version)
      Description copied from interface: Function
      Creates some new input arguments for this function.
      Specified by:
      newArguments in interface Function
      Parameters:
      version - the protocol version
      Returns:
      some new input arguments for this function
    • tryCreate

      public static UDFunction tryCreate(FunctionName name, List<ColumnIdentifier> argNames, List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, String language, String body)
    • create

      public static UDFunction create(FunctionName name, List<ColumnIdentifier> argNames, List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, String language, String body)
    • createBrokenFunction

      public static UDFunction createBrokenFunction(FunctionName name, List<ColumnIdentifier> argNames, List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, String language, String body, InvalidRequestException reason)
      It can happen that a function has been declared (is listed in the scheam) but cannot be loaded (maybe only on some nodes). This is the case for instance if the class defining the class is not on the classpath for some of the node, or after a restart. In that case, we create a "fake" function so that: 1) the broken function can be dropped easily if that is what people want to do. 2) we return a meaningful error message if the function is executed (something more precise than saying that the function doesn't exist)
    • elementType

      public SchemaElement.SchemaElementType elementType()
      Description copied from interface: SchemaElement
      Return the schema element type
      Specified by:
      elementType in interface SchemaElement
      Returns:
      the schema element type
    • toCqlString

      public String toCqlString(boolean withInternals, boolean ifNotExists)
      Description copied from interface: SchemaElement
      Returns a CQL representation of this element
      Specified by:
      toCqlString in interface SchemaElement
      Parameters:
      withInternals - if the internals part of the CQL should be exposed.
      ifNotExists - if "IF NOT EXISTS" should be included.
      Returns:
      a CQL representation of this element
    • isPure

      public boolean isPure()
      Description copied from interface: Function
      Checks whether the function is a pure function (as in doesn't depend on, nor produces side effects) or not.
      Specified by:
      isPure in interface Function
      Returns:
      true if the function is a pure function, false otherwise.
    • execute

      public final ByteBuffer execute(Arguments arguments)
      Description copied from interface: ScalarFunction
      Applies this function to the specified arguments.
      Specified by:
      execute in interface ScalarFunction
      Parameters:
      arguments - the input arguments for the function
      Returns:
      the result of applying this function to the arguments
    • executeForAggregate

      public final Object executeForAggregate(Object state, Arguments arguments)
    • assertUdfsEnabled

      public static void assertUdfsEnabled(String language)
    • executor

      protected abstract ExecutorService executor()
    • isCallableWrtNullable

      public boolean isCallableWrtNullable(Arguments arguments)
    • executeUserDefined

      protected abstract ByteBuffer executeUserDefined(Arguments arguments)
    • executeAggregateUserDefined

      protected abstract Object executeAggregateUserDefined(Object firstParam, Arguments arguments)
    • isAggregate

      public boolean isAggregate()
      Description copied from interface: Function
      Checks whether the function is an aggregate function or not.
      Specified by:
      isAggregate in interface Function
      Returns:
      true if the function is an aggregate function, false otherwise.
    • isCalledOnNullInput

      public boolean isCalledOnNullInput()
      Specified by:
      isCalledOnNullInput in interface ScalarFunction
    • argNames

      public List<ColumnIdentifier> argNames()
    • body

      public String body()
    • language

      public String language()
    • decompose

      protected ByteBuffer decompose(ProtocolVersion protocolVersion, Object value)
      Used by UDF implementations (both Java code generated by JavaBasedUDFunction) to convert the Java object representation for the return value to the C* serialized representation.
      Parameters:
      protocolVersion - the native protocol version used for serialization
    • referencesUserType

      public boolean referencesUserType(ByteBuffer name)
      Specified by:
      referencesUserType in interface Function
      Overrides:
      referencesUserType in class AbstractFunction
    • withUpdatedUserType

      public UDFunction withUpdatedUserType(UserType udt)
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class AbstractFunction
    • compare

      public Optional<Difference> compare(Function function)
      Specified by:
      compare in interface Function
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class AbstractFunction