brimdata / zed

A novel data lake based on super-structured data
https://zed.brimdata.io/
BSD 3-Clause "New" or "Revised" License
1.38k stars 67 forks source link

Spread values from an array to become the multiple args to coalesce() #5201

Open philrz opened 1 month ago

philrz commented 1 month ago

tl;dr

I attempted this, but it's not currently possible.

$ zq 'const a = [null,2] yield coalesce(...a)'
zq: could not invoke zq with a single argument because:
 - a file could not be found with the name "const a = [null,2] y..."
 - the argument could not be compiled as a valid Zed query:
   error parsing Zed at line 1, column 36:
   const a = [null,2] yield coalesce(...a)
                                  === ^ ===

Details

Repro is with Zed commit c39086b.

I attempted this when working on this example shown in #5186.

@mattnibs gave a 👍 reaction to the idea, also adding:

In the semantic pass we do check if the number of arguments in a call match that of the declared function and return an error if not. You couldn't do that here but I don't think there's a problem returning an error in runtime. Just depends on how strict we want to be.