THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
Code Block | ||
---|---|---|
| ||
public @interface ArgumentHint { String name() default ""; boolean isOptional() default true; } |
...
Function developing and call procedure
...
developing
For UDF development or call developers, the UDX or procedure we develop can be roughly divided into two types:
1 . 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( 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}; } } |
2 .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( 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( 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}; } } |
...