pyspark.sql.functions.try_multiply

pyspark.sql.functions.try_multiply(left: ColumnOrName, right: ColumnOrName) → pyspark.sql.column.Column[source]

Returns left`*`right and the result is null on overflow. The acceptable input types are the same with the * operator.

New in version 3.5.0.

Parameters
leftColumn or str

multiplicand

rightColumn or str

multiplier

Examples

>>> df = spark.createDataFrame([(6000, 15), (1990, 2)], ["a", "b"])
>>> df.select(try_multiply(df.a, df.b).alias('r')).collect()
[Row(r=90000), Row(r=3980)]
>>> df = spark.createDataFrame([(2, 3),], ["a", "b"])
>>> df.select(try_multiply(make_interval(df.a), df.b).alias('r')).show(truncate=False)
+-------+
|r      |
+-------+
|6 years|
+-------+