You can write user-defined functions (UDFs) to MaxCompute SQL.

Basic operations

Use list_functions as the ODPS object to obtain all functions in the project. Use exist_function to check whether the specified function exists. Use get_function to obtain the object of a function.

Create functions

>>> # reference resources in the current project
>>> resource = o.get_resource('')
>>> function = o.create_function('test_function', class_type='my_udf.Test', resources=[resource])
>>> # reference resources in other projects
>>> resource2 = o.get_resource('', project='another_project')
>>> function2 = o.create_function('test_function2', class_type='my_udf.Test', resources=[resource2])

Delete functions

>>> o.delete_function('test_function')
>>> function.drop()  # call drop method of a Function instance to delete

Update functions

To update functions, use the update method.

>>> function = o.get_function('test_function')
>>> new_resource = o.get_resource('')
>>> function.class_type = 'my_udf2.Test'
>>> function.resources = [new_resource, ]
>>> function.update()  # update metadata on the function object