Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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
from pyspark.databricks.sql import functions as dbf
dbf.locate(substr=<substr>, str=<str>, pos=<pos>)
Parameters
| Parameter | Type | Description |
|---|---|---|
substr |
literal string |
a string |
str |
pyspark.sql.Column or str |
a Column of pyspark.sql.types.StringType |
pos |
int, optional |
start position (zero based) |
Returns
pyspark.sql.Column: position of the substring.
Examples
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()