com.ibm.streams.function.model
Annotation Type Function
-
@Documented @Retention(value=RUNTIME) @Target(value=METHOD) public @interface FunctionDeclare an SPL Java native function. A method annotated with@Functionallows the method to be called as a Java native function from SPL. The annotated method must bepublicandstatic. The method may use classes from other libraries specified with theToolkitLibrariesannotation.A Java method annotated with
@Functionis automatically created as an SPL native function during toolkit indexing. The resulting function that can be called from SPL:- Has an SPL namespace defined according to
namespace(). - Is a public function.
- Has an SPL name defined according to
name(). - Has SPL parameter and return types according to the supported mapping.
- Has immutable parameters.
- Is stateful if
stateful()is true.
Supported mapping of Java types to SPL types for native functions is:
SPL Java native function type mapping Java method parameter or return type SPL Types Notes voidvoidReturn type only. booleanbooleanbyteint8,uint8When the method has integral Java primitive parameter types or arrays of integral primitive parameter types, then multiple SPL functions are generated to support signed and unsigned integral SPL types. Each resulting function prototype defines that all integral Java primitive types are mapped to either all signed or all unsigned SPL types. For example all intandlongparameters and return type must map toint32andint64, respectively, or touint32anduint64, respectively, and similarly for the corresponding list types, and a mix ofint32anduint32expressions is not allowed in a single SPL Java function invocation. When a Java integral primitive type is used only as the return type for the method, and there are no integral Java primitive parameter types, then the SPL function prototype supports returning only the signed SPL integral. For example a method that returns ashortand takes no arguments has a single SPL function prototype returning anint16. When an unsigned integral SPL type is passed to, or returned from, an SPL Java native function, it is mapped to a signed Java type, and so the result might not be correct if a value exceeds the maximum positive value supported by the signed Java type.shortint16,uint16intint32,uint32longint64,uint64floatfloat32doublefloat64Stringrstring,rstring[n],ustringWhen the function has StringorString[]parameters the prototype for the SPL function uses a single generic<string T>to represent allStringandString[]parameters and the return type if it is of typeStringorString[]. If the method has a return type ofStringorString[]without anyStringorString[]parameters then the SPL function has a return type ofrstring, orlist<rstring>(andlist<rstring>[m]if there are other array parameters), respectively.boolean[]list<boolean>,list<boolean>[m]byte[]list<int8>,list<int8>[m],list<uint8>,list<uint8>[m]See above note for integral primitive types to see how signed and unsigned SPL types are supported. short[]list<int16>,list<int16>[m],list<uint16>,list<uint16>[m]int[]list<int32>,list<int32>[m],list<uint32>,list<uint32>[m]long[]list<int64>,list<int64>[m],list<uint64>,list<uint64>[m]float[]list<float32>,list<float32>[m]double[]list<float64>,list<float64>[m]String[]list<rstring>,list<rstring>[m],list<rstring[n]>,list<rstring[n]>[m],list<ustring>,list<ustring>[m]See above note for string types. When the Java method has
Stringor array parameters, then the prototypes for the automatically generated SPL native functions define that all bounded-length strings have the same upper bound, and all bounded-length lists have the same upper bound. If the Java method returns an array and does not have any array parameters, then the SPL function has a return type of an unbounded array only.Here's an example which allows the method to be called from SPL code as "res = sum(a, b)":
@Function public static int sum(int a, int b) { return a + b; }- Since:
- InfoSphere® Streams Version 3.2
- Has an SPL namespace defined according to
-
-
Optional Element Summary
Optional Elements Modifier and Type Optional Element and Description java.lang.StringdescriptionDescription for the native function.java.lang.StringnameName of the function.java.lang.StringnamespaceSPL namespace of the Java native function.booleanstatefulDeclare the function as stateful or stateless.
-
-
-
Element Detail
-
namespace
public abstract java.lang.String namespace
SPL namespace of the Java native function. The SPL namespace of the function is:- The value of this
namespaceelement of the annotation if it is explicitly present. - Otherwise, the value of the
Namespaceannotation for the package of the annotated method, if it exists. - Otherwise, the package name of the annotated method.
- Returns:
- Namespace for the native function
- See Also:
Namespace
- Default:
- ""
- The value of this
-
-
-
name
public abstract java.lang.String name
Name of the function. If thisnameelement is the default value (the empty string) then the name of the function is the name of the annotated method. The name of the function must be a valid SPL identifier.- Returns:
- Name of the native function
- Default:
- ""
-
-
-
stateful
public abstract boolean stateful
Declare the function as stateful or stateless. Functions are stateless by default. A stateful function is a function that is not referentially transparent or has side-effects. A function is not referentially transparent if it does not consistently yield the same result each time it is called with the same inputs. A function has side-effects if it modifies state observable outside the function.- Returns:
- True if the function is stateful, false if it is stateless.
- Default:
- false
-
-