Class UDFunction
- java.lang.Object
-
- org.apache.cassandra.cql3.functions.AbstractFunction
-
- org.apache.cassandra.cql3.functions.UDFunction
-
- All Implemented Interfaces:
AssignmentTestable,Function,ScalarFunction,SchemaElement
- Direct Known Subclasses:
JavaBasedUDFunction
public abstract class UDFunction extends AbstractFunction implements ScalarFunction, SchemaElement
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 TypeCodec<java.lang.Object>[]argCodecsprotected java.util.List<ColumnIdentifier>argNamesprotected java.lang.Stringbodyprotected booleancalledOnNullInputprotected java.lang.Stringlanguageprotected static org.slf4j.Loggerloggerprotected TypeCodec<java.lang.Object>returnCodecprotected UDFContextudfContext-
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 protectedUDFunction(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, DataType[] argDataTypes, AbstractType<?> returnType, DataType returnDataType, boolean calledOnNullInput, java.lang.String language, java.lang.String body)protectedUDFunction(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 voidassertUdfsEnabled(java.lang.String language)java.lang.Stringbody()java.util.Optional<Difference>compare(Function function)protected static java.lang.Objectcompose(TypeCodec<java.lang.Object>[] codecs, ProtocolVersion protocolVersion, int argIndex, java.nio.ByteBuffer value)protected java.lang.Objectcompose(ProtocolVersion protocolVersion, int argIndex, java.nio.ByteBuffer value)Used by UDF implementations (both Java code generated byJavaBasedUDFunctionand script executorScriptBasedUDFunction) to convert the C* serialized representation to the Java object representation.static UDFunctioncreate(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 UDFunctioncreateBrokenFunction(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 static java.nio.ByteBufferdecompose(TypeCodec<java.lang.Object> codec, ProtocolVersion protocolVersion, java.lang.Object value)protected java.nio.ByteBufferdecompose(ProtocolVersion protocolVersion, java.lang.Object value)Used by UDF implementations (both Java code generated byJavaBasedUDFunctionand script executorScriptBasedUDFunction) to convert the Java object representation for the return value to the C* serialized representation.SchemaElement.SchemaElementTypeelementType()Return the schema element typebooleanequals(java.lang.Object o)java.nio.ByteBufferexecute(ProtocolVersion protocolVersion, java.util.List<java.nio.ByteBuffer> parameters)Applies this function to the specified parameter.protected abstract java.lang.ObjectexecuteAggregateUserDefined(ProtocolVersion protocolVersion, java.lang.Object firstParam, java.util.List<java.nio.ByteBuffer> parameters)java.lang.ObjectexecuteForAggregate(ProtocolVersion protocolVersion, java.lang.Object firstParam, java.util.List<java.nio.ByteBuffer> parameters)LikeScalarFunction.execute(ProtocolVersion, List)but the first parameter is already in non-serialized form.protected abstract java.nio.ByteBufferexecuteUserDefined(ProtocolVersion protocolVersion, java.util.List<java.nio.ByteBuffer> parameters)protected abstract java.util.concurrent.ExecutorServiceexecutor()inthashCode()booleanisAggregate()Checks whether the function is an aggregate function or not.booleanisCallableWrtNullable(java.util.List<java.nio.ByteBuffer> parameters)booleanisCalledOnNullInput()booleanisNative()Checks whether the function is a native/hard coded one or not.booleanisPure()Checks whether the function is a pure function (as in doesn't depend on, nor produces side effects) or not.java.lang.Stringlanguage()booleanreferencesUserType(java.nio.ByteBuffer name)java.lang.StringtoCqlString(boolean withInternals, boolean ifNotExists)Returns a CQL representation of this elementstatic UDFunctiontryCreate(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, AbstractType<?> returnType, boolean calledOnNullInput, java.lang.String language, java.lang.String body)UDFunctionwithUpdatedUserType(UserType udt)-
Methods inherited from class org.apache.cassandra.cql3.functions.AbstractFunction
addFunctionsTo, argTypes, argumentsList, columnName, elementKeyspace, elementName, name, returnType, testAssignment, toCqlString, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.cassandra.cql3.AssignmentTestable
testAssignment
-
Methods inherited from interface org.apache.cassandra.cql3.functions.Function
addFunctionsTo, argTypes, columnName, 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
-
argCodecs
protected final TypeCodec<java.lang.Object>[] argCodecs
-
returnCodec
protected final TypeCodec<java.lang.Object> returnCodec
-
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)
-
UDFunction
protected UDFunction(FunctionName name, java.util.List<ColumnIdentifier> argNames, java.util.List<AbstractType<?>> argTypes, DataType[] argDataTypes, AbstractType<?> returnType, DataType returnDataType, boolean calledOnNullInput, java.lang.String language, java.lang.String body)
-
-
Method Detail
-
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:SchemaElementReturn the schema element type- Specified by:
elementTypein interfaceSchemaElement- Returns:
- the schema element type
-
toCqlString
public java.lang.String toCqlString(boolean withInternals, boolean ifNotExists)Description copied from interface:SchemaElementReturns a CQL representation of this element- Specified by:
toCqlStringin 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:FunctionChecks 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(ProtocolVersion protocolVersion, java.util.List<java.nio.ByteBuffer> parameters)
Description copied from interface:ScalarFunctionApplies this function to the specified parameter.- Specified by:
executein interfaceScalarFunction- Parameters:
protocolVersion- protocol version used for parameters and return valueparameters- the input parameters- Returns:
- the result of applying this function to the parameter
-
executeForAggregate
public final java.lang.Object executeForAggregate(ProtocolVersion protocolVersion, java.lang.Object firstParam, java.util.List<java.nio.ByteBuffer> parameters)
LikeScalarFunction.execute(ProtocolVersion, List)but the first parameter is already in non-serialized form. Remaining parameters (2nd paramters and all others) are inparameters. This is used to prevent superfluous (de)serialization of the state of aggregates. Means: scalar functions of aggregates are called using this variant.
-
assertUdfsEnabled
public static void assertUdfsEnabled(java.lang.String language)
-
executor
protected abstract java.util.concurrent.ExecutorService executor()
-
isCallableWrtNullable
public boolean isCallableWrtNullable(java.util.List<java.nio.ByteBuffer> parameters)
-
executeUserDefined
protected abstract java.nio.ByteBuffer executeUserDefined(ProtocolVersion protocolVersion, java.util.List<java.nio.ByteBuffer> parameters)
-
executeAggregateUserDefined
protected abstract java.lang.Object executeAggregateUserDefined(ProtocolVersion protocolVersion, java.lang.Object firstParam, java.util.List<java.nio.ByteBuffer> parameters)
-
isAggregate
public boolean isAggregate()
Description copied from interface:FunctionChecks whether the function is an aggregate function or not.- Specified by:
isAggregatein interfaceFunction- Returns:
trueif the function is an aggregate function,falseotherwise.
-
isNative
public boolean isNative()
Description copied from interface:FunctionChecks whether the function is a native/hard coded one or not.
-
isCalledOnNullInput
public boolean isCalledOnNullInput()
- Specified by:
isCalledOnNullInputin interfaceScalarFunction
-
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(ProtocolVersion protocolVersion, int argIndex, java.nio.ByteBuffer value)
Used by UDF implementations (both Java code generated byJavaBasedUDFunctionand script executorScriptBasedUDFunction) to convert the C* serialized representation to the Java object representation.- Parameters:
protocolVersion- the native protocol version used for serializationargIndex- index of the UDF input argument
-
compose
protected static java.lang.Object compose(TypeCodec<java.lang.Object>[] codecs, ProtocolVersion protocolVersion, int argIndex, java.nio.ByteBuffer value)
-
decompose
protected java.nio.ByteBuffer decompose(ProtocolVersion protocolVersion, java.lang.Object value)
Used by UDF implementations (both Java code generated byJavaBasedUDFunctionand script executorScriptBasedUDFunction) to convert the Java object representation for the return value to the C* serialized representation.- Parameters:
protocolVersion- the native protocol version used for serialization
-
decompose
protected static java.nio.ByteBuffer decompose(TypeCodec<java.lang.Object> codec, ProtocolVersion protocolVersion, java.lang.Object value)
-
referencesUserType
public boolean referencesUserType(java.nio.ByteBuffer name)
- Specified by:
referencesUserTypein interfaceFunction- Overrides:
referencesUserTypein classAbstractFunction
-
withUpdatedUserType
public UDFunction withUpdatedUserType(UserType udt)
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classAbstractFunction
-
compare
public java.util.Optional<Difference> compare(Function function)
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractFunction
-
-