...
Modify DataTypeHint to support specifying whether the parameter is optional.
@PublicEvolving
...
Code Block | ||
---|---|---|
| ||
@PublicEvolving @Retention(RetentionPolicy.RUNTIME) |
...
@Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) |
...
/**
* Used to indicate whether the parameter is optional or not.
*/
...
public @interface DataTypeHint { // UDF Development public static class NamedArgumentsTableFunction extends TableFunction<Object> { // Method overloads with different parameter sets // Example usage: SELECT * FROM TABLE(my_table_function(in1 => 'value1', in2 => 'value2')) @FunctionHint( input = {@DataTypeHint("STRING"), @DataTypeHint("STRING")}, output = @DataTypeHint("STRING"), argumentNames = {"in1", "in2"}) public void eval(String arg1, String arg2) { collect(arg1 + ", " + arg2); } // Example usage: SELECT * FROM TABLE(my_table_function(in1 => 'value1', in2 => 'value2', in3 => 'value3')) @FunctionHint( input = {@DataTypeHint("STRING"), @DataTypeHint("STRING"), @DataTypeHint("STRING")}, output = @DataTypeHint("STRING"), argumentNames = {"in1", "in2", "in3"}) public void eval(String arg1, String arg2, String arg3) { collect(arg1 + ", " + arg2); } } // Call Procedure Development public static class NamedArgumentsProcedure implements Procedure { // Method overloads with different parameter sets // Example usage: CALL myNamedProcedure(in1 => 'value1', d => 100) @ProcedureHint( input = {@DataTypeHint("STRING"), @DataTypeHint("INT")}, output = @DataTypeHint("STRING"), argumentNames = {"in1", "in2"}) public String[] call(ProcedureContext procedureContext, String arg1, Integer arg2) { return new String[]{arg1 + ", " + arg2}; } // Example usage: CALL myNamedProcedure(in1 => 100, in2 => 200) @ProcedureHint( input = {@DataTypeHint("INT"), @DataTypeHint("INT")}, output = @DataTypeHint("STRING"), argumentNames = {"in1", "in2"}) public String[] call(ProcedureContext procedureContext, Integer arg1, Integer arg2) { return new String[]{arg1 + ", " + arg2}; } } /** * Used to indicate whether the parameter is optional or not. */ boolean isOptional() default true; } |
For function developer and call procedure developer
...
- Class overloads multiple methods with different parameters and types. Users need to specify all the parameters when using.
Code Block | ||
---|---|---|
| ||
// UDF Development |
...
public static class NamedArgumentsTableFunction |
...
extends TableFunction<Object> { // Method overloads with different parameter sets |
...
// Example usage: SELECT * FROM TABLE(my_table_function(in1 => 'value1', in2 => 'value2')) |
...
@FunctionHint(
...
@FunctionHint( input = {@DataTypeHint("STRING"), |
...
@DataTypeHint("STRING")}, |
...
output = |
...
@DataTypeHint("STRING"), |
...
argumentNames = {"in1", "in2"}) |
...
public void eval(String arg1, String arg2) |
...
{ collect(arg1 + ", " + arg2); |
...
} |
...
// Example usage: SELECT * FROM TABLE(my_table_function(in1 => 'value1', in2 => 'value2', in3 => 'value3')) |
...
@FunctionHint(
...
@FunctionHint( input = {@DataTypeHint("STRING"), |
...
@DataTypeHint("STRING"), |
...
@DataTypeHint("STRING")}, |
...
output = |
...
@DataTypeHint("STRING"), |
...
argumentNames = {"in1", "in2", "in3"}) |
...
public void eval(String arg1, String arg2, String arg3) |
...
{ collect(arg1 + ", " + arg2); |
...
} |
...
}
} // Call Procedure Development |
...
public static class NamedArgumentsProcedure implements Procedure { |
...
// Method overloads with different parameter sets |
...
// Example usage: CALL myNamedProcedure(in1 => 'value1', d => 100) |
...
@ProcedureHint(
...
@ProcedureHint( input = {@DataTypeHint("STRING"), |
...
@DataTypeHint("INT")}, |
...
output = |
...
@DataTypeHint("STRING"), |
...
argumentNames = {"in1", "in2"}) |
...
public String[] call(ProcedureContext procedureContext, String arg1, Integer arg2) |
...
{ return new String[]{arg1 + ", " + arg2}; |
...
} |
...
// Example usage: CALL myNamedProcedure(in1 => 100, in2 => 200) |
...
@ProcedureHint(
...
@ProcedureHint( input = {@DataTypeHint("INT"), |
...
@DataTypeHint("INT")}, |
...
output = |
...
@DataTypeHint("STRING"), |
...
argumentNames = {"in1", "in2"}) |
...
public String[] call(ProcedureContext procedureContext, Integer arg1, Integer arg2) |
...
{ return new String[]{arg1 + ", " + arg2}; |
...
} |
...
} |
- The class can only have one method, and users can optionally specify parameters.
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(
...
@FunctionHint( input = {@DataTypeHint("STRING"), |
...
@DataTypeHint(value = "STRING", isOptional = false), |
...
@DataTypeHint(value = "STRING", isOptional = true)}, |
...
output = |
...
@DataTypeHint("STRING"), |
...
argumentNames = {"in1", "in2", "in3"}) |
...
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(
...
@ProcedureHint( input = {@DataTypeHint(value = "STRING", isOptional = false), |
...
@DataTypeHint(value = "STRING", isOptional = false), |
...
@DataTypeHint(value = "STRING", isOptional = true)}, |
...
output = |
...
@DataTypeHint("STRING"), |
...
argumentNames = {"c", "d", "e"}) |
...
public String[] call(ProcedureContext procedureContext, String arg1, String arg2, String arg3) |
...
{ return new String[]{arg1 + ", " + arg2 + "," + arg3}; |
...
} |
...
} |
For users
Users can now use functions and call procedures with named parameters as follows:
Code Block | |
---|---|
|
...
| |
-- for scalar function |
...
SELECT my_scalar_function(param1 => ‘value1’, param2 => ‘value2’’) FROM [] |
...
-- for table |
...
function SELECT * FROM TABLE(my_table_function(param1 => 'value1', param2 => 'value2')) |
...
-- for agg function |
...
SELECT my_agg_function(param1 => 'value1', param2 => 'value2') FROM [] |
...
-- for call |
...
procedure CALL procedure_name(param1 => ‘value1’, param2 => ‘value2’) |
...
Proposed Changes
Implementing Named Parameters:
...