-
Notifications
You must be signed in to change notification settings - Fork 2k
[Fix][Transform-v2] Fix custom udf throw exception #9195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
eda98f2
0fd9ab5
10cde5d
73a6158
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -187,6 +187,19 @@ | |||||
<scope>provided</scope> | ||||||
</dependencySet> | ||||||
|
||||||
<!-- ============ SeaTunnel Transforms-v2 Jar============ --> | ||||||
<dependencySet> | ||||||
<useProjectArtifact>false</useProjectArtifact> | ||||||
<useTransitiveDependencies>true</useTransitiveDependencies> | ||||||
<unpack>false</unpack> | ||||||
<includes> | ||||||
<include>org.apache.seatunnel:seatunnel-transforms-v2:jar</include> | ||||||
</includes> | ||||||
<outputFileNameMapping>${artifact.file.name}</outputFileNameMapping> | ||||||
<outputDirectory>/lib</outputDirectory> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why? This conflicts with pr #7218 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pr #7218 does not consider the scenarios of custom udf , moved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The core reason is NoClassDefFoundError There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||
<scope>provided</scope> | ||||||
</dependencySet> | ||||||
|
||||||
<!-- ============ Connectors Jars And Transforms V2 Jar ============ --> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<!-- SeaTunnel connectors for Demo --> | ||||||
<dependencySet> | ||||||
|
@@ -196,7 +209,6 @@ | |||||
<includes> | ||||||
<include>org.apache.seatunnel:connector-fake:jar</include> | ||||||
<include>org.apache.seatunnel:connector-console:jar</include> | ||||||
<include>org.apache.seatunnel:seatunnel-transforms-v2:jar</include> | ||||||
</includes> | ||||||
<outputDirectory>/connectors</outputDirectory> | ||||||
<scope>provided</scope> | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-transforms-v2-e2e</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>seatunnel-transforms-v2-e2e-udf</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>seatunnel-transforms-v2-e2e-udf</name> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-transforms-v2-e2e-common</artifactId> | ||
<version>${project.version}</version> | ||
<type>test-jar</type> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-transforms-v2-udf</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.e2e.transform.udf; | ||
|
||
import org.apache.seatunnel.e2e.common.TestSuiteBase; | ||
import org.apache.seatunnel.e2e.common.container.EngineType; | ||
import org.apache.seatunnel.e2e.common.container.TestContainer; | ||
import org.apache.seatunnel.e2e.common.junit.DisabledOnContainer; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.TestTemplate; | ||
import org.testcontainers.containers.Container; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.io.IOException; | ||
|
||
@DisabledOnContainer( | ||
value = {}, | ||
type = {EngineType.SPARK, EngineType.FLINK}, | ||
disabledReason = "Custom UDF is supported in Zeta") | ||
@Slf4j | ||
public class ExampleUdfIT extends TestSuiteBase { | ||
|
||
@TestTemplate | ||
public void testCustomUdf(TestContainer container) throws IOException, InterruptedException { | ||
Container.ExecResult execResult = container.executeJob("/custom_udf.conf"); | ||
Assertions.assertEquals(0, execResult.getExitCode()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
###### | ||
###### This config file is a demonstration of streaming processing in seatunnel config | ||
###### | ||
|
||
env { | ||
parallelism = 1 | ||
job.mode = "BATCH" | ||
checkpoint.interval = 10000 | ||
} | ||
|
||
source { | ||
FakeSource { | ||
plugin_output = "fake" | ||
schema = { | ||
fields { | ||
id = "int" | ||
name = "string" | ||
} | ||
} | ||
rows = [ | ||
{fields = [1, "Hello World"], kind = INSERT} | ||
] | ||
} | ||
} | ||
|
||
transform { | ||
sql { | ||
plugin_input = "fake" | ||
plugin_output = "fake1" | ||
query = "select id, EXAMPLE(name) as name from dual" | ||
} | ||
} | ||
|
||
sink { | ||
Assert { | ||
plugin_input = "fake1" | ||
rules = { | ||
field_rules = [ | ||
{ | ||
field_name = "id" | ||
field_type = "int" | ||
field_value = [ | ||
{equals_to = 1} | ||
] | ||
}, | ||
{ | ||
field_name = "name" | ||
field_type = "string" | ||
field_value = [ | ||
{equals_to = "UDF: Hello World"} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-transforms-v2-e2e</artifactId> | ||
<version>${revision}</version> | ||
</parent> | ||
|
||
<artifactId>seatunnel-transforms-v2-udf</artifactId> | ||
<packaging>jar</packaging> | ||
|
||
<name>seatunnel-transforms-v2-udf</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-transforms-v2</artifactId> | ||
<version>${revision}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.seatunnel</groupId> | ||
<artifactId>seatunnel-api</artifactId> | ||
<version>${revision}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.auto.service</groupId> | ||
<artifactId>auto-service</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<finalName>${project.artifactId}</finalName> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<configuration> | ||
<artifactSet> | ||
<excludes> | ||
<exclude>io.prometheus:simpleclient</exclude> | ||
<exclude>io.prometheus:simpleclient_hotspot</exclude> | ||
<exclude>io.prometheus:simpleclient_httpserver</exclude> | ||
</excludes> | ||
</artifactSet> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.seatunnel.e2e.transform.udf; | ||
|
||
import org.apache.seatunnel.api.table.type.BasicType; | ||
import org.apache.seatunnel.api.table.type.SeaTunnelDataType; | ||
import org.apache.seatunnel.transform.sql.zeta.functions.udf.ZetaUDF; | ||
|
||
import com.google.auto.service.AutoService; | ||
|
||
import java.util.List; | ||
|
||
@AutoService(ZetaUDF.class) | ||
public class ExampleUdf implements ZetaUDF { | ||
|
||
@Override | ||
public String functionName() { | ||
return "EXAMPLE"; | ||
} | ||
|
||
@Override | ||
public SeaTunnelDataType<?> resultType(List<SeaTunnelDataType<?>> list) { | ||
return BasicType.STRING_TYPE; | ||
} | ||
|
||
@Override | ||
public Object evaluate(List<Object> args) { | ||
String arg = (String) args.get(0); | ||
if (arg == null) return null; | ||
return "UDF: " + arg; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can leave a demo about how to create plugin-mapping for new custom transform.