snowpark-python icon indicating copy to clipboard operation
snowpark-python copied to clipboard

SNOW-960172: Add `map_dict` functionality

Open granthamtaylor opened this issue 1 year ago • 1 comments

What is the current behavior?

I have some arbitrary values in a column. Let's say the unique values of this column are in the set {"foo", "bar", "buzz"}.

I would like to be able to have a pythonic way to apply some function in way resembling a case-switch operation, but using a pythonic dictionary.

To my understanding, this is not possible to do in the current Python Snowpark SDK without resorting to a recursive case-when expression, a custom function, or using a templates SQL expression.

What is the desired behavior?

I would like to be able to use a pythonic expression on a reference to the column with like so: col("colname").map_dict({"foo": 5, "bar": 6, "buzz": 12}), which would convert any existing keys in the provided dictionary with their associated values. In this example, every instance of "foo" becomes 5, and the correct data type of the new column is coerced accordingly. Should a unique value in the column not be available in the set of keys of the provided dictionary, it would result in a null value.

How would this improve snowflake-snowpark-python?

This is extremely vital functionality that, to my understanding, is far too complicated to implement with the current implementation of a CASE WHEN statement

References, Other Background

This behavior is provided in the Polars API

granthamtaylor avatar Nov 03 '23 22:11 granthamtaylor

Hi @granthamtaylor , I would like to have a look into the issue.

RahulDubey391 avatar Nov 30 '23 14:11 RahulDubey391