[ 
https://issues.apache.org/jira/browse/CALCITE-3000?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

pengzhiwei updated CALCITE-3000:
--------------------------------
    Comment: was deleted

(was: Hi [~julianhyde], I mean overload function.Thanks for your correction.

Here is the example :
{code:java}
@Function(name = "my_udf")
public class MyUdf {
  public static String eval(String arg0,String arg1) {...}
  public static String eval(long arg0, long arg1)    {...}
  public static String eval(int arg0, int arg1)      {...}
}{code}
_MyUdf_  is a user defined scalar function named "my_udf"  with multiple 
overload method. Currently the ModelHandler would register multiple 
ScalarFunctions to the schema for each method.

I would like to mapping one  SqlUserDefinedFunction to "my_udf" no mater how 
many overload functions it has just like the BuildIn operator.

To implement this, I will extend the Types#lookupMethod:
{code:java}
public static Method lookupMethod(Class clazz,String name, Class... inputTypes) 
{
  
// Find the best match method from the overload functions for the input types.
....
}{code}
In the  SqlReturnTypeInference for  SqlUserDefinedFunction, I can use the 
Types#lookupMethod to infer the return type :
{code:java}
SqlReturnTypeInference returnTypeInference =
opBinding -> {
   ......
   List<Class<?> paramTypes = convertToJavaTypes(
      opBinding.collectOperandTypes(), opBinding.getTypeFactory());
  Method method = Types.lookupMethod(udfClazz, "eval", paramTypes);
  return typeFactory.createType(method.getReturnType());
}{code}
The similar thing can apply to  SqlOperandTypeInference and 
SqlOperandTypeChecker.

So we can implement a dynamic type inference for the overload functions in 
scalar function. And there is only one SqlUserDefinedFunction mapping to the 
sql function.

We can also do the same thing for SqlUserDefinedTableFunction for the "my_udtf" 
as followed:
{code:java}
@Function(name = "my_udtf")
public class MyUdtf {
 public static ScannableTable eval(String arg0,String arg1) {...}
 public static ScannableTable eval(long arg0, long arg1) {...}
 public static ScannableTable eval(int arg0, int arg1) {...}
}
{code}
We mapping one SqlUserDefinedTableFunction to the "my_udtf" table function and 
support all the overload methods call.

 

 

 )

> Improve SqlUserDefinedFunction and SqlUserDefinedTableFunction to support 
> overload method call
> ----------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-3000
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3000
>             Project: Calcite
>          Issue Type: Improvement
>          Components: core
>            Reporter: pengzhiwei
>            Assignee: pengzhiwei
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
>  Here are  User-defined scalar function class and table function class:
>  
> {code:java}
> @UDFDescription(name = "MY_UDF", category = 
> SqlFunctionCategory.USER_DEFINED_FUNCTION)
> public static class MyUdfFunction {
>   public static String eval(String a) {
>     ...
>   }
>   public static String eval(String a, String b) {
>     ....
>   }
>   public static String eval(String a, int c) {
>     ....
>   }
> }
> {code}
> {code:java}
> @UDFDescription(name = "MY_UDTF", category = 
> SqlFunctionCategory.USER_DEFINED_TABLE_FUNCTION)
> public static class MyUdtfFunction {
>   public static MyScannableTable eval(String a) {
>     ...
>   }
>   public static MyScannableTable eval(long a) {
>     ...
>   }
>   public static MyScannableTable eval(int a) {
>     ...
>   }
> }
> {code}
> This issue wants to improve the SqlUserDefinedFunction and 
> SqlUserDefinedTableFunction to support  the overload functions in both 
> User-defined scalar function class and table function class.
>  
>  
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to