Skip to content

[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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

hawk9821
Copy link
Contributor

@hawk9821 hawk9821 commented Apr 17, 2025

Purpose of this pull request

custom udf throw Exception. remove seatunnel-transform-v2.jar from connecots to lib solve the problem .

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/seatunnel/transform/sql/zeta/ZetaUDF
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
	at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:411)
	at org.apache.seatunnel.engine.common.loader.SeaTunnelBaseClassLoader.loadClassWithoutExceptionHandling(SeaTunnelBaseClassLoader.java:56)
	at org.apache.seatunnel.engine.common.loader.SeaTunnelChildFirstClassLoader.loadClassWithoutExceptionHandling(SeaTunnelChildFirstClassLoader.java:97)
	at org.apache.seatunnel.engine.common.loader.SeaTunnelBaseClassLoader.loadClass(SeaTunnelBaseClassLoader.java:47)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:348)
	at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:370)
	at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
	at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
	at java.lang.Iterable.forEach(Iterable.java:74)
	at org.apache.seatunnel.transform.sql.zeta.ZetaSQLEngine.init(ZetaSQLEngine.java:88)
	at org.apache.seatunnel.transform.sql.SQLTransform.open(SQLTransform.java:94)
	at org.apache.seatunnel.transform.sql.SQLTransform.tryOpen(SQLTransform.java:103)
	at org.apache.seatunnel.transform.sql.SQLTransform.transformTableSchema(SQLTransform.java:115)
	at org.apache.seatunnel.transform.common.AbstractSeaTunnelTransform.transformCatalogTable(AbstractSeaTunnelTransform.java:69)
	at org.apache.seatunnel.transform.common.AbstractSeaTunnelTransform.getProducedCatalogTable(AbstractSeaTunnelTransform.java:54)
	at org.apache.seatunnel.transform.common.AbstractMultiCatalogTransform.lambda$new$3(AbstractMultiCatalogTransform.java:86)
	at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
	at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1382)
	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
	at org.apache.seatunnel.transform.common.AbstractMultiCatalogTransform.<init>(AbstractMultiCatalogTransform.java:88)
	at org.apache.seatunnel.transform.common.AbstractMultiCatalogFlatMapTransform.<init>(AbstractMultiCatalogFlatMapTransform.java:33)
	at org.apache.seatunnel.transform.sql.SQLMultiCatalogFlatMapTransform.<init>(SQLMultiCatalogFlatMapTransform.java:32)
	at org.apache.seatunnel.transform.sql.SQLTransformFactory.lambda$createTransform$0(SQLTransformFactory.java:51)
	at org.apache.seatunnel.api.table.factory.FactoryUtil.createAndPrepareMultiTableTransform(FactoryUtil.java:445)
	at org.apache.seatunnel.engine.core.parse.MultipleTableJobConfigParser.parseTransform(MultipleTableJobConfigParser.java:459)
	at org.apache.seatunnel.engine.core.parse.MultipleTableJobConfigParser.parseTransforms(MultipleTableJobConfigParser.java:408)
	at org.apache.seatunnel.engine.core.parse.MultipleTableJobConfigParser.parse(MultipleTableJobConfigParser.java:232)
	at org.apache.seatunnel.engine.client.job.ClientJobExecutionEnvironment.getLogicalDag(ClientJobExecutionEnvironment.java:123)
	at org.apache.seatunnel.engine.client.job.ClientJobExecutionEnvironment.execute(ClientJobExecutionEnvironment.java:191)
	at org.apache.seatunnel.core.starter.seatunnel.command.ClientExecuteCommand.execute(ClientExecuteCommand.java:165)
	at org.apache.seatunnel.core.starter.SeaTunnel.run(SeaTunnel.java:40)
	at org.apache.seatunnel.core.starter.seatunnel.SeaTunnelClient.main(SeaTunnelClient.java:34)
Caused by: java.lang.ClassNotFoundException: org.apache.seatunnel.transform.sql.zeta.ZetaUDF
	at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 49 more

Does this PR introduce any user-facing change?

How was this patch tested?

e2e case : ExampleUdfIT

Check list

@github-actions github-actions bot added core SeaTunnel core module e2e labels Apr 17, 2025
@hawk9821 hawk9821 changed the title Custom udf [BUG][Transform-v2]Custom udf throw exception Apr 17, 2025
<include>org.apache.seatunnel:seatunnel-transforms-v2:jar</include>
</includes>
<outputFileNameMapping>${artifact.file.name}</outputFileNameMapping>
<outputDirectory>/lib</outputDirectory>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? This conflicts with pr #7218

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pr #7218 does not consider the scenarios of custom udf , moved seatunnel-transform-v2.jar to connectors will throw exception.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core reason is NoClassDefFoundError org.apache.seatunnel.transform.sql.zeta.ZetaUDF. It would be more appropriate to move interface org.apache.seatunnel.transform.sql.zeta.ZetaUDF to the api module

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions github-actions bot added Transform-v2 api and removed core SeaTunnel core module labels Apr 17, 2025
@nielifeng nielifeng requested a review from Copilot April 18, 2025 01:31
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request addresses a NoClassDefFoundError in custom UDFs by updating the import paths for ZetaUDF and relocating the transform UDF jar from the connectors directory to the lib directory.

  • Update import statements in several UDF-related classes to use the new org.apache.seatunnel.api.transform.sql.ZetaUDF package
  • Adjust the container copy logic to load the transform UDF jar from the lib directory
  • Update the API package for ZetaUDF accordingly

