datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

support IFNULL function

Open guojidan opened this issue 2 years ago • 3 comments

Is your feature request related to a problem or challenge?

https://docs.databend.com/sql/sql-functions/conditional-functions/ifnull I want implement IFNULL function, As implemented by databend

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

Additional context

guojidan avatar Feb 18 '24 09:02 guojidan

cc @alamb , Is it necessary to implement this function? if yes I will do it

guojidan avatar Feb 18 '24 09:02 guojidan

~~There's nullif already: https://arrow.apache.org/datafusion/user-guide/sql/scalar_functions.html#nullif~~

~~Could add ifnull as an alias if there's need for it I suppose~~ :thinking:

Edit: ah my mistake, seems nullif does something different than ifnull

Jefffrey avatar Feb 18 '24 11:02 Jefffrey

TLDR I think implementing this function (perhaps call it nvl and add an alias to ifnull) would be a good addition. Thank you @guojidan

I thought DataFusion already supported the NVL function but I guess I was remembering the Nan equivalent of nanvl: https://arrow.apache.org/datafusion/user-guide/sql/scalar_functions.html#nanvl

So the steps are something like:

  1. add function
  2. add sqllogictests
  3. add doc entries

Should be a good feature 🏆

Can you please implement it as a ScalarUDF in https://github.com/apache/arrow-datafusion/tree/main/datafusion/functions/src/core (following the model of nullif) rather than adding to BuiltInFunction?

alamb avatar Feb 19 '24 07:02 alamb