I have never used Java UDFs in Calcite, so I don't know the answer to your 
question. But if you have an example which works - the CSV one - then I suggest 
running it under a debugger, and comparing what happens with your own program.

Mihai


________________________________
From: Yang Zhou <[email protected]>
Sent: Tuesday, November 4, 2025 6:51 PM
To: [email protected] <[email protected]>
Subject: How should I understand UDF registration?

Hello I have a question. I'm learning how to define UDFs in Calcite.
Using the CSV example JAR as a base, I'm defining a UDF using `SqlFunction`. It 
only works during SQL validation, but during execution, it reports a "UDF not 
matched" error.


public class UAddStr extends SqlFunction {

  public UAddStr(String name, SqlKind kind, @Nullable SqlReturnTypeInference 
returnTypeInference, @Nullable SqlOperandTypeInference operandTypeInference, 
@Nullable SqlOperandTypeChecker operandTypeChecker, SqlFunctionCategory 
category) {
    super(name, kind, returnTypeInference, operandTypeInference, 
operandTypeChecker, category);
  }
}


public class ExtendedSqlOperatorTable extends ReflectiveSqlOperatorTable {
  private static ExtendedSqlOperatorTable instance;

  public static synchronized ExtendedSqlOperatorTable instance() {
    if (instance == null) {
      instance = new ExtendedSqlOperatorTable();
      instance.init();
    }
    instance.register(addStr());
    return instance;
  }

  private static SqlFunction addStr() {
    return new UAddStr("addStr",
            SqlKind.OTHER_FUNCTION,
            ReturnTypes.VARCHAR,
            null,
            OperandTypes.STRING,
            SqlFunctionCategory.USER_DEFINED_FUNCTION);
  }
}




If I use a UDF registered with Schmea, it also reports a "UDF not matched" 
error during SQL validation, but I can still query data during execution.
rootSchema.add("addstr", ScalarFunctionImpl.create(UAddStr.class, "addStr"));


What I don't understand is: how should I define a UDF that works in both SQL 
validation and execution?


中文介绍:
你好

想请教一个问题,我正在学习使用 在 Calcite 中定义 UDF 功能,
我以 csv example jar 为基础,我使用 SqlFunction 定义 UDF 它只能在 SQL 校验校验起作用,但是在 执行阶段 会报 udf 
无法匹配到。

如果使用 schmea 注册的UDF, 在 SQL 校验阶段它又会报 udf 无法匹配到,但是在执行阶段是可以查询数据的。

我没有想明白的是: 我应该怎么去定义一个 udf,让它既可以在 SQL 校验起作用,也可以在 执行阶段起作用。

Reply via email to