instr
Locate the position of the first occurrence of substr column in the given string. Returns null if either of the arguments are null.
The position is not zero based, but 1 based index. Returns 0 if substr could not be found in str.
For the corresponding Databricks SQL function, see instr function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.instr(str=<str>, substr=<substr>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| target column to work on. |
|
| substring to look for. |
Returns
pyspark.sql.Column: location of the first occurrence of the substring as integer.
Examples
Python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([("abcd",), ("xyz",)], ["s",])
df.select("*", dbf.instr(df.s, "b")).show()
df = spark.createDataFrame([("abcd",), ("xyz",)], ["s",])
df.select("*", dbf.instr("s", dbf.lit("abc").substr(0, 2))).show()