T
- The type of the output row@Experimental public abstract class AsyncTableFunction<T> extends UserDefinedFunction
TableFunction
but this function is asynchronously.
A user-defined table functions works on zero, one, or multiple scalar values as input and returns multiple rows as output.
The behavior of a AsyncTableFunction
can be defined by implementing a custom evaluation
method. An evaluation method must be declared publicly, not static and named "eval".
Evaluation methods can also be overloaded by implementing multiple methods named "eval".
The first parameter of evaluation method must be CompletableFuture
, and the others are
user defined input parameters like the "eval" method of TableFunction
. The generic type of
CompletableFuture
must be Collection
to collect multiple possible result
values.
For each "eval", an async io operation can be triggered, and once it has been done,
the result can be collected by calling CompletableFuture.complete(T)
. For each async
operation, its context is stored in the operator immediately after invoking "eval",
avoiding blocking for each stream input as long as the internal buffer is not full.
CompletableFuture
can be passed into callbacks or futures to collect the result data.
An error can also be propagate to the async IO operator by
CompletableFuture.completeExceptionally(Throwable)
.
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. Currently, only support Row
and BaseRow
as
the result type. Will support more complex, custom types in the future.
Example:
public class HBaseAsyncTableFunction extends AsyncTableFunction<String> {
// implement an "eval" method with as many parameters as you want
public void eval(CompletableFuture<Collection<String>> result, String rowkey) {
Get get = new Get(Bytes.toBytes(rowkey));
ListenableFuture<Result> future = hbase.asyncGet(get);
Futures.addCallback(future, new FutureCallback<Result>() {
public void onSuccess(Result result) {
List<String> ret = process(result);
result.complete(ret);
}
public void onFailure(Throwable thrown) {
result.completeExceptionally(thrown);
}
});
}
// you can overload the eval method here ...
}
NOTE: the AsyncTableFunction
can not be used as UDTF currently. It only used in
temporal table join as an async lookup function.
Constructor and Description |
---|
AsyncTableFunction() |
Modifier and Type | Method and Description |
---|---|
FunctionKind |
getKind()
Returns the kind of function this definition describes.
|
org.apache.flink.api.common.typeinfo.TypeInformation<T> |
getResultType()
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<T> getResultType()
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.
TypeInformation
of result type or null
if Flink should determine the typepublic final FunctionKind getKind()
FunctionDefinition
Copyright © 2014–2019 The Apache Software Foundation. All rights reserved.