parse_url function (Databricks SQL)

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 SQL returns an error 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