Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Encodes a string into a URL-encoded string in 'application/x-www-form-urlencoded' format.
Syntax
from pyspark.sql import functions as sf
sf.url_encode(str)
Parameters
| Parameter | Type | Description |
|---|---|---|
str |
pyspark.sql.Column or str |
A column of strings, each representing a string to be URL-encoded. |
Returns
pyspark.sql.Column: A new column of strings, each representing the URL-encoded string.
Examples
Example 1: Encoding a simple URL
from pyspark.sql import functions as sf
df = spark.createDataFrame([("https://spark.apache.org",)], ["url"])
df.select(sf.url_encode(df.url)).show(truncate=False)
+------------------------------+
|url_encode(url) |
+------------------------------+
|https%3A%2F%2Fspark.apache.org|
+------------------------------+
Example 2: Encoding a URL with spaces
from pyspark.sql import functions as sf
df = spark.createDataFrame([("Hello World!",)], ["url"])
df.select(sf.url_encode(df.url)).show()
+---------------+
|url_encode(url)|
+---------------+
| Hello+World%21|
+---------------+
Example 3: Encoding a URL with special characters
from pyspark.sql import functions as sf
df = spark.createDataFrame([("A+B==",)], ["url"])
df.select(sf.url_encode(df.url)).show()
+---------------+
|url_encode(url)|
+---------------+
| A%2BB%3D%3D|
+---------------+
Example 4: Encoding a URL with non-ASCII characters
from pyspark.sql import functions as sf
df = spark.createDataFrame([("你好",)], ["url"])
df.select(sf.url_encode(df.url)).show()
+------------------+
| url_encode(url)|
+------------------+
|%E4%BD%A0%E5%A5%BD|
+------------------+