snowflake.snowpark.functions.editdistance¶

snowflake.snowpark.functions.editdistance(e1: Union[Column, str], e2: Union[Column, str], max_distance: Optional[Union[Column, str, int]] = None) → Column[source]¶

Computes the Levenshtein distance between two input strings.

Optionally, a maximum distance can be specified. If the distance exceeds this value, the computation halts and returns the maximum distance.

Example:

>>> df = session.create_dataframe(
...     [["abc", "def"], ["abcdef", "abc"], ["snow", "flake"]],
...     schema=["s1", "s2"]
... )
>>> df.select(
...     editdistance(col("s1"), col("s2")).alias("distance"),
...     editdistance(col("s1"), col("s2"), 2).alias("max_2_distance")
... ).collect()
[Row(DISTANCE=3, MAX_2_DISTANCE=2), Row(DISTANCE=3, MAX_2_DISTANCE=2), Row(DISTANCE=5, MAX_2_DISTANCE=2)]
Copy