CREATE FUNCTION <function_name> AS <package_to_class> USING <resource_list>;
function_name: UDF name, which is the name referenced in SQL.
package_to_class: for java UDF, this name is a fully qualified class name (from top level package name to UDF class name). For python UDF, this name is python script name.class name. This parameter must be in quotes.
resource_list: resources list used by UDF. The resource which contains UDF code must be included in the list. If the user’s code reads the resource file by ‘distributed cache’ interface, this list also contain the resource file list UDF reads. The resource list is composed of multiple resource names, separated by comma (,). The resource list must be in quotes.
Suppose that the Java UDF class org.alidata.odps.udf.examples.Lower is in my_lower.jar. Create the UDF ‘test_lower’:
CREATE FUNCTION test_lower AS 'org.alidata.odps.udf.examples.Lower'
Suppose that Python UDF MyLower is in the script ‘pyudf_test.py’, create the function ‘my_lower’:
create function my_lower as 'pyudf_test.MyLower'
Like the resource file, the same name UDF can only be registered once.
Generally UDF cannot overwrite system built-in functions. Only the project owner has right to overwrite the built-in functions. If you use a UDF which overwrites the built-in function, the warning information can be printed in Summary after SQL execution.
DROP FUNCTION <function_name>;
DROP FUNCTION test_lower;
list functions; --View all user-defined functions in current project
list functions -p my_project; --View all user-defined functions in the project 'my_project'.