pyspark.sql.functions.url_decode#

pyspark.sql.functions.url_decode(str)[source]#

URL function: Decodes a URL-encoded string in ‘application/x-www-form-urlencoded’ format to its original format.

New in version 3.5.0.

Parameters
strColumn or str

A column of strings, each representing a URL-encoded string.

Returns
Column

A new column of strings, each representing the decoded string.

Examples

Example 1: Decoding a URL-encoded string

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([("https%3A%2F%2Fspark.apache.org",)], ["url"])
>>> df.select(sf.url_decode(df.url)).show(truncate=False)
+------------------------+
|url_decode(url)         |
+------------------------+
|https://spark.apache.org|
+------------------------+

Example 2: Decoding a URL-encoded string with spaces

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([("Hello%20World%21",)], ["url"])
>>> df.select(sf.url_decode(df.url)).show()
+---------------+
|url_decode(url)|
+---------------+
|   Hello World!|
+---------------+

Example 3: Decoding a URL-encoded string with special characters

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([("A%2BB%3D%3D",)], ["url"])
>>> df.select(sf.url_decode(df.url)).show()
+---------------+
|url_decode(url)|
+---------------+
|          A+B==|
+---------------+

Example 4: Decoding a URL-encoded string with non-ASCII characters

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([("%E4%BD%A0%E5%A5%BD",)], ["url"])
>>> df.select(sf.url_decode(df.url)).show()
+---------------+
|url_decode(url)|
+---------------+
|           你好|
+---------------+

Example 5: Decoding a URL-encoded string with hexadecimal values

>>> from pyspark.sql import functions as sf
>>> df = spark.createDataFrame([("%7E%21%40%23%24%25%5E%26%2A%28%29%5F%2B",)], ["url"])
>>> df.select(sf.url_decode(df.url)).show()
+---------------+
|url_decode(url)|
+---------------+
|  ~!@#$%^&*()_+|
+---------------+