Todos los productos
Search
Centro de documentos

MaxCompute:Function operations

Última actualización: Sep 03, 2026

MaxCompute admite dos tipos de funciones: las funciones integradas y las funciones definidas por el usuario (UDF). Las funciones integradas están disponibles de inmediato y no requieren configuración. Las UDF deben registrarse antes de poder invocarse en sentencias SQL.

Este tema aborda las operaciones comunes de gestión de UDF: creación, eliminación y consulta de funciones.

Resumen de operaciones

Operación

Permiso obligatorio

Plataformas

Crear una UDF

Permiso de escritura sobre funciones

Cliente de MaxCompute, consola de DataWorks, MaxCompute Studio

Eliminar una UDF

Permiso de eliminación sobre funciones

—

View a UDF

Permiso de lectura sobre funciones

—

Listar todas las UDF

Permiso de listado sobre objetos del proyecto

—

List all built-in functions

Permiso de listado sobre objetos del proyecto

—

Requisitos previos

Antes de empezar, asegúrese de contar con lo siguiente:

  • Un recurso JAR o Python que contenga el código de la UDF, cargado en MaxCompute

  • Los permisos obligatorios para la operación (consulte la tabla anterior)

Crear una UDF

Registra una UDF en un proyecto de MaxCompute para que pueda invocarse en sentencias SQL.

Limitaciones

  • Los nombres de las funciones deben ser únicos dentro de un proyecto. No se permite crear una función con el mismo nombre que una ya existente.

  • Las UDF no pueden sobrescribir funciones integradas. Solo el propietario del proyecto puede registrar una UDF que comparta nombre con una función integrada. Si se invoca una UDF de este tipo, aparecerá una advertencia en el resumen de Logview después de que se ejecute el trabajo SQL.

Sintaxis

create function <function_name> as '<package_to_class>' using '<resource_list>';

Parámetros

Parámetro

Obligatorio

Descripción

function_name

Sí

Nombre de la UDF que se va a crear. Debe ser único en el proyecto.

package_to_class

Sí

