You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Note: Flink provides a [Maven Archetype and quickstart script](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/configuration/overview/#getting-started) for getting started. However, it includes a lot of dependencies and boilerplate we don't need for this tutorial, so we will start with a minimal Maven project instead.
@@ -190,7 +189,7 @@ Next, we will rename the `App` class to `CurrencyConverter` and rename the file
190
189
```shell
191
190
sed -i -e 's/App/CurrencyConverter/g' src/main/java/com/github/example/App.java
The project should still build and run successfully at this point, we can run the following commands to verify:
@@ -224,7 +223,9 @@ To make our UDF, we will need to extend the [`ScalarFunction`](https://nightlies
224
223
225
224
> Note: Notice how we should specify the `provided` scope, in order to exclude the dependency from our JAR. We should to do this for any core Flink API dependencies we add. Otherwise, the core Flink API dependencies in our JAR [could clash with some of our other dependency versions](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/configuration/maven/#adding-dependencies-to-the-project).
226
225
227
-
We don't need any external dependencies in our JAR (apart from Flink). But, if we did want to add some, we would need to either [shade them into an uber/fat JAR or add them to the classpath of the distribution](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/configuration/maven/#packaging-the-application). If you want to do the former, the [Flink docs provide a template](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/configuration/maven/#template-for-creating-an-uberfat-jar-with-dependencies) on how to use the [Maven Shade Plugin](https://maven.apache.org/plugins/maven-shade-plugin/index.html) to do so.
226
+
We don't need any external dependencies in our JAR (apart from Flink).
227
+
But, if we did want to add some, we would need to either [shade them into an uber/fat JAR or add them to the classpath of the distribution](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/configuration/maven/#packaging-the-application).
228
+
If you want to do the former, the [Flink docs provide a template](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/configuration/maven/#template-for-creating-an-uberfat-jar-with-dependencies) on how to use the [Maven Shade Plugin](https://maven.apache.org/plugins/maven-shade-plugin/index.html) to do so.
228
229
229
230
### Extending the `ScalarFunction` base class
230
231
@@ -234,7 +235,7 @@ Let's start by making our `CurrencyConverter` class extend the `ScalarFunction`
@@ -259,7 +260,8 @@ public class CurrencyConverter extends ScalarFunction {
259
260
}
260
261
```
261
262
262
-
Flink's [Automatic Type Inference](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/table/functions/udfs/#automatic-type-inference) will use reflection to derive SQL data types for the argument and result of our UDF. If you want to override this behavior, you can [explicitly specify the types]((https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/table/functions/udfs/#automatic-type-inference)), but in this case we will keep it simple and let Flink decide for us.
263
+
Flink's [Automatic Type Inference](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/table/functions/udfs/#automatic-type-inference) will use reflection to derive SQL data types for the argument and result of our UDF.
264
+
If you want to override this behaviour, you can [explicitly specify the types]((https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/table/functions/udfs/#automatic-type-inference)), but in this case we will keep it simple and let Flink decide for us.
263
265
264
266
If we look at the [Data Generator](https://github.com/streamshub/flink-sql-examples/blob/main/data-generator/src/main/java/com/github/streamshub/kafka/data/generator/examples/InternationalSalesData.java) in the StreamsHub [Flink SQL Examples](https://github.com/streamshub/flink-sql-examples) repository, we can see the possible currency symbols that can appear in the `unit_cost` field:
265
267
@@ -424,7 +426,7 @@ In order to try the UDF you will need:
424
426
425
427
### Running the UDF
426
428
427
-
Since we want to try the UDF in different scenarios, we will create a container containing the Flink SQL CLI to run our queries (see the [Interactive ETL example](../interactive-etl/index.md) for details on the CLI).
429
+
In order to use our UDF we need to create a container containing it and the Flink runtime.
428
430
429
431
First, we need to port forward the Flink Job Manager pod so the Flink SQL CLI can access it:
430
432
@@ -484,7 +486,7 @@ AS 'com.github.example.CurrencyConverter'
484
486
USING JAR '/opt/currency-converter-1.0-SNAPSHOT.jar';
485
487
```
486
488
487
-
> Note: Temporary catalog functions [only live as long as the current session](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/table/functions/overview/#types-of-functions). You can omit the `TEMPORARY` keyword to create a catalog function that persists across sessions.
489
+
> Note: Temporary catalog functions [only live as long as the current session](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/table/functions/overview/#types-of-functions). Provided you have a [Flink catalog](https://nightlies.apache.org/flink/flink-docs-release-2.0/docs/dev/table/catalogs/#catalogs) deployed and configured, you can omit the `TEMPORARY` keyword to create a function that persists across sessions.
488
490
489
491
> Note: This statement may succeed even if the JAR was not found or has insufficient permissions. You will likely only find this out when you try to use the UDF in a query.
0 commit comments