Function

Last Updated: Dec 08, 2017

Command Format:

  1. CREATE FUNCTION <function_name> AS <package_to_class> USING <resource_list>;

Description:

  • 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 incuded in the list. If the user’s code reads the resource file by ‘distributed cache’ interface, this list will 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.

Example:Suppose that the Java UDF class org.alidata.odps.udf.examples.Lower is in my_lower.jar. Create the UDF ‘test_lower’:

  1. CREATE FUNCTION test_lower AS 'org.alidata.odps.udf.examples.Lower'
  2. USING 'my_lower.jar';
  3. Suppose that Python UDF MyLower is in the script pyudf_test.py’, create the function my_lower’:
  4. create function my_lower as 'pyudf_test.MyLower'
  5. using 'pyudf_test.py';

Notes:

  • 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 will be printed in Summary after SQL execution.

Drop Function

Command Format:

  1. DROP FUNCTION <function_name>;

Example:

  1. DROP FUNCTION test_lower;

List Functions

Command Examples:

  1. list functions; --View all user-defined functions in current project
  2. list functions -p my_project; --View all user-defined functions in the project 'my_project'.
Thank you! We've received your feedback.