pyspark.sql.functions.endswith#

pyspark.sql.functions.endswith(str, suffix)[source]#

Returns a boolean. The value is True if str ends with suffix. Returns NULL if either input expression is NULL. Otherwise, returns False. Both str or suffix must be of STRING or BINARY type.

Added in version 3.5.0.

Parameters:
strColumn or str

The input value to test. A column that evaluates to a string or binary.

suffixColumn or str

The suffix to test for. A column that evaluates to a string or binary.

Examples

>>> df = spark.createDataFrame([("Spark SQL", "Spark",)], ["a", "b"])
>>> df.select(endswith(df.a, df.b).alias('r')).collect()
[Row(r=False)]
>>> df = spark.createDataFrame([("414243", "4243",)], ["e", "f"])
>>> df = df.select(to_binary("e").alias("e"), to_binary("f").alias("f"))
>>> df.printSchema()
root
 |-- e: binary (nullable = true)
 |-- f: binary (nullable = true)
>>> df.select(endswith("e", "f"), endswith("f", "e")).show()
+--------------+--------------+
|endswith(e, f)|endswith(f, e)|
+--------------+--------------+
|          true|         false|
+--------------+--------------+