Ruta de clase completa de la UDF. Distingue entre mayúsculas y minúsculas. Debe ir entre comillas simples ('). Para una UDF de Java, especifique la ruta completa desde el nombre del paquete de nivel superior hasta el nombre de la clase de la UDF. Para una UDF de Python, utilice el formato script_name.ClassName.

resource_list

Sí

Lista de nombres de recursos separados por comas, entre comillas simples ('). Debe incluir el recurso que contiene el código de la UDF. Si la UDF llama a la API de Distributed Cache para leer archivos de recursos, incluya también dichos archivos. Para hacer referencia a un recurso de otro proyecto, utilice el formato <project_name>/resources/<resource_name>.

Nota

Los nombres de los recursos de Python no distinguen entre mayúsculas y minúsculas en el nivel subyacente. El nombre subyacente del recurso se determina por el nombre utilizado durante la primera carga. Por ejemplo, si primero carga pyudf_test.py y luego le cambia el nombre a PYUDF_TEST.py, el nombre subyacente del recurso seguirá siendo pyudf_test.py. Al registrar la UDF, el nombre de la clase debe coincidir con el nombre subyacente: pyudf_test.SampleUDF. Ejecute list resources; para comprobar los nombres subyacentes de todos los recursos.

Ejemplos

Ejemplo 1: UDF de Java

Cree la función my_lower mediante la clase de Java org.alidata.odps.udf.examples.Lower en my_lower.jar.

create function my_lower as 'org.alidata.odps.udf.examples.Lower' using 'my_lower.jar';

Ejemplo 2: UDF de Python de otro proyecto

Cree la función my_lower mediante la clase de Python MyLower en el script pyudf_test.py, que es un recurso en test_project.

create function my_lower as 'pyudf_test.MyLower' using 'test_project/resources/pyudf_test.py';

Ejemplo 3: Función con valor de tabla definida por el usuario (UDTF) de Java con varios recursos

Cree test_udtf mediante la clase com.aliyun.odps.examples.udf.UDTFResource en udtfexample1.jar. La función también depende de un recurso de archivo, un recurso de tabla y un recurso de archivo comprimido.

create function test_udtf as 'com.aliyun.odps.examples.udf.UDTFResource' using 'udtfexample1.jar, file_resource.txt, table_resource1, test_archive.zip';

Eliminar una UDF

Quita una UDF existente de un proyecto de MaxCompute.

Sintaxis

drop function <function_name>;

Parámetros

Parámetro

Obligatorio

Descripción

function_name

Sí

Nombre de la UDF que se va a eliminar.

Ejemplo

-- Delete the my_lower function.
drop function my_lower;

Consultar una UDF

Devuelve los metadatos de una UDF específica: su nombre, propietario, hora de creación, clase y lista de recursos.

Sintaxis

desc function <function_name>;

Parámetros

Parámetro

Obligatorio

Descripción

function_name

Sí

Nombre de la UDF que se va a inspeccionar.

Campos de salida

Campo

Descripción

Name

Nombre de la UDF.

Owner

Cuenta que registró la UDF.

Created Time

Hora en que se creó la UDF.

Class

Ruta de la clase de la UDF. Distingue entre mayúsculas y minúsculas.

Resources

Lista de recursos asociados a la UDF.

Ejemplo

-- View details of the my_lower function.
desc function my_lower;

Salida:

Name                                    my_lower
Owner                                   ALIYUN$****
Created Time                            2020-06-18 15:50:19
Class                                   org.alidata.odps.udf.examples.Lower
Resources                               project_name/my_lower.jar

Listar todas las UDF

Devuelve todas las UDF registradas en un proyecto de MaxCompute.

Sintaxis

Utilice cualquiera de los siguientes comandos:

list functions [-p <project_name>];
show functions;

Parámetros

Parámetro

Obligatorio

Descripción

project_name

No

Nombre del proyecto de MaxCompute que se va a consultar. Si se omite, se utiliza el proyecto actual. Solo es compatible con list functions.

Ejemplo

list functions;

Salida:

Name              Owner                                        Create Time           Class                             Resources
ipv4_ipv6_aton    ALIYUN$****@aliyun.com 2021-11-15 13:42:14   com.aliyun.odps.udf.udfFunction.IpLocation ipv4.txt,ipv6.txt,udf-1.0-SNAPSHOT.jar
Lower_test        ALIYUN$****@aliyun.com 2021-08-25 15:51:22   com.aliyun.odps.udf.example.Lower udf-1.0-SNAPSHOT.jar
my_add            ALIYUN$****@aliyun.com 2021-05-08 11:26:02
my_index          ALIYUN$****@aliyun.com 2021-08-25 12:01:05   com.aliyun.odps.examples.udf.UdfArray udf-1.0-SNAPSHOT.jar
my_sum            ALIYUN$****@aliyun.com 2021-05-08 10:24:58
my_udtf           ALIYUN$****@aliyun.com 2021-02-23 11:37:30   com.aliyun.odps.examples.udf.UDTFResource udf-1.0-SNAPSHOT.jar
numpy             ALIYUN$****@aliyun.com 2020-11-11 14:12:50   numpy.TryImport                   numpy.py,numpy-1.19.4-cp37-cp37m-manylinux1_x86_64.zip
ST_Aggr_ConvexHull ALIYUN$****@aliyun.com 2021-03-18 17:06:29   com.esri.hadoop.hive.ST_Aggr_ConvexHull esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Aggr_Intersection ALIYUN$****@aliyun.com 2021-03-18 17:06:29   com.esri.hadoop.hive.ST_Aggr_Intersection esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Aggr_Union     ALIYUN$****@aliyun.com 2021-03-18 17:06:30   com.esri.hadoop.hive.ST_Aggr_Union esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Area           ALIYUN$****@aliyun.com 2021-03-18 17:06:30   com.esri.hadoop.hive.ST_Area      esri-geometry-api.jar,spatial-sdk-hive.jar
ST_AsBinary       ALIYUN$****@aliyun.com 2021-03-18 17:06:30   com.esri.hadoop.hive.ST_AsBinary  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_AsGeoJson      ALIYUN$****@aliyun.com 2021-03-18 17:06:49   com.esri.hadoop.hive.ST_AsGeoJson esri-geometry-api.jar,spatial-sdk-hive.jar
ST_AsJson         ALIYUN$****@aliyun.com 2021-03-18 17:06:50   com.esri.hadoop.hive.ST_AsJson    esri-geometry-api.jar,spatial-sdk-hive.jar
ST_AsShape        ALIYUN$****@aliyun.com 2021-03-18 17:06:50   com.esri.hadoop.hive.ST_AsShape   esri-geometry-api.jar,spatial-sdk-hive.jar
ST_AsText         ALIYUN$****@aliyun.com 2021-03-18 17:06:50   com.esri.hadoop.hive.ST_AsText    esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Bin            ALIYUN$****@aliyun.com 2021-03-18 17:06:50   com.esri.hadoop.hive.ST_Bin       esri-geometry-api.jar,spatial-sdk-hive.jar
ST_BinEnvelope    ALIYUN$****@aliyun.com 2021-03-18 17:07:01   com.esri.hadoop.hive.ST_BinEnvelope esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Boundary       ALIYUN$****@aliyun.com 2021-03-18 17:07:01   com.esri.hadoop.hive.ST_Boundary  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Buffer         ALIYUN$****@aliyun.com 2021-03-18 17:07:01   com.esri.hadoop.hive.ST_Buffer    esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Centroid       ALIYUN$****@aliyun.com 2021-03-18 17:07:01   com.esri.hadoop.hive.ST_Centroid  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Contains       ALIYUN$****@aliyun.com 2021-03-18 17:07:01   com.esri.hadoop.hive.ST_Contains  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_ConvexHull     ALIYUN$****@aliyun.com 2021-03-18 17:07:13   com.esri.hadoop.hive.ST_ConvexHull esri-geometry-api.jar,spatial-sdk-hive.jar
ST_CoordDim       ALIYUN$****@aliyun.com 2021-03-18 17:07:14   com.esri.hadoop.hive.ST_CoordDim  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Crosses        ALIYUN$****@aliyun.com 2021-03-18 17:07:14   com.esri.hadoop.hive.ST_Crosses   esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Difference     ALIYUN$****@aliyun.com 2021-03-18 17:07:14   com.esri.hadoop.hive.ST_Difference esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Dimension      ALIYUN$****@aliyun.com 2021-03-18 17:07:14   com.esri.hadoop.hive.ST_Dimension esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Disjoint       ALIYUN$****@aliyun.com 2021-03-18 17:07:31   com.esri.hadoop.hive.ST_Disjoint  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Distance       ALIYUN$****@aliyun.com 2021-03-18 17:07:31   com.esri.hadoop.hive.ST_Distance  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_EndPoint       ALIYUN$****@aliyun.com 2021-03-18 17:07:31   com.esri.hadoop.hive.ST_EndPoint  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Envelope       ALIYUN$****@aliyun.com 2021-03-18 17:07:32   com.esri.hadoop.hive.ST_Envelope  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_EnvIntersects  ALIYUN$****@aliyun.com 2021-03-18 17:07:32   com.esri.hadoop.hive.ST_EnvIntersects esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Equals         ALIYUN$****@aliyun.com 2021-03-18 17:07:44   com.esri.hadoop.hive.ST_Equals    esri-geometry-api.jar,spatial-sdk-hive.jar
ST_ExteriorRing   ALIYUN$****@aliyun.com 2021-03-18 17:07:44   com.esri.hadoop.hive.ST_ExteriorRing esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeodesicLengthWGS84 ALIYUN$****@aliyun.com 2021-03-18 17:07:44   com.esri.hadoop.hive.ST_GeodesicLengthWGS84 esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeomCollection ALIYUN$****@aliyun.com 2021-03-18 17:07:44   com.esri.hadoop.hive.ST_GeomCollection esri-geometry-api.jar,spatial-sdk-hive.jar
ST_Geometry       ALIYUN$****@aliyun.com 2021-03-18 17:07:44   com.esri.hadoop.hive.ST_Geometry  esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeometryN      ALIYUN$****@aliyun.com 2021-03-18 17:07:55   com.esri.hadoop.hive.ST_GeometryN esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeometryType   ALIYUN$****@aliyun.com 2021-03-18 17:07:55   com.esri.hadoop.hive.ST_GeometryType esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeomFromGeoJson ALIYUN$****@aliyun.com 2021-03-18 17:07:55   com.esri.hadoop.hive.ST_GeomFromGeoJson esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeomFromJson   ALIYUN$****@aliyun.com 2021-03-18 17:07:55   com.esri.hadoop.hive.ST_GeomFromJson esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeomFromShape  ALIYUN$****@aliyun.com 2021-03-18 17:07:56   com.esri.hadoop.hive.ST_GeomFromShape esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeomFromText   ALIYUN$****@aliyun.com 2021-03-18 17:08:10   com.esri.hadoop.hive.ST_GeomFromText esri-geometry-api.jar,spatial-sdk-hive.jar
ST_GeomFromWKB    ALIYUN$****@aliyun.com 2021-03-18 17:08:10   com.esri.hadoop.hive.ST_GeomFromWKB esri-geometry-api.jar,spatial-sdk-hive.jar

Las columnas de la salida son:

Columna

Descripción

Name

Nombre de la UDF.

Owner

Cuenta que registró la UDF.

Create Time

Hora en que se creó la UDF.

Class

Ruta de la clase de la UDF. Vacío si la información de la clase no está disponible.

Resources

Recursos asociados a la UDF. Vacío si no hay recursos registrados.

Listar todas las funciones integradas

Devuelve información sobre las funciones integradas disponibles en MaxCompute, incluidas las firmas de función y los tipos de datos compatibles.

Nota

Este comando requiere el cliente de MaxCompute V0.43.0 o posterior.

Sintaxis

show builtin functions [<function_name>];

Parámetros

Parámetro

Obligatorio

Descripción

function_name

No

Nombre de una función integrada específica que se desea buscar. Si se omite, se devuelven todas las funciones integradas.

Ejemplo

show builtin functions;

Salida (parcial):

ID = 20230307081023424gef2hwowr1
::ABS   SCALAR  DECIMAL(?,?) ABS(DECIMAL(?,?) arg0),DOUBLE ABS(DOUBLE arg0),BIGINT ABS(BIGINT arg0),INT ABS(INT arg0)
::ACOS  SCALAR  DOUBLE ACOS(DOUBLE arg0),DOUBLE ACOS(DECIMAL(?,?) arg0)
::ADD_MONTHS    SCALAR  STRING ADD_MONTHS(DATE arg0, BIGINT arg1),STRING ADD_MONTHS(TIMESTAMP arg0, BIGINT arg1),STRING ADD_MONTHS(STRING arg0, BIGINT arg1)
::ALL_MATCH     SCALAR  BOOLEAN ALL_MATCH(ARRAY<T> arg0, java.util.function.Function<T, java.lang.Boolean> arg1)
::ANY_MATCH     SCALAR  BOOLEAN ANY_MATCH(ARRAY<T> arg0, java.util.function.Function<T, java.lang.Boolean> arg1)
::ANY_VALUE     AGGREGATOR      T ANY_VALUE([DISTINCT] T arg1)
::APPROX_DISTINCT       AGGREGATOR      BIGINT APPROX_DISTINCT([DISTINCT] P arg1, DOUBLE arg2),BIGINT APPROX_DISTINCT([DISTINCT] P arg1)
::ARG_MAX       AGGREGATOR      R ARG_MAX([DISTINCT] T arg1, R arg2)
::ARG_MIN       AGGREGATOR      R ARG_MIN([DISTINCT] T arg1, R arg2)
::ARRAY SCALAR  ARRAY<STRING> ARRAY(),ARRAY<T> ARRAY(T arg0...)
::ARRAYS_OVERLAP        SCALAR  BOOLEAN ARRAYS_OVERLAP(ARRAY<T> arg0, ARRAY<T> arg1)
::ARRAYS_ZIP    SCALAR  null
::ARRAY_CONTAINS        SCALAR  BOOLEAN ARRAY_CONTAINS(ARRAY<T> arg0, T arg1)
::ARRAY_DISTINCT        SCALAR  ARRAY<T> ARRAY_DISTINCT(ARRAY<T> arg0)
::ARRAY_EXCEPT  SCALAR  ARRAY<T> ARRAY_EXCEPT(ARRAY<T> arg0, ARRAY<T> arg1)
::ARRAY_INTERSECT       SCALAR  null
::ARRAY_JOIN    SCALAR  STRING ARRAY_JOIN(ARRAY<STRING> arg0, STRING arg1, STRING arg2),STRING ARRAY_JOIN(ARRAY<STRING> arg0, STRING arg1)
::ARRAY_MAX     SCALAR  T ARRAY_MAX(ARRAY<T> arg0)
::ARRAY_MIN     SCALAR  T ARRAY_MIN(ARRAY<T> arg0)
::ARRAY_NORMALIZE       SCALAR  ARRAY<FLOAT> ARRAY_NORMALIZE(ARRAY<FLOAT> arg0, FLOAT arg1),ARRAY<DOUBLE> ARRAY_NORMALIZE(ARRAY<DOUBLE> arg0, DOUBLE arg1)
::ARRAY_POSITION        SCALAR  BIGINT ARRAY_POSITION(ARRAY<T> arg0, T arg1, BIGINT arg2),BIGINT ARRAY_POSITION(ARRAY<T> arg0, T arg1)
::ARRAY_REDUCE  SCALAR  OUT ARRAY_REDUCE(ARRAY<IN> arg0, BUF arg1, java.util.function.BiFunction<BUF, IN, BUF> arg2, java.util.function.Function<BUF, OUT> arg3)
::ARRAY_REMOVE  SCALAR  ARRAY<T> ARRAY_REMOVE(ARRAY<T> arg0, T arg1)
::ARRAY_REPEAT  SCALAR  ARRAY<T> ARRAY_REPEAT(T arg0, BIGINT arg1)
::ARRAY_SORT    SCALAR  ARRAY<T> ARRAY_SORT(ARRAY<T> arg0, java.util.function.BiFunction<T, T, java.lang.Long> arg1)
::ARRAY_UNION   SCALAR  ARRAY<T> ARRAY_UNION(ARRAY<T> arg0, ARRAY<T> arg1)
::ASCII SCALAR  BIGINT ASCII(STRING arg0)
::ASIN  SCALAR  DOUBLE ASIN(DOUBLE arg0),DOUBLE ASIN(DECIMAL(?,?) arg0)
::ATAN  SCALAR  DOUBLE ATAN(DECIMAL(?,?) arg0),DOUBLE ATAN(DOUBLE arg0)
::ATAN2 SCALAR  DOUBLE ATAN2(DECIMAL(?,?) arg0, DECIMAL(?,?) arg1),DOUBLE ATAN2(DOUBLE arg0, DOUBLE arg1)
::AVG   AGGREGATOR      DECIMAL(?,?) AVG([DISTINCT] DECIMAL(?,?) arg1),DOUBLE AVG([DISTINCT] DOUBLE arg1)
::AVG   WINDOW  DOUBLE AVG([DISTINCT] DOUBLE arg0),DECIMAL(?,?) AVG([DISTINCT] DECIMAL(?,?) arg0)
::BASE64        SCALAR  STRING BASE64(BINARY arg0)
::BIN   SCALAR  STRING BIN(BIGINT arg0)
::BITAND        SCALAR  BIGINT BITAND(BIGINT arg0, BIGINT arg1)
::BITNOT        SCALAR  BIGINT BITNOT(BIGINT arg0)
::BITOR SCALAR  BIGINT BITOR(BIGINT arg0, BIGINT arg1)
::BITWISE_AND_AGG       AGGREGATOR      BIGINT BITWISE_AND_AGG([DISTINCT] BIGINT arg1)
::BITWISE_OR_AGG        AGGREGATOR      BIGINT BITWISE_OR_AGG([DISTINCT] BIGINT arg1)
::BITXOR        SCALAR  BIGINT BITXOR(BIGINT arg0, BIGINT arg1)
::BROUND        SCALAR  DOUBLE BROUND(DOUBLE arg0, BIGINT arg1),DOUBLE BROUND(DOUBLE arg0)
......

Cada línea de la salida sigue el formato: function_name function_type signature(s). El tipo de función es uno de los siguientes: SCALAR, AGGREGATOR o WINDOW.