Skip to content
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

UdfSchemaProvider doesn't work with Structs #5286

Closed
agavra opened this issue May 5, 2020 · 0 comments · Fixed by #5287
Closed

UdfSchemaProvider doesn't work with Structs #5286

agavra opened this issue May 5, 2020 · 0 comments · Fixed by #5287
Assignees
Labels
Milestone

Comments

@agavra
Copy link
Contributor

agavra commented May 5, 2020

Describe the bug

@UdfSchemaProvider should be usable with UDFs that return Struct, but it fails to register such UDFs.

To Reproduce

The following UDF fails to register:

  @UdfDescription(
      name = "KsqlStructUdf",
      description = "A test-only UDF for testing struct return types")
  public static class KsqlStructUdf {

    private static final SqlStruct RETURN =
        SqlStruct.builder().field("VAL", SqlTypes.STRING).build();

    @UdfSchemaProvider
    public SqlType provide(final List<SqlType> params) {
      return RETURN;
    }

    @Udf(schemaProvider = "provide")
    public Struct getDecimalStruct() {
      return null;
    }
  }

Expected behavior
Should register

Actual behaviour

[2020-05-05 15:11:23,955] WARN Failed to add UDF to the MetaStore. name=KsqlStructUdf method=public org.apache.kafka.connect.data.Struct io.confluent.ksql.function.UdfLoaderTest$KsqlStructUdf.getDecimalStruct() (io.confluent.ksql.function.UdfLoader:113)
io.confluent.ksql.util.KsqlException: Could not load UDF method with signature: public org.apache.kafka.connect.data.Struct io.confluent.ksql.function.UdfLoaderTest$KsqlStructUdf.getDecimalStruct()
	at io.confluent.ksql.function.FunctionLoaderUtils.getReturnType(FunctionLoaderUtils.java:176)
	at io.confluent.ksql.function.FunctionLoaderUtils.getReturnType(FunctionLoaderUtils.java:161)
	at io.confluent.ksql.function.UdfLoader.createFunction(UdfLoader.java:148)
	at io.confluent.ksql.function.UdfLoader.loadUdfFromClass(UdfLoader.java:106)
	at io.confluent.ksql.function.UserFunctionLoader.loadFunctions(UserFunctionLoader.java:122)
	at io.confluent.ksql.function.UserFunctionLoader.load(UserFunctionLoader.java:84)
	at io.confluent.ksql.function.UdfLoaderTest.initializeFunctionRegistry(UdfLoaderTest.java:1293)
	at io.confluent.ksql.function.UdfLoaderTest.<clinit>(UdfLoaderTest.java:98)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:250)
	at org.junit.runners.BlockJUnit4ClassRunner.createTest(BlockJUnit4ClassRunner.java:260)
	at org.junit.runners.BlockJUnit4ClassRunner$2.runReflectiveCall(BlockJUnit4ClassRunner.java:309)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
Caused by: io.confluent.ksql.util.KsqlException: Type inference is not supported for: class org.apache.kafka.connect.data.Struct
	at io.confluent.ksql.execution.function.UdfUtil.handleParameterizedType(UdfUtil.java:138)
	at io.confluent.ksql.execution.function.UdfUtil.getSchemaFromType(UdfUtil.java:100)
	at io.confluent.ksql.function.FunctionLoaderUtils.getReturnType(FunctionLoaderUtils.java:170)
	... 32 more
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants