Skip to main content

try_multiply

Returns left_right and the result is null on overflow. The acceptable input types are the same with the _ operator. Supports Spark Connect.

For the corresponding Databricks SQL function, see try_multiply function.

Syntax​

Python
from pyspark.sql import functions as dbf

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

Parameters​

Parameter

Type

Description

left

pyspark.sql.Column or column name

multiplicand

right

pyspark.sql.Column or column name

multiplier

Parameter

Type

Description

left

pyspark.sql.Column or column name

multiplicand

right

pyspark.sql.Column or column name

multiplier

Examples​

Python
from pyspark.sql import functions as dbf
spark.createDataFrame(
[(6000, 15), (1990, 2)], ["a", "b"]
).select("*", dbf.try_multiply("a", "b")).show()
Output
+----+---+------------------+
| a| b|try_multiply(a, b)|
+----+---+------------------+
|6000| 15| 90000|
|1990| 2| 3980|
+----+---+------------------+

Python
from pyspark.sql import functions as dbf
df = spark.range(6).select(dbf.make_interval(dbf.col("id"), dbf.lit(3)).alias("itvl"), "id")
df.select("*", dbf.try_multiply("itvl", "id")).show()
Output
+----------------+---+----------------------+
| itvl| id|try_multiply(itvl, id)|
+----------------+---+----------------------+
| 3 months| 0| 0 seconds|
|1 years 3 months| 1| 1 years 3 months|
|2 years 3 months| 2| 4 years 6 months|
|3 years 3 months| 3| 9 years 9 months|
|4 years 3 months| 4| 17 years|
|5 years 3 months| 5| 26 years 3 months|
+----------------+---+----------------------+