parse_url function

Applies to: check marked yes Databricks SQL check marked yes Databricks Runtime

Extracts a part from url.

Syntax

parse_url(url, partToExtract [, key] )

Arguments

  • url: A STRING expression.

  • partToExtract: A STRING expression.

  • key: A STRING expression.

Returns

A STRING.

partToExtract must be one of:

  • 'HOST'

  • 'PATH'

  • 'QUERY'

  • 'REF'

  • 'PROTOCOL'

  • 'FILE'

  • 'AUTHORITY'

  • 'USERINFO'

key is case-sensitive.

If a requested partToExtract or key is not found, NULL is returned.

Databricks returns an error if the url string is invalid.

Note

In Databricks Runtime, if spark.sql.ansi.enabled is false, parse_url returns NULL if the url string is invalid.

Examples

> SELECT parse_url('http://spark.apache.org/path?query=1', 'HOST');
 spark.apache.org

> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY');
 query=1

> SELECT parse_url('http://spark.apache.org/path?query=1', 'QUERY', 'query');
 1

> SELECT parse_url('http://spark.  apache.org/path?query=1', 'QUERY', 'query');
Error: Illegal argument