This article explains how to use common commands to operate functions in the MaxCompute client.
You can also operate functions using the visualized online data development tools in DataWorks.
Create a Function
CREATE FUNCTION <function_name> AS <package_to_class> USING <resource_list>;
- function_name: An UDF 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). This parameter must be in double quotation marks. And, for Python UDF, this name is a python script name. classname. For both Java UDF and python script, use double quotation (““) marks to indicate this parameter. And for the name, use quotation marks.
- resource_list: Provides resource list used by UDF.
- Resources that contain UDF code must be included in the list.
- If the code reads the resource file by the distributed cache interface, this list also contains the list of resource files read by the UDF.
- The resource list is composed of multiple resource names, separated by a comma (,). The resource list must be in double quotation (“”) marks.
- Specify the project in which the resource is located as follows:
- Suppose a Java UDF class org.alidata.odps.udf.examples.Lower is in my_lower.jar, create
function my_lower as follows:
CREATE FUNCTION my_lower AS 'org.alidata.odps.udf.examples.Lower' USING 'my_lower.jar';
- Suppose a Python UDF MyLower is used in project pyudf_test.py,create function my_lower
create function my_lower as 'pyudf_test.MyLower' using 'test_project/resources/pyudf_test.py';
- Suppose a Java UDF class com.aliyun.odps.examples.udf.UDTFResource is in udtfexample1.jar,
and it depends on file resource file_resource.txt and table resource table_resource1,create
function test_udtf as follows:
create function test_udtf as 'com.aliyun.odps.examples.udf.UDTFResource' using 'udtfexample1.jar, file_resource.txt, table_resource1,test_archive.zip';
- Similar to the resource files, the UDF duplicate name can be registered only once.
- Generally UDF cannot overwrite system built-in functions. Only the project owner has right to overwrite the built-in functions. If you are using a UDF which overwrites the built-in function, the warning is triggered in Summary after SQL execution.
Drop a Function
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'.