risingwavelabs / risingwave

SQL stream processing, analytics, and management. We decouple storage and compute to offer efficient joins, instant failover, dynamic scaling, speedy bootstrapping, and concurrent query serving.
https://www.risingwave.com/slack
Apache License 2.0
6.64k stars 545 forks source link

incorrect result for SQL UDF with aggregate functions #16578

Open xxchan opened 2 months ago

xxchan commented 2 months ago

Describe the bug

create function mycount(x int[]) returns bigint language sql as 'select count(*) from unnest(x)';

select mycount('{1,2}');
┌─────────┐
│ mycount │
├─────────┤
│       1 │
└─────────┘

create table t(x int[]); insert into t values('{1,2,3}'),('{3,4}');

select mycount(x) from t;
┌─────────┐
│ mycount │
├─────────┤
│       2 │
└─────────┘

postgres:

+---------+
| mycount |
|---------|
| 2       |
+---------+

+---------+
| mycount |
|---------|
| 3       |
| 2       |
+---------+

Maybe we should ban agg in SQL UDF for now.

Error message/log

No response

To Reproduce

No response

Expected behavior

No response

How did you deploy RisingWave?

No response

The version of RisingWave

No response

Additional context

No response

xxchan commented 2 months ago

BTW, I found this when I was trying to solve the problem of casting a jsonb array to normal array (and then to use array functions like array_to_string). That may also require a aggregate SQL UDF.

https://risingwave-community.slack.com/archives/C03BW71523T/p1714818123417119

github-actions[bot] commented 2 weeks ago

This issue has been open for 60 days with no activity.

If you think it is still relevant today, and needs to be done in the near future, you can comment to update the status, or just manually remove the no-issue-activity label.

You can also confidently close this issue as not planned to keep our backlog clean. Don't worry if you think the issue is still valuable to continue in the future. It's searchable and can be reopened when it's time. 😄