Skip to content

Commit aa0f47a

Browse files
committed
Flink UDF in Go
1 parent 8da88e7 commit aa0f47a

File tree

16 files changed

+482
-0
lines changed

16 files changed

+482
-0
lines changed

.classpath

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
14+
</attributes>
15+
</classpathentry>
16+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
17+
<attributes>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
</attributes>
25+
</classpathentry>
26+
<classpathentry kind="src" path="target/generated-sources/annotations">
27+
<attributes>
28+
<attribute name="optional" value="true"/>
29+
<attribute name="maven.pomderived" value="true"/>
30+
<attribute name="ignore_optional_problems" value="true"/>
31+
<attribute name="m2e-apt" value="true"/>
32+
</attributes>
33+
</classpathentry>
34+
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
35+
<attributes>
36+
<attribute name="optional" value="true"/>
37+
<attribute name="maven.pomderived" value="true"/>
38+
<attribute name="ignore_optional_problems" value="true"/>
39+
<attribute name="m2e-apt" value="true"/>
40+
<attribute name="test" value="true"/>
41+
</attributes>
42+
</classpathentry>
43+
<classpathentry kind="output" path="target/classes"/>
44+
</classpath>

.github/workflows/main.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Flink UDF in Go
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
java: [8, 11, 18, 19]
16+
fail-fast: false
17+
name: Test JDK ${{ matrix.java }}
18+
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v3
22+
with:
23+
submodules: true
24+
fetch-depth: 0
25+
26+
- name: Setup Java
27+
uses: actions/setup-java@v3
28+
with:
29+
distribution: 'temurin'
30+
java-version: ${{ matrix.java }}
31+
cache: 'maven'
32+
33+
# https://stackoverflow.com/questions/64706720/how-to-access-maven-dependency-from-github-packages-on-a-github-actions-workflow
34+
- name: Test
35+
env:
36+
USERNAME: ${{ secrets.USERNAME }}
37+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
38+
run: |
39+
mvn -s $GITHUB_WORKSPACE/.m2/settings.xml clean test --file pom.xml -Djna.debug_load=true -Djna.debug_load.jna=true

.github/workflows/release.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
with:
16+
submodules: true
17+
fetch-depth: 0
18+
19+
- name: Setup Java
20+
uses: actions/setup-java@v3
21+
with:
22+
distribution: 'temurin'
23+
java-version: 8
24+
cache: 'maven'
25+
26+
- name: Maven install
27+
env:
28+
USERNAME: ${{ secrets.USERNAME }}
29+
ACCESS_TOKEN: ${{ secrets.ACCESS_TOKEN }}
30+
run: |
31+
mvn -s $GITHUB_WORKSPACE/.m2/settings.xml install
32+
33+
- name: Publish to GitHub Packages Apache Maven
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
run: |
37+
mvn -B deploy

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Compiled class file
2+
target/*
3+
*.class
4+
5+
# Log file
6+
*.log
7+
8+
# BlueJ files
9+
*.ctxt
10+
11+
# Mobile Tools for Java (J2ME)
12+
.mtj.tmp/
13+
14+
# Package Files #
15+
*.jar
16+
*.war
17+
*.nar
18+
*.ear
19+
*.zip
20+
*.tar.gz
21+
*.rar
22+
23+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
24+
hs_err_pid*

.m2/settings.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
4+
http://maven.apache.org/xsd/settings-1.0.0.xsd">
5+
6+
<activeProfiles>
7+
<activeProfile>github</activeProfile>
8+
</activeProfiles>
9+
10+
<profiles>
11+
<profile>
12+
<id>github</id>
13+
<repositories>
14+
<repository>
15+
<id>central</id>
16+
<url>https://repo1.maven.org/maven2</url>
17+
</repository>
18+
<repository>
19+
<id>github</id>
20+
<url>https://maven.pkg.github.com/superbear/java-call-go</url>
21+
<snapshots>
22+
<enabled>true</enabled>
23+
<updatePolicy>always</updatePolicy>
24+
</snapshots>
25+
</repository>
26+
</repositories>
27+
</profile>
28+
</profiles>
29+
30+
<servers>
31+
<server>
32+
<id>github</id>
33+
<username>${env.USERNAME}</username>
34+
<password>${env.ACCESS_TOKEN}</password>
35+
</server>
36+
</servers>
37+
</settings>

.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>flink-udf-in-go</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.apt.aptEnabled=false
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.processAnnotations=disabled
8+
org.eclipse.jdt.core.compiler.release=disabled
9+
org.eclipse.jdt.core.compiler.source=1.5
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Flink UDF in Go
2+
3+
## Requirements
4+
- Java 8+, 64-bit
5+
- https://github.com/superbear/java-call-go
6+
7+
## How to build
8+
### Build
9+
```bash
10+
mvn clean package assembly:single
11+
```
12+
This creates a `flink-udf-in-go-1.0-SNAPSHOT-jar-with-dependencies.jar` in the `target/` directory.
13+
14+
### Test
15+
```bash
16+
mvn clean test
17+
```
18+
19+
## Usage
20+
Running the container
21+
```bash
22+
docker compose up -d
23+
```
24+
25+
Executing queries
26+
```bash
27+
docker compose run sql-client
28+
```
29+
```sql
30+
Flink SQL> CREATE FUNCTION atoi AS 'github.superbear.flink.udf.scalar.Atoi' LANGUAGE JAVA;
31+
Flink SQL> CREATE FUNCTION toupper AS 'github.superbear.flink.udf.scalar.ToUpper' LANGUAGE JAVA;
32+
33+
Flink SQL> SELECT atoi('123');
34+
Flink SQL> SELECT toupper('hello world');
35+
36+
Flink SQL> exit;
37+
```
38+
39+
## References
40+
[Flink User-defined Functions](https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/functions/udfs/)
41+
[Flink Docker Setup](https://nightlies.apache.org/flink/flink-docs-master/docs/deployment/resource-providers/standalone/docker/)

0 commit comments

Comments
 (0)