startswith
Returns a boolean. The value is True if str starts with prefix. Returns NULL if either input expression is NULL. Otherwise, returns False. Both str or prefix must be of STRING or BINARY type.
For the corresponding Databricks SQL function, see startswith function.
Syntax
Python
from pyspark.databricks.sql import functions as dbf
dbf.startswith(str=<str>, prefix=<prefix>)
Parameters
Parameter | Type | Description |
|---|---|---|
|
| A column of string. |
|
| A column of string, the prefix. |
Examples
Python
df = spark.createDataFrame([("Spark SQL", "Spark",)], ["a", "b"])
df.select(startswith(df.a, df.b).alias('r')).collect()
Python
df = spark.createDataFrame([("414243", "4142",)], ["e", "f"])
df = df.select(to_binary("e").alias("e"), to_binary("f").alias("f"))
df.printSchema()
df.select(startswith("e", "f"), startswith("f", "e")).show()