pyspark.sql.functions.try_url_decode#
- pyspark.sql.functions.try_url_decode(str)[source]#
This is a special version of url_decode that performs the same operation, but returns a NULL value instead of raising an error if the decoding cannot be performed.
New in version 4.0.0.
- Parameters
- str
Column
or str A column of strings, each representing a URL-encoded string.
- str
- 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.try_url_decode(df.url)).show(truncate=False) +------------------------+ |try_url_decode(url) | +------------------------+ |https://spark.apache.org| +------------------------+
Example 2: Return NULL if the decoding cannot be performed.
>>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([("https%3A%2F%2spark.apache.org",)], ["url"]) >>> df.select(sf.try_url_decode(df.url)).show() +-------------------+ |try_url_decode(url)| +-------------------+ | NULL| +-------------------+