THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Page properties | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Table of Contents
Motivation
...
Code Block | ||
---|---|---|
| ||
public @interface ArgumentHint { /** * The name of the parameter, default is an empty string. */ String name() default ""; /** * Whether the parameter is optional, default is truefalse. */ boolean isOptional() default truefalse; /** * The data type hint for the parameter. */ DataTypeHint type() default @DataTypeHint(); } |
...
Code Block |
---|
public @interface FunctionHint { /** * Deprecated attribute for specifying the names of the arguments. * It is no longer recommended to use this attribute. */ @Deprecated String[] argumentNames() default {""}; /** * Attribute for specifying the hints and additional information for function arguments. */ ArgumentHint[] arguments() default {}; } |
Code Block |
---|
public @interface ProcedureHint { /** * Deprecated attribute for specifying the names of the arguments. * It is no longer recommended to use this attribute. */ @Deprecated String[] argumentNames() default {""}; /** * Attribute for specifying the hints and additional information for procedure arguments. */ ArgumentHint[] arguments() default {}; } |
...
Code Block | ||
---|---|---|
| ||
// UDF Development public static class NamedArgumentsTableFunction extends TableFunction<Object> { // Example usage: SELECT * FROM TABLE(my_table_function(in1 => 'value1', in2 => 'value2')) // Example usage: SELECT * FROM TABLE(my_table_function(in1 => 'value1', in2 => 'value2', in3 => 'value3')) @FunctionHint( input = {@DataTypeHint("STRING"), @DataTypeHint(value = "STRING"), @DataTypeHint(value = "STRING")}, output = @DataTypeHint("STRING"), arguments = { @ArgumentHint(name = "in1", isOptional = true, type = @DataTypeHint("STRING")), @ArgumentHint(name = "in2", isOptional = true, type = @DataTypeHint("STRING")) @ArgumentHint(name = "in3", isOptional = true, type = @DataTypeHint("STRING"))}) public void eval(String arg1, String arg2, String arg3) { collect(arg1 + ", " + arg2 + "," + arg3); } } // Call Procedure Development public static class NamedArgumentsProcedure implements Procedure { // Example usage: CALL myNamedProcedure(in1 => 'value1', in2 => 'value2') // Example usage: CALL myNamedProcedure(in1 => 'value1', in2 => 'value2', in3 => 'value3') @ProcedureHint( input = {@DataTypeHint(value = "STRING"), @DataTypeHint(value = "STRING"), @DataTypeHint(value = "STRING")}, output = @DataTypeHint("STRING"), arguments = { @ArgumentHint(name = "in1", isOptional = false, type = @DataTypeHint("STRING")), @ArgumentHint(name = "in2", isOptional = true, type = @DataTypeHint("STRING")) @ArgumentHint(name = "in3", isOptional = true, type = @DataTypeHint("STRING"))}) public String[] call(ProcedureContext procedureContext, String arg1, String arg2, String arg3) { return new String[]{arg1 + ", " + arg2 + "," + arg3}; } } |
...
To validate this feature, we can develop custom UDFs or call procedures and use named parameters when invoking them.
Rejected Alternatives
None
1 . https://issues.apache.org/jira/browse/CALCITE-947
2. poc: https://github.com/apache/flink/compare/master...hackergin:flink:poc_named_argument