What language is this?

> On Mar 20, 2023, at 9:01 AM, Guillaume Masse <[email protected]> 
> wrote:
> 
> Hi All,
> 
> How can we register a custom udf? I found some solutions on Stackoverflow
> but they are out of date (
> https://stackoverflow.com/questions/44147819/adding-a-user-defined-function-to-calcite
> )
> 
> So far what I have:
> 
> // top level class
> class CustomUdf {
>  def foo(in: Double): Double = in + 1
> }
> 
> // somewhere else
> val typeFactory = new JavaTypeFactoryImpl()
> 
> val root = CalciteSchema.createRootSchema(false)
> root.plus().add("foo", ScalarFunctionImpl.create(classOf[CustomUdf], "foo"))
> 
> val catalogReader = new CalciteCatalogReader(
>  root,
>  Collections.emptyList(),
>  typeFactory,
>  CalciteConnectionConfig.DEFAULT
> )
> 
> val operators =
>  SqlLibraryOperatorTableFactory.INSTANCE.getOperatorTable(
>    SqlLibrary.STANDARD,
>    SqlLibrary.SPARK
>  )
> 
> val sqlValidator = SqlValidatorUtil.newValidator(
>  operators,
>  catalogReader,
>  typeFactory,
>  SqlValidator.Config.DEFAULT
> )
> 
> simple expression failed to
> validate,org.apache.calcite.runtime.CalciteContextException: From line 1,
> column 1 to line 1, column 22: No match found for function signature
> toto(<NUMERIC>))
> 
> From what I saw on Stackoverflow, it looks like I need to also add the
> function to the operator table.
> 
> Thanks!
> Guillaume Massé (马赛卫)

Reply via email to