locate
Locate the position of the first occurrence of substr in a string column, after position pos.
For the corresponding Databricks SQL function, see locate function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.locate(substr=<substr>, str=<str>, pos=<pos>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| a string |
|
| a Column of |
|
| start position (zero based) |
Returns
pyspark.sql.Column: position of the substring.
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('abcd',)], ['s',])
df.select('*', dbf.locate('b', 's', 1)).show()
df.select('*', dbf.locate('b', df.s, 3)).show()