snowflake.snowpark.functions.split_part¶

snowflake.snowpark.functions.split_part(string: Union[snowflake.snowpark.column.Column, str], delimiter: Union[snowflake.snowpark.column.Column, str], part_number: Union[snowflake.snowpark.column.Column, str]) → Column[source]¶

Splits a given string at a specified character and returns the requested part.

Parameters:
  • string (ColumnOrName) – The string to be split.

  • delimiter (ColumnOrName) – The delimiter to split the string on.

  • part_number (ColumnOrName) – The part number to return (1-based indexing). Negative numbers count from the end.

Returns:

The specified part of the split string.

Return type:

Column

Examples::
>>> from snowflake.snowpark.functions import col
>>> df = session.create_dataframe([
...     ("11.22.33", ".", 1),
...     ("11.22.33", ".", 2),
...     ("11.22.33", ".", 3),
...     ("11.22.33", ".", -1),
...     ("127.0.0.1", ".", 1),
...     ("127.0.0.1", ".", -1),
...     ("|a|b|c|", "|", 1),
...     ("|a|b|c|", "|", 2),
...     ("aaa--bbb-BBB--ccc", "--", 2)
... ], schema=["string_col", "delimiter_col", "part_number_col"])
>>> result = df.select(split_part(col("string_col"), col("delimiter_col"), col("part_number_col")).alias("result"))
>>> result.collect()
[Row(RESULT='11'), Row(RESULT='22'), Row(RESULT='33'), Row(RESULT='33'), Row(RESULT='127'), Row(RESULT='1'), Row(RESULT=''), Row(RESULT='a'), Row(RESULT='bbb-BBB')]
Copy