brimdata / zed

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

Stateful expressions in user defined functions #5092

Closed mattnibs closed 2 weeks ago

mattnibs commented 3 months ago

Aggregations are supposed to carry separate state for each textual invocation but this rule breaks apart when using aggregation expressions in user defined functions. Observe:

func c(): ( count() )
yield [c(), c(), c()]

currently returns

[1,2,3]

when it should be returning [1,1,1].

philrz commented 2 weeks ago

Verified in Zed commit 9c3f5fd.

The example program now returns the expected output that reflects separate state with each invocation.

$ zq -version
Version: v1.15.0-42-g9c3f5fdc

$ zq 'func c(): ( count() ) yield [c(), c(), c()]'
[1(uint64),1(uint64),1(uint64)]

Thanks @mattnibs!