LinuxCommandLibrary

odpscmd-func

Manage ODPS user-defined functions

TLDR

[Interactive] Show functions in the current project

$ list functions;
copy

[Interactive] Create a Java function using a .jar resource
$ create function [func_name] as [path.to.package.Func] using '[package.jar]';
copy

[Interactive] Create a Python function using a .py resource
$ create function [func_name] as [script.Func] using '[script.py]';
copy

[Interactive] Delete a function
$ drop function [func_name];
copy

SYNOPSIS

odpscmd-func [-h|--help] [--name func_name] [--type udf|udaf|udtf] [--inputs input_data] [--resource path] [--lang java|python] [--output]

PARAMETERS

-h, --help
    Display help and exit

--name <name>
    Name of the function to test

--type <type>
    Function type: udf, udaf, or udtf

--inputs <data>
    Input parameters as JSON array or delimited string

--input-row-type <type>
    Schema for input rows (e.g., string:int)

--resource <path>
    Local path to JAR, Python file, or resource

--lang <lang>
    Runtime language: java, python2, python3

--output-row-type <type>
    Expected output schema for UDTFs

--classpath <dirs>
    Additional Java classpath directories

DESCRIPTION

odpscmd-func is a specialized command in Alibaba Cloud's MaxCompute (formerly ODPS) CLI toolkit, designed for testing user-defined functions (UDFs), aggregate functions (UDAFs), and table functions (UDTFs). It enables developers to execute and debug custom functions locally or in a simulated cloud environment before full deployment.

Key features include specifying function names, input data in JSON or delimited formats, resource files (JARs for Java, .py for Python), runtime types, and output handling. This accelerates development by providing immediate feedback on function logic, error handling, and performance without submitting SQL jobs to the cluster.

Configuration requires a valid MaxCompute project, access credentials (AccessKey), and endpoint setup in ~/.odpsconf. Supports Java, Python 2/3, and other runtimes. Ideal for iterative UDF refinement in big data pipelines.

Limited to non-complex dependencies; full cluster testing recommended for production validation.

CAVEATS

Requires configured MaxCompute client; local execution doesn't replicate full cluster resources or parallelism. Python support limited to basic environments. Errors in resource loading common without proper paths.

PREREQUISITES

Install MaxCompute client via odpscmd --install; set endpoint, accesskey.id, accesskey.secret in config.

EXAMPLE USAGE

odpscmd-func --name my_udf --type udf --inputs '["hello"]' --resource ./myudf.jar --lang java
Outputs function result to stdout.

HISTORY

Developed by Alibaba for ODPS (2009), evolved with MaxCompute rebranding (2017+). Enhanced UDF testing in v2.0+ for Python3 and better error reporting.

SEE ALSO

odpscmd(1), mc(1), sql(1)

Copied to clipboard