Class FunctionFactory

  • Direct Known Subclasses:
    MaskingFunction.Factory

    public abstract class FunctionFactory
    extends java.lang.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 Detail

      • name

        protected final FunctionName name
        The name of the built functions.
      • parameters

        protected final java.util.List<FunctionParameter> parameters
        The accepted parameters.
    • Constructor Detail

      • FunctionFactory

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

      • getOrCreateFunction

        @Nullable
        public NativeFunction getOrCreateFunction​(java.util.List<? extends AssignmentTestable> args,
                                                  AbstractType<?> receiverType,
                                                  java.lang.String receiverKeyspace,
                                                  java.lang.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.
      • doGetOrCreateFunction

        @Nullable
        protected abstract NativeFunction doGetOrCreateFunction​(java.util.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object