メインコンテンツまでスキップ

try_url_decode

これはurl_decodeの特別なバージョンであり、同じ操作を実行しますが、デコードを実行できない場合はエラーを発生させる代わりに NULL 値を返します。

構文

Python
from pyspark.sql import functions as sf

sf.try_url_decode(str)

パラメーター

パラメーター

Type

説明

str

pyspark.sql.Column または文字列

文字列の列。それぞれが URL エンコードされた文字列を表します。

戻り値

pyspark.sql.Column: 文字列の新しい列。それぞれがデコードされた文字列を表します。

例1 : URLエンコードされた文字列のデコード

Python
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)
Output
+------------------------+
|try_url_decode(url) |
+------------------------+
|https://spark.apache.org|
+------------------------+

例2 : デコードが実行できない場合はNULLを返す

Python
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()
Output
+-------------------+
|try_url_decode(url)|
+-------------------+
| NULL|
+-------------------+