Piezīmes
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt pierakstīties vai mainīt direktorijus.
Lai piekļūtu šai lapai, ir nepieciešama autorizācija. Varat mēģināt mainīt direktorijus.
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
from pyspark.databricks.sql import functions as dbf
dbf.instr(str=<str>, substr=<substr>)
Parameters
| Parameter | Type | Description |
|---|---|---|
str |
pyspark.sql.Column or str |
target column to work on. |
substr |
pyspark.sql.Column or literal string |
substring to look for. |
Returns
pyspark.sql.Column: location of the first occurrence of the substring as integer.
Examples
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()