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.
Returns the remainder after dividend/divisor. Its result is always null if divisor is 0. Supports Spark Connect.
For the corresponding Databricks SQL function, see try_mod function.
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.try_mod(left=<left>, right=<right>)
Parameters
| Parameter | Type | Description |
|---|---|---|
left |
pyspark.sql.Column or column name |
dividend |
right |
pyspark.sql.Column or column name |
divisor |
Examples
from pyspark.databricks.sql import functions as dbf
spark.createDataFrame(
[(6000, 15), (3, 2), (1234, 0)], ["a", "b"]
).select("*", dbf.try_mod("a", "b")).show()
+----+---+-------------+
| a| b|try_mod(a, b)|
+----+---+-------------+
|6000| 15| 0|
| 3| 2| 1|
|1234| 0| NULL|
+----+---+-------------+
from pyspark.databricks.sql import functions as dbf
origin = spark.conf.get("spark.sql.ansi.enabled")
spark.conf.set("spark.sql.ansi.enabled", "true")
try:
spark.range(1).select(dbf.try_mod("id", dbf.lit(0))).show()
finally:
spark.conf.set("spark.sql.ansi.enabled", origin)
+--------------+
|try_mod(id, 0)|
+--------------+
| NULL|
+--------------+