apache / datafusion-python

Apache DataFusion Python Bindings
https://datafusion.apache.org/python
Apache License 2.0
343 stars 69 forks source link

Add case function #447

Closed mesejo closed 1 year ago

mesejo commented 1 year ago

Is your feature request related to a problem or challenge? Please describe what you are trying to do. I would like to add to use the case conditional function from Python.

Describe the solution you'd like Ideally, I would like it to be possible to do something like the following:

df = df.select(
        f.case(column("a"))
        .when(literal("Hello"), literal("Hola"))
        .when(literal("World"), literal("Mundo"))
        .otherwise(literal("!!")),
    )

Describe alternatives you've considered None

Additional context This was suggested as a possible solution by @alamb in arrow-datafusion#7062 discussion