Class FunctionFactory

java.lang.Object
org.apache.cassandra.cql3.functions.FunctionFactory
Direct Known Subclasses:
MaskingFunction.Factory

public abstract class FunctionFactory extends Object
Class for dynamically building different overloads of a CQL Function according to specific function calls.

For example, the factory for the max function will return a (text) -> text function if it's called with an text argument, like in max('abc'). It however will return a (list<int>) -> list<int> function if it's called with max([1,2,3]), etc.

This is meant to be used to create functions that require too many overloads to have them pre-created in memory. Note that in the case of functions accepting collections, tuples or UDTs the number of overloads is potentially infinite.

  • Field Details

  • Constructor Details

    • FunctionFactory

      public FunctionFactory(String name, FunctionParameter... parameters)
      Parameters:
      name - the name of the built functions
      parameters - the accepted parameters
  • Method Details

    • name

      public FunctionName name()
    • getOrCreateFunction

      @Nullable public NativeFunction getOrCreateFunction(List<? extends AssignmentTestable> args, AbstractType<?> receiverType, String receiverKeyspace, String receiverTable)
      Returns a function with a signature compatible with the specified function call.
      Parameters:
      args - the arguments in the function call for which the function is going to be built
      receiverType - the expected return type of the function call for which the function is going to be built
      receiverKeyspace - the name of the recevier keyspace
      receiverTable - the name of the recevier table
      Returns:
      a function with a signature compatible with the specified function call, or null if the factory cannot create a function for the supplied arguments but there might be another factory with the same name() able to do it.
    • invalidNumberOfArgumentsException

      public InvalidRequestException invalidNumberOfArgumentsException()
    • doGetOrCreateFunction

      @Nullable protected abstract NativeFunction doGetOrCreateFunction(List<AbstractType<?>> argTypes, AbstractType<?> receiverType)
      Returns a function compatible with the specified signature.
      Parameters:
      argTypes - the types of the function arguments
      receiverType - the expected return type of the function
      Returns:
      a function compatible with the specified signature, or null if this cannot create a function for the supplied arguments but there might be another factory with the same name() able to do it.
    • toString

      public String toString()
      Overrides:
      toString in class Object