返回字符串 str 中在分隔符 delim 出现 count 次之前的子字符串。 如果 count 为正数,则返回最终分隔符(从左计数)的左侧的所有内容。 如果 count 为负数,则返回最终分隔符右侧的每一个(从右计数)。 substring_index搜索 delim 时执行区分大小写的匹配。
有关相应的 Databricks SQL 函数,请参阅 substring_index 函数。
Syntax
from pyspark.databricks.sql import functions as dbf
dbf.substring_index(str=<str>, delim=<delim>, count=<count>)
参数
| 参数 | 类型 | Description |
|---|---|---|
str |
pyspark.sql.Column 或 str |
要处理的目标列。 |
delim |
literal string |
值的分隔符。 |
count |
int |
出现次数。 |
退货
pyspark.sql.Column:给定值的子字符串。
例子
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('a.b.c.d',)], ['s'])
df.select('*', dbf.substring_index(df.s, '.', 2)).show()
df.select('*', dbf.substring_index('s', '.', -3)).show()