...
Currently, when users invoke a function or call a procedure, they must specify all fields in order. When there are a large number of parameters, it is easy to make mistakes and cannot omit specifying non-mandatory fields. By using named parameters, you can selectively specify the required parameters, reducing the probability of errors and making it more convenient to use.
Public Interfaces
Interface change
Introduce a new annotation to specify the parameter name, indicate if it is optional, and potentially support specifying default values in the future.Deprecate the ArgumentNames annotation as it is not user-friendly for specifying argument names with optional configuration.
Code Block | ||
---|---|---|
| ||
public @interface ArgumentHint { String name() default ""; boolean isOptional() default true; } |
Develop UDX or call procedures that support named parameters
For UDF development or call developers, the UDX or procedure we develop can be roughly divided into two types:
...
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), @ArgumentHint(name = "in2", isOptional = true) @ArgumentHint(name = "in3", isOptional = true)}) 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), @ArgumentHint(name = "in2", isOptional = true) @ArgumentHint(name = "in3", isOptional = true)}) public String[] call(ProcedureContext procedureContext, String arg1, String arg2, String arg3) { return new String[]{arg1 + ", " + arg2 + "," + arg3}; } } |
Use named parameters when using function and call procedure.
Users can use functions and call procedures with named parameters as follows:
...