Skip to content

Commit 7082403

Browse files
Apply suggestions from code review
Co-authored-by: Thomas Cooper <code@tomcooper.dev>
1 parent dc44d33 commit 7082403

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

docs/user-defined-functions/index.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,15 @@ FROM InternationalSalesRecordTable;
9292
First, we will create a blank Maven project:
9393

9494
```shell
95-
cd ~
9695

9796
mvn archetype:generate \
98-
-DgroupId=com.github.example \
99-
-DartifactId=currency-converter \
97+
-DgroupId=com.github.streamshub \
98+
-DartifactId=flink-udf-currency-converter \
10099
-DarchetypeArtifactId=maven-archetype-quickstart \
101100
-DarchetypeVersion=1.5 \
102101
-DinteractiveMode=false
103102

104-
cd ~/currency-converter
103+
cd ~/flink-udf-currency-converter
105104
```
106105

107106
> 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
190189
```shell
191190
sed -i -e 's/App/CurrencyConverter/g' src/main/java/com/github/example/App.java
192191

193-
mv src/main/java/com/github/example/App.java src/main/java/com/github/example/CurrencyConverter.java
192+
mv src/main/java/com/github/example/App.java src/main/java/com/github/streamshub/CurrencyConverter.java
194193
```
195194

196195
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
224223

225224
> 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).
226225
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.
228229

229230
### Extending the `ScalarFunction` base class
230231

@@ -234,7 +235,7 @@ Let's start by making our `CurrencyConverter` class extend the `ScalarFunction`
234235

235236
```java
236237
// ~/currency-converter/src/main/java/com/github/example/CurrencyConverter.java
237-
package com.github.example;
238+
package com.github.streamshub;
238239

239240
import org.apache.flink.table.functions.ScalarFunction;
240241

@@ -259,7 +260,8 @@ public class CurrencyConverter extends ScalarFunction {
259260
}
260261
```
261262

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.
263265

264266
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:
265267

@@ -424,7 +426,7 @@ In order to try the UDF you will need:
424426

425427
### Running the UDF
426428

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.
428430

429431
First, we need to port forward the Flink Job Manager pod so the Flink SQL CLI can access it:
430432

@@ -484,7 +486,7 @@ AS 'com.github.example.CurrencyConverter'
484486
USING JAR '/opt/currency-converter-1.0-SNAPSHOT.jar';
485487
```
486488

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.
488490

489491
> 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.
490492

0 commit comments

Comments
 (0)