Class UDFunction
- java.lang.Object
-
- org.apache.cassandra.cql3.functions.AbstractFunction
-
- org.apache.cassandra.cql3.functions.UserFunction
-
- org.apache.cassandra.cql3.functions.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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.AssignmentTestable
AssignmentTestable.TestResult
-
Nested classes/interfaces inherited from interface org.apache.cassandra.cql3.SchemaElement
SchemaElement.SchemaElementType
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<ColumnIdentifier>
argNames
protected java.util.List<UDFDataType>
argumentTypes
protected java.lang.String
body
protected boolean
calledOnNullInput
protected java.lang.String
language
protected static org.slf4j.Logger
logger
protected UDFDataType
resultType
protected UDFContext
udfContext
-
Fields inherited from class org.apache.cassandra.cql3.functions.AbstractFunction
argTypes, name, returnType
-
Fields inherited from interface org.apache.cassandra.cql3.functions.Function
UNRESOLVED
-
Fields inherited from interface org.apache.cassandra.cql3.SchemaElement
NAME_COMPARATOR
-
-
Constructor Summary
Constructors Modifier Constructor 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)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.List<ColumnIdentifier>
argNames()
static void
assertUdfsEnabled(java.lang.String language)
java.lang.String
body()
java.util.Optional<Difference>
compare(Function function)
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(ProtocolVersion protocolVersion, java.lang.Object value)
Used by UDF implementations (both Java code generated byJavaBasedUDFunction
) to convert the Java object representation for the return value to the C* serialized representation.SchemaElement.SchemaElementType
elementType()
Return the schema element typeboolean
equals(java.lang.Object o)
java.nio.ByteBuffer
execute(Arguments arguments)
Applies this function to the specified arguments.protected abstract java.lang.Object
executeAggregateUserDefined(java.lang.Object firstParam, Arguments arguments)
java.lang.Object
executeForAggregate(java.lang.Object state, Arguments arguments)
protected abstract java.nio.ByteBuffer
executeUserDefined(Arguments arguments)
protected abstract java.util.concurrent.ExecutorService
executor()
int
hashCode()
boolean
isAggregate()
Checks whether the function is an aggregate function or not.boolean
isCallableWrtNullable(Arguments arguments)
boolean
isCalledOnNullInput()
boolean
isPure()
Checks whether the function is a pure function (as in doesn't depend on, nor produces side effects) or not.java.lang.String
language()
Arguments
newArguments(ProtocolVersion version)
Creates some new input arguments for this function.boolean
referencesUserType(java.nio.ByteBuffer name)
java.lang.String
toCqlString(boolean withInternals, boolean ifNotExists)
Returns a CQL representation of this elementstatic UDFunction
tryCreate(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
withUpdatedUserType(UserType udt)
-
Methods inherited from class org.apache.cassandra.cql3.functions.UserFunction
isNative
-
Methods inherited from class org.apache.cassandra.cql3.functions.AbstractFunction
addFunctionsTo, argTypes, argumentsList, columnName, elementKeyspace, elementName, getCompatibleTypeIfKnown, name, returnType, testAssignment, toCqlString, toString, typesMatch
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.cql3.AssignmentTestable
getCompatibleTypeIfKnown, testAssignment
-
Methods inherited from interface org.apache.cassandra.cql3.functions.Function
addFunctionsTo, argTypes, columnName, isNative, name, returnType
-
Methods inherited from interface org.apache.cassandra.cql3.functions.ScalarFunction
isMonotonic, partialApplication
-
Methods inherited from interface org.apache.cassandra.cql3.SchemaElement
elementKeyspace, elementKeyspaceQuotedIfNeeded, elementName, elementNameQuotedIfNeeded
-
-
-
-
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
-
argumentTypes
protected final java.util.List<UDFDataType> argumentTypes
-
resultType
protected final UDFDataType resultType
-
calledOnNullInput
protected final boolean calledOnNullInput
-
udfContext
protected final UDFContext udfContext
-
-
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)
-
-
Method Detail
-
newArguments
public Arguments newArguments(ProtocolVersion version)
Description copied from interface:Function
Creates some new input arguments for this function.- Specified by:
newArguments
in interfaceFunction
- Parameters:
version
- the protocol version- Returns:
- some new input arguments for this function
-
tryCreate
public static UDFunction tryCreate(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, java.lang.String language, java.lang.String body)
-
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)
-
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)
-
elementType
public SchemaElement.SchemaElementType elementType()
Description copied from interface:SchemaElement
Return the schema element type- Specified by:
elementType
in interfaceSchemaElement
- Returns:
- the schema element type
-
toCqlString
public java.lang.String toCqlString(boolean withInternals, boolean ifNotExists)
Description copied from interface:SchemaElement
Returns a CQL representation of this element- Specified by:
toCqlString
in interfaceSchemaElement
- 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.
-
execute
public final java.nio.ByteBuffer execute(Arguments arguments)
Description copied from interface:ScalarFunction
Applies this function to the specified arguments.- Specified by:
execute
in interfaceScalarFunction
- Parameters:
arguments
- the input arguments for the function- Returns:
- the result of applying this function to the arguments
-
executeForAggregate
public final java.lang.Object executeForAggregate(java.lang.Object state, Arguments arguments)
-
assertUdfsEnabled
public static void assertUdfsEnabled(java.lang.String language)
-
executor
protected abstract java.util.concurrent.ExecutorService executor()
-
isCallableWrtNullable
public boolean isCallableWrtNullable(Arguments arguments)
-
executeUserDefined
protected abstract java.nio.ByteBuffer executeUserDefined(Arguments arguments)
-
executeAggregateUserDefined
protected abstract java.lang.Object executeAggregateUserDefined(java.lang.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 interfaceFunction
- Returns:
true
if the function is an aggregate function,false
otherwise.
-
isCalledOnNullInput
public boolean isCalledOnNullInput()
- Specified by:
isCalledOnNullInput
in interfaceScalarFunction
-
argNames
public java.util.List<ColumnIdentifier> argNames()
-
body
public java.lang.String body()
-
language
public java.lang.String language()
-
decompose
protected java.nio.ByteBuffer decompose(ProtocolVersion protocolVersion, java.lang.Object value)
Used by UDF implementations (both Java code generated byJavaBasedUDFunction
) 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(java.nio.ByteBuffer name)
- Specified by:
referencesUserType
in interfaceFunction
- Overrides:
referencesUserType
in classAbstractFunction
-
withUpdatedUserType
public UDFunction withUpdatedUserType(UserType udt)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classAbstractFunction
-
compare
public java.util.Optional<Difference> compare(Function function)
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classAbstractFunction
-
-