apache / datafusion

Apache DataFusion SQL Query Engine
https://datafusion.apache.org/
Apache License 2.0
6.03k stars 1.14k forks source link

Explore Updating VariadicAny Signature to take 0 Args #11522

Open tshauck opened 2 months ago

tshauck commented 2 months ago

Is your feature request related to a problem or challenge?

Currently VariadicAny represents 1 or more arguments, but given the name and seemingly intention, it seems like 0 or more would make more sense (though there a number of counter examples).

See https://github.com/apache/datafusion/pull/11229/files#r1680888279 for more discussion.

Describe the solution you'd like

VariadicAny is updated to support 0 arguments.

Describe alternatives you've considered

See the linked discussion for a few alternatives. It's unclear if VariadicAny w/ 0 args is the best option here, but was an issue implementing COUNT().

Additional context

https://github.com/apache/datafusion/blob/b0925c801e1c07bd78c78b045ab58fbd0630b638/datafusion/expr/src/signature.rs#L100-L101

2010YOUY01 commented 2 months ago

Does that work for your use case? I vaguely remember VariadicAny is set to >=1 argument for some reason 🤔 https://github.com/apache/datafusion/blob/b0925c801e1c07bd78c78b045ab58fbd0630b638/datafusion/expr/src/signature.rs#L116-L118

tshauck commented 2 months ago

That's actually what I did do in https://github.com/apache/datafusion/blob/b19744968770c4ab426d065dec3cc5147534e87a/datafusion/functions-aggregate/src/count.rs#L98-L102 -- it was more the discussion in https://github.com/apache/datafusion/pull/11229/files#r1680888279. To your point, I took a quick look at duckdb and they also represent their variadic any as >= 1, so maybe there is a good reason, and if someone can remember it (or rediscover it), it could be good to document.

jayzhan211 commented 1 month ago

The reason is that we currently use VariadicAny for functions that expect at least one args. If we now accept empty args for VariadicAny, we need to do tons of non-zero length check for them. functions that accept 0 is little, therefore adding Any(0) is easy.