Reviewed Changes

Copilot reviewed 9 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/udf/DesEncrypt.java Updated ZetaUDF import to the new API package
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/functions/udf/DesDecrypt.java Updated ZetaUDF import to the new API package
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLType.java Added import for ZetaUDF from the API package
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLFunction.java Added import for ZetaUDF from the API package
seatunnel-transforms-v2/src/main/java/org/apache/seatunnel/transform/sql/zeta/ZetaSQLEngine.java Added import for ZetaUDF from the API package
seatunnel-e2e/seatunnel-transforms-v2-e2e/seatunnel-transforms-v2-udf/src/main/java/org/apache/seatunnel/e2e/transform/udf/ExampleUdf.java Provides an example implementation for custom UDF testing
seatunnel-e2e/seatunnel-transforms-v2-e2e/seatunnel-transforms-v2-e2e-udf/src/test/java/org/apache/seatunnel/e2e/transform/udf/ExampleUdfIT.java End-to-end integration test for the custom UDF
seatunnel-e2e/seatunnel-e2e-common/src/test/java/org/apache/seatunnel/e2e/common/util/ContainerUtil.java Updated the container copy logic to move the UDF jar to the lib directory
seatunnel-api/src/main/java/org/apache/seatunnel/api/transform/sql/ZetaUDF.java Changed the package to the new API namespace for ZetaUDF
Files not reviewed (4)
  • seatunnel-e2e/seatunnel-transforms-v2-e2e/pom.xml: Language not supported
  • seatunnel-e2e/seatunnel-transforms-v2-e2e/seatunnel-transforms-v2-e2e-udf/pom.xml: Language not supported
  • seatunnel-e2e/seatunnel-transforms-v2-e2e/seatunnel-transforms-v2-e2e-udf/src/test/resources/custom_udf.conf: Language not supported
  • seatunnel-e2e/seatunnel-transforms-v2-e2e/seatunnel-transforms-v2-udf/pom.xml: Language not supported

@Hisoka-X Hisoka-X changed the title [BUG][Transform-v2]Custom udf throw exception [Fix][Transform-v2] Fix custom udf throw exception Apr 21, 2025
@@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.seatunnel.transform.sql.zeta;
package org.apache.seatunnel.api.transform.sql;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we move UDF to api module. Why we still need move seatunnel-transform-v2.jar to libs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed. assembly-bin.xml is rollbacked

@liunaijie
Copy link
Member

Thanks @hawk9821 point this issue, this is a bug, good catch.

It would be more appropriate to move interface org.apache.seatunnel.transform.sql.zeta.ZetaUDF to the api module

I tested with this fix, it works. But I don’t understand why these changes can be work. Can you give me some hint? Thanks.

BTW, when do this update, it can impact the user that has implment udf. it need update the udf lib, update the class full name, we need describe this in the document or release note (Breaking Change).

@github-actions github-actions bot removed the api label Apr 23, 2025
@hawk9821
Copy link
Contributor Author

Thanks @hawk9821 point this issue, this is a bug, good catch.

It would be more appropriate to move interface org.apache.seatunnel.transform.sql.zeta.ZetaUDF to the api module

I tested with this fix, it works. But I don’t understand why these changes can be work. Can you give me some hint? Thanks.

BTW, when do this update, it can impact the user that has implment udf. it need update the udf lib, update the class full name, we need describe this in the document or release note (Breaking Change).

The compatibility issue was indeed not considered. It has been fixed in the way of moving transform-v2.jar to the lib .

<outputDirectory>/lib</outputDirectory>
<scope>provided</scope>
</dependencySet>

<!-- ============ Connectors Jars And Transforms V2 Jar ============ -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<!-- ============ Connectors Jars And Transforms V2 Jar ============ -->
<!-- ============ Connectors Jars ============ -->

@@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.seatunnel.transform.sql.zeta;
package org.apache.seatunnel.transform.sql.zeta.functions.udf;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why move the package of ZetaUDF?

@hailin0
Copy link
Member

hailin0 commented Apr 24, 2025

Need to delete transform from plugin-mapping.properties?
https://github.com/apache/seatunnel/blob/dev/plugin-mapping.properties #L148

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core SeaTunnel core module e2e Transform-v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants