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

引き算を試す

left - rightを返し、オーバーフローの場合は結果は null になります。許容される入力タイプは-演算子と同じです。Spark Connect をサポートします。

対応する Databricks SQL 関数については、 try_subtract関数を参照してください。

構文

Python
from pyspark.databricks.sql import functions as dbf

dbf.try_subtract(left=<left>, right=<right>)

パラメーター

パラメーター

Type

説明

left

pyspark.sql.Column or column name

right

pyspark.sql.Column or column name

Python
from pyspark.databricks.sql import functions as dbf
spark.createDataFrame(
[(1982, 15), (1990, 2)], ["birth", "age"]
).select("*", dbf.try_subtract("birth", "age")).show()
Output
+-----+---+------------------------+
|birth|age|try_subtract(birth, age)|
+-----+---+------------------------+
| 1982| 15| 1967|
| 1990| 2| 1988|
+-----+---+------------------------+

Python
from pyspark.databricks.sql import functions as dbf
spark.sql(
"SELECT * FROM VALUES (DATE('2015-10-01')) AS TAB(date)"
).select("*", dbf.try_subtract("date", dbf.lit(1))).show()
Output
+----------+---------------------+
| date|try_subtract(date, 1)|
+----------+---------------------+
|2015-10-01| 2015-09-30|
+----------+---------------------+