org.apache.cassandra.cql3.functions

## Class UDFunction

- java.lang.Object
- - org.apache.cassandra.cql3.functions.AbstractFunction
  - - org.apache.cassandra.cql3.functions.UDFunction

- All Implemented Interfaces:
    AssignmentTestable, Function, ScalarFunction
  Direct Known Subclasses:
    ScriptBasedUDF

      public abstract class UDFunction
      extends AbstractFunction
      implements ScalarFunction

  Base class for User Defined Functions.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable

      `AssignmentTestable.TestResult`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected com.datastax.driver.core.DataType[]` | `argDataTypes`
    `protected java.util.List<ColumnIdentifier>` | `argNames`
    `protected java.lang.String` | `body`
    `protected boolean` | `calledOnNullInput`
    `protected java.lang.String` | `language`
    `protected static org.slf4j.Logger` | `logger`
    `protected com.datastax.driver.core.DataType` | `returnDataType`

    - ### Fields inherited from class org.apache.cassandra.cql3.functions.AbstractFunction

      `argTypes, name, returnType`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `UDFunction(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, java.lang.String language, java.lang.String body)`
    `protected` | `UDFunction(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, com.datastax.driver.core.DataType[] argDataTypes, AbstractType<?> returnType, com.datastax.driver.core.DataType returnDataType, boolean calledOnNullInput, java.lang.String language, java.lang.String body)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.util.List<ColumnIdentifier>` | `argNames()`
    `java.lang.String` | `body()`
    `protected boolean` | `compose_boolean(int protocolVersion, int argIndex, java.nio.ByteBuffer value)`
    `protected byte` | `compose_byte(int protocolVersion, int argIndex, java.nio.ByteBuffer value)`
    `protected double` | `compose_double(int protocolVersion, int argIndex, java.nio.ByteBuffer value)`
    `protected float` | `compose_float(int protocolVersion, int argIndex, java.nio.ByteBuffer value)`
    `protected int` | `compose_int(int protocolVersion, int argIndex, java.nio.ByteBuffer value)`
    `protected long` | `compose_long(int protocolVersion, int argIndex, java.nio.ByteBuffer value)`
    `protected short` | `compose_short(int protocolVersion, int argIndex, java.nio.ByteBuffer value)`
    `protected java.lang.Object` | `compose(int protocolVersion, int argIndex, java.nio.ByteBuffer value)` Used by UDF implementations (both Java code generated by `JavaSourceUDFFactory` and script executor `ScriptBasedUDF`) to convert the C* serialized representation to the Java object representation.
    `static UDFunction` | `create(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, java.lang.String language, java.lang.String body)`
    `static UDFunction` | `createBrokenFunction(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, java.lang.String language, java.lang.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).
    `protected java.nio.ByteBuffer` | `decompose(int protocolVersion, java.lang.Object value)` Used by UDF implementations (both Java code generated by `JavaSourceUDFFactory` and script executor `ScriptBasedUDF`) to convert the Java object representation for the return value to the C* serialized representation.
    `boolean` | `equals(java.lang.Object o)`
    `java.nio.ByteBuffer` | `execute(int protocolVersion, java.util.List<java.nio.ByteBuffer> parameters)` Applies this function to the specified parameter.
    `protected abstract java.nio.ByteBuffer` | `executeUserDefined(int protocolVersion, java.util.List<java.nio.ByteBuffer> parameters)`
    `int` | `hashCode()`
    `boolean` | `isAggregate()` Checks whether the function is an aggregate function or not.
    `boolean` | `isCallableWrtNullable(java.util.List<java.nio.ByteBuffer> parameters)`
    `boolean` | `isCalledOnNullInput()`
    `boolean` | `isNative()` Checks whether the function is a native/hard coded one or not.
    `java.lang.String` | `language()`
    `void` | `userTypeUpdated(java.lang.String ksName, java.lang.String typeName)`

    - ### Methods inherited from class org.apache.cassandra.cql3.functions.AbstractFunction

      `argTypes, getFunctions, hasReferenceTo, name, returnType, testAssignment, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface org.apache.cassandra.cql3.functions.Function

      `argTypes, getFunctions, hasReferenceTo, name, returnType`

    - ### Methods inherited from interface org.apache.cassandra.cql3.AssignmentTestable

      `testAssignment`

- - ### Field Detail

    - #### logger

          protected static final org.slf4j.Logger logger

    - #### argNames

          protected final java.util.List<ColumnIdentifier> argNames

    - #### language

          protected final java.lang.String language

    - #### body

          protected final java.lang.String body

    - #### argDataTypes

          protected final com.datastax.driver.core.DataType[] argDataTypes

    - #### returnDataType

          protected final com.datastax.driver.core.DataType returnDataType

    - #### calledOnNullInput

          protected final boolean calledOnNullInput

  - ### Constructor Detail

    - #### UDFunction

          protected UDFunction(FunctionName name,
                               java.util.List<ColumnIdentifier> argNames,
                               java.util.List<AbstractType<?>> argTypes,
                               AbstractType<?> returnType,
                               boolean calledOnNullInput,
                               java.lang.String language,
                               java.lang.String body)

    - #### UDFunction

          protected UDFunction(FunctionName name,
                               java.util.List<ColumnIdentifier> argNames,
                               java.util.List<AbstractType<?>> argTypes,
                               com.datastax.driver.core.DataType[] argDataTypes,
                               AbstractType<?> returnType,
                               com.datastax.driver.core.DataType returnDataType,
                               boolean calledOnNullInput,
                               java.lang.String language,
                               java.lang.String body)

  - ### Method Detail

    - #### create

          public static UDFunction create(FunctionName name,
                                          java.util.List<ColumnIdentifier> argNames,
                                          java.util.List<AbstractType<?>> argTypes,
                                          AbstractType<?> returnType,
                                          boolean calledOnNullInput,
                                          java.lang.String language,
                                          java.lang.String body)
                                   throws InvalidRequestException

      Throws:
        `InvalidRequestException`

    - #### createBrokenFunction

          public static UDFunction createBrokenFunction(FunctionName name,
                                                        java.util.List<ColumnIdentifier> argNames,
                                                        java.util.List<AbstractType<?>> argTypes,
                                                        AbstractType<?> returnType,
                                                        boolean calledOnNullInput,
                                                        java.lang.String language,
                                                        java.lang.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)

    - #### execute

          public final java.nio.ByteBuffer execute(int protocolVersion,
                                                   java.util.List<java.nio.ByteBuffer> parameters)
                                            throws InvalidRequestException

      Description copied from interface: `ScalarFunction`
      Applies this function to the specified parameter.
      Specified by:
        `execute` in interface `ScalarFunction`
      Parameters:
        `protocolVersion` - protocol version used for parameters and return value
        `parameters` - the input parameters
      Returns:
        the result of applying this function to the parameter
      Throws:
        `InvalidRequestException` - if this function cannot not be applied to the parameter

    - #### isCallableWrtNullable

          public boolean isCallableWrtNullable(java.util.List<java.nio.ByteBuffer> parameters)

    - #### executeUserDefined

          protected abstract java.nio.ByteBuffer executeUserDefined(int protocolVersion,
                                                                    java.util.List<java.nio.ByteBuffer> parameters)
                                                             throws InvalidRequestException

      Throws:
        `InvalidRequestException`

    - #### 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.

    - #### isNative

          public boolean isNative()

      Description copied from interface: `Function`
      Checks whether the function is a native/hard coded one or not.
      Specified by:
        `isNative` in interface `Function`
      Returns:
        `true` if the function is a native/hard coded one, `false` otherwise.

    - #### isCalledOnNullInput

          public boolean isCalledOnNullInput()

      Specified by:
        `isCalledOnNullInput` in interface `ScalarFunction`

    - #### argNames

          public java.util.List<ColumnIdentifier> argNames()

    - #### body

          public java.lang.String body()

    - #### language

          public java.lang.String language()

    - #### compose

          protected java.lang.Object compose(int protocolVersion,
                                             int argIndex,
                                             java.nio.ByteBuffer value)

      Used by UDF implementations (both Java code generated by `JavaSourceUDFFactory` and script executor `ScriptBasedUDF`) to convert the C* serialized representation to the Java object representation.
      Parameters:
        `protocolVersion` - the native protocol version used for serialization
        `argIndex` - index of the UDF input argument

    - #### compose_float

          protected float compose_float(int protocolVersion,
                                        int argIndex,
                                        java.nio.ByteBuffer value)

    - #### compose_double

          protected double compose_double(int protocolVersion,
                                          int argIndex,
                                          java.nio.ByteBuffer value)

    - #### compose_byte

          protected byte compose_byte(int protocolVersion,
                                      int argIndex,
                                      java.nio.ByteBuffer value)

    - #### compose_short

          protected short compose_short(int protocolVersion,
                                        int argIndex,
                                        java.nio.ByteBuffer value)

    - #### compose_int

          protected int compose_int(int protocolVersion,
                                    int argIndex,
                                    java.nio.ByteBuffer value)

    - #### compose_long

          protected long compose_long(int protocolVersion,
                                      int argIndex,
                                      java.nio.ByteBuffer value)

    - #### compose_boolean

          protected boolean compose_boolean(int protocolVersion,
                                            int argIndex,
                                            java.nio.ByteBuffer value)

    - #### decompose

          protected java.nio.ByteBuffer decompose(int protocolVersion,
                                                  java.lang.Object value)

      Used by UDF implementations (both Java code generated by `JavaSourceUDFFactory` and script executor `ScriptBasedUDF`) to convert the Java object representation for the return value to the C* serialized representation.
      Parameters:
        `protocolVersion` - the native protocol version used for serialization

    - #### equals

          public boolean equals(java.lang.Object o)

      Overrides:
        `equals` in class `AbstractFunction`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `AbstractFunction`

    - #### userTypeUpdated

          public void userTypeUpdated(java.lang.String ksName,
                                      java.lang.String typeName)

Copyright © 2018 The Apache Software Foundation