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

Returns a boolean. The value is True if right is found inside left. Returns NULL if either input expression is NULL. Otherwise, returns False. Both left or right must be of STRING or BINARY type.

New in version 3.5.0.

leftColumn or str

The input column or strings to check, may be NULL.

rightColumn or str

The input column or strings to find, may be NULL.


>>> df = spark.createDataFrame([("Spark SQL", "Spark")], ['a', 'b'])
>>>, df.b).alias('r')).collect()
>>> df = spark.createDataFrame([("414243", "4243",)], ["c", "d"])
>>> df ="c").alias("c"), to_binary("d").alias("d"))
>>> df.printSchema()
 |-- c: binary (nullable = true)
 |-- d: binary (nullable = true)
>>>"c", "d"), contains("d", "c")).show()
|contains(c, d)|contains(d, c)|
|          true|         false|