snowflake.snowpark.functions.strtok¶
- snowflake.snowpark.functions.strtok(string: Union[snowflake.snowpark.column.Column, str], delimiter: Union[snowflake.snowpark.column.Column, str] = None, part_nr: Union[snowflake.snowpark.column.Column, str] = None) Column[source]¶
Tokenizes a string with the given set of delimiters and returns the requested part.
- Parameters:
string (ColumnOrName) – The string to be tokenized.
delimiter (ColumnOrName, optional) – A set of delimiters. Each character in the delimiter string is treated as a delimiter. If not specified, defaults to a single space character.
part_nr (ColumnOrName, optional) – The requested part number (1-based). If not specified, returns the entire string.
- Returns:
The requested part of the tokenized string.
- Return type:
- Examples::
>>> from snowflake.snowpark.functions import col, lit >>> df = session.create_dataframe([["a.b.c"]], schema=["string_col"]) >>> df.select(strtok(col("string_col")).alias("result")).collect() [Row(RESULT='a.b.c')] >>> df.select(strtok(col("string_col"), lit(".")).alias("result")).collect() [Row(RESULT='a')] >>> df.select(strtok(col("string_col"), lit("."), lit(2)).alias("result")).collect() [Row(RESULT='b')] >>> df2 = session.create_dataframe([["user@snowflake.com"]], schema=["string_col"]) >>> df2.select(strtok(col("string_col"), lit("@."), lit(1)).alias("result")).collect() [Row(RESULT='user')] >>> df2.select(strtok(col("string_col"), lit("@."), lit(3)).alias("result")).collect() [Row(RESULT='com')]