`count` vs `count *`
In the example functions, there are two functions with the same name:
func count = s"COUNT(*)"
func count column = s"COUNT({column})"
We need to decide how to handle these.
Options:
- Don't allow this —
count *would be required rather than justcount- This would be tempting to use in the short term, but has the disadvantage that we'd need to special-case the
*, since it's currently an operator (i.e.foo * 3). I don't think it's a CS PhD to implement, but it's the sort of special-casing that causes issues later, both in the code and our ability to provide good error messages. - We could find a different symbol than
*, but that's also unfamiliar.
- This would be tempting to use in the short term, but has the disadvantage that we'd need to special-case the
- Multiple dispatch — i.e. the compiler allows for multiple functions with the same name as long as they have different signatures, and it selects the function that matches the signature. In this case the number of positional args defines the signature. So the function definitions above would be correct.
- Use a named argument — so
func count column="*" = s"COUNT({column})". But then people have to writecount column:salary, which isn't friendly — and either we do it everywhere, or it's unfamiliar in thecountcase (there's nosum *). - Allow optional positional args, and find a different way of specifying named args. As a reminder, this is our current function specification, and has the advantage that it's extremely simple — only two types of arguments, with named arguments defined by having a default. This is python's.
I vote multi dispatch, based on the number of arguments. Nothing fancy, just match the number of arguments supplied to the number defined.
As discussed on discord, one downside of multiple dispatch which I forgot to mention, is it preludes partials / currying; e.g.:
func add a b = a + b
func plus_one = add 1
# Does `add 1` curry `add a b`? Or refer to a one-arg version of `add`?
(though I don't think it's that important, and definitely not in the short term)
This is the last item in https://github.com/max-sixty/prql/milestone/1 and I can't think of sufficiently general solution to the problem. I was leaning to count_all, but it's just awkward. I'm fine sacrificing currying, but adding multiple dispatch isn't trivial and doesn't seem to serve any purpose beyond this specific case.
I think I'm going to hack the parser so count * is allowed, and then we can iterate from there.
We're going to have the same issue with select foo_table.*
One approach here that might work is count ., or select foo_table.. I think that could work quite well. Any thoughts?
In my latest patch, both count and count first_name can coexist, so we can parse * only as part of ident or as operator.