Hi Yang, I previously wrote an article about Calcite UDF function implementation and extension, which introduced some details about UDFs. I hope it will be helpful to you. Article link: https://strongduanmu.com/blog/apache-calcite-catalog-udf-function-implementation-and-extension.html
Best regards, Zhengqiang Yang Zhou <[email protected]> 于2025年11月5日周三 10:52写道: > > 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 校验起作用,也可以在 执行阶段起作用。 >
