@PublicEvolving public abstract class ScalarFunction extends UserDefinedFunction
The behavior of a ScalarFunction
can be defined by implementing a custom evaluation
method. An evaluation method must be declared publicly and named eval
. Evaluation
methods can also be overloaded by implementing multiple methods named eval
.
User-defined functions must have a default constructor and must be instantiable during runtime.
By default the result type of an evaluation method is determined by Flink's type extraction
facilities. This is sufficient for basic types or simple POJOs but might be wrong for more
complex, custom, or composite types. In these cases TypeInformation
of the result type
can be manually defined by overriding getResultType(java.lang.Class<?>[])
.
Internally, the Table/SQL API code generation works with primitive values as much as possible.
If a user-defined scalar function should not introduce much overhead during runtime, it is
recommended to declare parameters and result types as primitive types instead of their boxed
classes. DATE/TIME
is equal to int
, TIMESTAMP
is equal
to long
.
Constructor and Description |
---|
ScalarFunction() |
Modifier and Type | Method and Description |
---|---|
FunctionKind |
getKind()
Returns the kind of function this definition describes.
|
org.apache.flink.api.common.typeinfo.TypeInformation<?>[] |
getParameterTypes(Class<?>[] signature)
Returns
TypeInformation about the operands of the evaluation method with a given
signature. |
org.apache.flink.api.common.typeinfo.TypeInformation<?> |
getResultType(Class<?>[] signature)
Returns the result type of the evaluation method with a given signature.
|
close, functionIdentifier, open, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getRequirements, isDeterministic
public org.apache.flink.api.common.typeinfo.TypeInformation<?> getResultType(Class<?>[] signature)
This method needs to be overridden in case Flink's type extraction facilities are not
sufficient to extract the TypeInformation
based on the return type of the evaluation
method. Flink's type extraction facilities can handle basic types or
simple POJOs but might be wrong for more complex, custom, or composite types.
signature
- signature of the method the return type needs to be determinedTypeInformation
of result type or null
if Flink should
determine the typepublic org.apache.flink.api.common.typeinfo.TypeInformation<?>[] getParameterTypes(Class<?>[] signature)
TypeInformation
about the operands of the evaluation method with a given
signature.
In order to perform operand type inference in SQL (especially when NULL
is
used) it might be necessary to determine the parameter TypeInformation
of an
evaluation method. By default Flink's type extraction facilities are used for this but might
be wrong for more complex, custom, or composite types.
signature
- signature of the method the operand types need to be determinedTypeInformation
of operand typespublic final FunctionKind getKind()
FunctionDefinition
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.