find_in_set
Returns the index (1-based) of the given string (str) in the comma-delimited list (strArray). Returns 0, if the string was not found or if the given string (str) contains a comma.
For the corresponding Databricks SQL function, see find_in_set function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.find_in_set(str=<str>, str_array=<str_array>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| The given string to be found. |
|
| The comma-delimited list. Examples -------- >>> df = spark.createDataFrame([("ab", "abc,b,ab,c,def")], ['a', 'b']) >>> df.select(find_in_set(df.a, df.b).alias('r')).collect() [Row(r=3)] |
Examples
Python
df = spark.createDataFrame([("ab", "abc,b,ab,c,def")], ['a', 'b'])
df.select(find_in_set(df.a, df.b).alias('r')).collect()