28
28
import org .apache .flink .table .catalog .DataTypeFactory ;
29
29
import org .apache .flink .table .catalog .ObjectIdentifier ;
30
30
import org .apache .flink .table .catalog .UnresolvedIdentifier ;
31
+ import org .apache .flink .table .functions .AsyncScalarFunction ;
31
32
import org .apache .flink .table .functions .FunctionDefinition ;
32
33
import org .apache .flink .table .functions .FunctionIdentifier ;
33
34
import org .apache .flink .table .functions .FunctionKind ;
80
81
import java .util .Collections ;
81
82
import java .util .Optional ;
82
83
import java .util .Set ;
84
+ import java .util .concurrent .CompletableFuture ;
83
85
import java .util .stream .Stream ;
84
86
85
87
import static org .apache .flink .core .testutils .FlinkAssertions .anyCauseMatches ;
@@ -104,15 +106,25 @@ public class RexNodeJsonSerdeTest {
104
106
new FlinkTypeFactory (
105
107
RexNodeJsonSerdeTest .class .getClassLoader (), FlinkTypeSystem .INSTANCE );
106
108
private static final String FUNCTION_NAME = "MyFunc" ;
109
+ private static final String ASYNC_FUNCTION_NAME = "MyAsyncFunc" ;
107
110
private static final FunctionIdentifier FUNCTION_SYS_ID = FunctionIdentifier .of (FUNCTION_NAME );
108
111
private static final FunctionIdentifier FUNCTION_CAT_ID =
109
112
FunctionIdentifier .of (
110
113
ObjectIdentifier .of (DEFAULT_CATALOG , DEFAULT_DATABASE , FUNCTION_NAME ));
114
+ private static final FunctionIdentifier ASYNC_FUNCTION_CAT_ID =
115
+ FunctionIdentifier .of (
116
+ ObjectIdentifier .of (DEFAULT_CATALOG , DEFAULT_DATABASE , ASYNC_FUNCTION_NAME ));
111
117
private static final UnresolvedIdentifier UNRESOLVED_FUNCTION_CAT_ID =
112
118
UnresolvedIdentifier .of (FUNCTION_CAT_ID .toList ());
119
+ private static final UnresolvedIdentifier UNRESOLVED_ASYNC_FUNCTION_CAT_ID =
120
+ UnresolvedIdentifier .of (ASYNC_FUNCTION_CAT_ID .toList ());
113
121
private static final SerializableScalarFunction SER_UDF_IMPL = new SerializableScalarFunction ();
122
+ private static final SerializableAsyncScalarFunction SER_ASYNC_UDF_IMPL =
123
+ new SerializableAsyncScalarFunction ();
114
124
private static final Class <SerializableScalarFunction > SER_UDF_CLASS =
115
125
SerializableScalarFunction .class ;
126
+ private static final Class <SerializableAsyncScalarFunction > SER_ASYNC_UDF_CLASS =
127
+ SerializableAsyncScalarFunction .class ;
116
128
private static final OtherSerializableScalarFunction SER_UDF_IMPL_OTHER =
117
129
new OtherSerializableScalarFunction ();
118
130
private static final Class <OtherSerializableScalarFunction > SER_UDF_CLASS_OTHER =
@@ -140,6 +152,12 @@ public void testInlineFunction() throws IOException {
140
152
createFunctionCall (serdeContext , ContextResolvedFunction .anonymous (SER_UDF_IMPL )),
141
153
RexNode .class );
142
154
155
+ // Serializable async function
156
+ testJsonRoundTrip (
157
+ createFunctionCall (
158
+ serdeContext , ContextResolvedFunction .anonymous (SER_ASYNC_UDF_IMPL )),
159
+ RexNode .class );
160
+
143
161
// Non-serializable function due to fields
144
162
assertThatThrownBy (
145
163
() ->
@@ -732,6 +750,11 @@ private static SerdeContext serdeContextWithPermanentFunction(
732
750
.getFlinkContext ()
733
751
.getFunctionCatalog ()
734
752
.registerCatalogFunction (UNRESOLVED_FUNCTION_CAT_ID , SER_UDF_CLASS , false );
753
+ serdeContext
754
+ .getFlinkContext ()
755
+ .getFunctionCatalog ()
756
+ .registerCatalogFunction (
757
+ UNRESOLVED_ASYNC_FUNCTION_CAT_ID , SER_ASYNC_UDF_CLASS , false );
735
758
return serdeContext ;
736
759
}
737
760
@@ -834,6 +857,15 @@ public boolean equals(Object obj) {
834
857
}
835
858
}
836
859
860
+ /** Serializable async function. */
861
+ public static class SerializableAsyncScalarFunction extends AsyncScalarFunction {
862
+
863
+ @ SuppressWarnings ("unused" )
864
+ public void eval (CompletableFuture <String > res , Integer i ) {
865
+ throw new UnsupportedOperationException ();
866
+ }
867
+ }
868
+
837
869
/** Non-serializable function. */
838
870
public static class NonSerializableScalarFunction extends ScalarFunction {
839
871
@ SuppressWarnings ({"FieldCanBeLocal" , "unused" })
0 commit comments