Share via


functions command group

Note

This information applies to Databricks CLI versions 0.205 and above. The Databricks CLI is in Public Preview.

Databricks CLI use is subject to the Databricks License and Databricks Privacy Notice, including any Usage Data provisions.

The functions command group within the Databricks CLI allows you to manage user-defined functions (UDFs) in Unity Catalog. The function implementation can be any SQL expression or query, and it can be invoked wherever a table reference is allowed in a query. In Unity Catalog, a function resides at the same level as a table, so it can be referenced with the form catalog_name.schema_name.function_name.

databricks functions create

Create a new function.

Important

This is an experimental feature.

The user must have the following permissions in order for the function to be created:

-USE_CATALOG on the function's parent catalog

  • USE_SCHEMA and CREATE_FUNCTION on the function's parent schema
databricks functions create [flags]

Options

--json JSON

    The inline JSON string or the @path to the JSON file with the request body.

Global flags

Examples

The following example creates a function using a JSON file:

databricks functions create --json @function-definition.json

The following example creates a function using inline JSON:

databricks functions create --json '{"name": "my_catalog.my_schema.my_function", "data_type": "INT", "full_data_type": "INT", "return_params": {"parameters": []}, "routine_body": "SQL", "routine_definition": "SELECT 1", "routine_dependencies": {"dependencies": []}, "parameter_style": "S", "is_deterministic": true, "sql_data_access": "CONTAINS_SQL", "is_null_call": false, "security_type": "DEFINER", "specific_name": "my_function"}'

databricks functions delete

Delete the function that matches the supplied name.

For the deletion to succeed, the user must satisfy one of the following conditions:

  • Is the owner of the function's parent catalog
  • Is the owner of the function's parent schema and have the USE_CATALOG privilege on its parent catalog
  • Is the owner of the function itself and have both the USE_CATALOG privilege on its parent catalog and the USE_SCHEMA privilege on its parent schema
databricks functions delete NAME [flags]

Arguments

NAME

    The fully-qualified name of the function (of the form catalog_name.schema_name.function_name).

Options

--force

    Force deletion even if the function is notempty.

Global flags

Examples

The following example deletes a function:

databricks functions delete my_catalog.my_schema.my_function

The following example forces deletion of a function:

databricks functions delete my_catalog.my_schema.my_function --force

databricks functions get

Get a function from within a parent catalog and schema.

For the fetch to succeed, the user must satisfy one of the following requirements:

  • Is a metastore admin
  • Is an owner of the function's parent catalog
  • Have the USE_CATALOG privilege on the function's parent catalog and be the owner of the function
  • Have the USE_CATALOG privilege on the function's parent catalog, the USE_SCHEMA privilege on the function's parent schema, and the EXECUTE privilege on the function itself
databricks functions get NAME [flags]

Arguments

NAME

    The fully-qualified name of the function (of the form catalog_name.schema_name.function_name).

Options

--include-browse

    Whether to include functions in the response for which the principal can only access selective metadata for.

Global flags

Examples

The following example gets information about a function:

databricks functions get my_catalog.my_schema.my_function

The following example gets a function with browse information included:

databricks functions get my_catalog.my_schema.my_function --include-browse

databricks functions list

List functions within the specified parent catalog and schema.

If the user is a metastore admin, all functions are returned in the output list. Otherwise, the user must have the USE_CATALOG privilege on the catalog and the USE_SCHEMA privilege on the schema, and the output list contains only functions for which either the user has the EXECUTE privilege or the user is the owner. There is no guarantee of a specific ordering of the elements in the array.

databricks functions list CATALOG_NAME SCHEMA_NAME [flags]

Arguments

CATALOG_NAME

    Name of parent catalog for functions of interest.

SCHEMA_NAME

    Parent schema of functions.

Options

--include-browse

    Whether to include functions in the response for which the principal can only access selective metadata for.

--max-results int

    Maximum number of functions to return.

--page-token string

    Opaque pagination token to go to next page based on previous query.

Global flags

Examples

The following example lists all functions in a catalog and schema:

databricks functions list my_catalog my_schema

The following example lists functions with a maximum of 10 results:

databricks functions list my_catalog my_schema --max-results 10

The following example lists functions with browse information included:

databricks functions list my_catalog my_schema --include-browse

databricks functions update

Update the function that matches the supplied name.

Only the owner of the function can be updated. If the user is not a metastore admin, the user must be a member of the group that is the new function owner. The user must satisfy one of the following conditions:

  • Is a metastore admin
  • Is the owner of the function's parent catalog
  • Is the owner of the function's parent schema and has the USE_CATALOG privilege on its parent catalog
  • Is the owner of the function itself and has the USE_CATALOG privilege on its parent catalog as well as the USE_SCHEMA privilege on the function's parent schema
databricks functions update NAME [flags]

Arguments

NAME

    The fully-qualified name of the function (of the form catalog_name.schema_name.function_name).

Options

--json JSON

    The inline JSON string or the @path to the JSON file with the request body.

--owner string

    Username of current owner of function.

Global flags

Examples

The following example updates a function's owner:

databricks functions update my_catalog.my_schema.my_function --owner someone@example.com

Global flags

--debug

  Whether to enable debug logging.

-h or --help

    Display help for the Databricks CLI or the related command group or the related command.

--log-file string

    A string representing the file to write output logs to. If this flag is not specified then the default is to write output logs to stderr.

--log-format format

    The log format type, text or json. The default value is text.

--log-level string

    A string representing the log format level. If not specified then the log format level is disabled.

-o, --output type

    The command output type, text or json. The default value is text.

-p, --profile string

    The name of the profile in the ~/.databrickscfg file to use to run the command. If this flag is not specified then if it exists, the profile named DEFAULT is used.

--progress-format format

    The format to display progress logs: default, append, inplace, or json

-t, --target string

    If applicable, the bundle target to use