pyspark.sql.functions.
assert_true
Returns null if the input column is true; throws an exception with the provided error message otherwise.
New in version 3.1.0.
Column
column name or column that represents the input column to test
A Python string literal or column containing the error message
Examples
>>> df = spark.createDataFrame([(0,1)], ['a', 'b']) >>> df.select(assert_true(df.a < df.b).alias('r')).collect() [Row(r=None)] >>> df = spark.createDataFrame([(0,1)], ['a', 'b']) >>> df.select(assert_true(df.a < df.b, df.a).alias('r')).collect() [Row(r=None)] >>> df = spark.createDataFrame([(0,1)], ['a', 'b']) >>> df.select(assert_true(df.a < df.b, 'error').alias('r')).collect() [Row(r=None)]