ユーザー定義関数 (UDF) を作成し、MaxCompute SQLで使用できます。
基本操作
list_functions()
: 特定のプロジェクト内のすべての関数を取得します。exist_function()
: 特定の関数が存在するかどうかを確認します。get_function()
: 特定の関数を取得します。create_function()
: 関数を作成します。delete_function()
: 特定の関数を削除します。
関数を作成
MaxComputeエントリオブジェクトのcreate_function()
メソッドを呼び出して、関数を作成できます。 次のコードは、現在のプロジェクトと別のプロジェクトでリソースを使用して関数を作成する方法の例を示しています。
# Reference a resource in the current project.
resource = o.get_resource('my_udf.py')
function = o.create_function('test_function', class_type='my_udf.Test', resources=[resource])
# Reference a resource in another project.
resource2 = o.get_resource('my_udf.py', project='another_project')
function2 = o.create_function('test_function2', class_type='my_udf.Test', resources=[resource2])
関数を削除する
MaxComputeエントリオブジェクトのdelete_function()
メソッドを呼び出して、関数を削除できます。 drop()
メソッドを呼び出して関数を削除することもできます。 次のコードは、delete_function() およびdrop() メソッドを使用して関数を削除する方法の例を示しています。
o.delete_function('test_function')
function.drop() # Call the drop() method if the function exists.
関数の更新
update()
メソッドを呼び出して、関数を更新できます。 次のコードは例を示しています。
function = o.get_function('test_function')
new_resource = o.get_resource('my_udf2.py')
function.class_type = 'my_udf2.Test'
function.resources = [new_resource, ]
function.update() # Update the function.