databend icon indicating copy to clipboard operation
databend copied to clipboard

bug: Higher order functions in SQL UDFs and queries do not share outer scope.

Open maxjustus opened this issue 10 months ago • 1 comments

Search before asking

  • [X] I had searched in the issues and found no similar issues.

Version

v1.2.371-a95ac62303

What's Wrong?

if do

create or replace function array_except as (x, y) -> array_filter(x, el -> not contains(y, el));
select array_except([1,2], [2,3]);

I get the following error: column y doesn't exist

if I do

with
  t as (select [2,3] as y)
select array_filter([1,2], el -> not contains(y, el)) from t;

I get the same error: column y doesn't exist

If I execute the equivalent SQL using constants it of course works:

select array_filter([1,2], el -> not contains([2,3], el))
-- returns [1]

Not being able to use variables or column aliases in higher order functions significantly limits their utility. I would love to see this fixed!

How to Reproduce?

No response

Are you willing to submit PR?

  • [X] Yes I am willing to submit a PR!

maxjustus avatar Apr 19 '24 01:04 maxjustus

Hi, @maxjustus Thanks for report the bug. Currently the array lambda function doesn't support external columns, we'll add this in the near future.

b41sh avatar Apr 22 '24 15:04 b41sh

Hi @maxjustus the bug has fixed, thanks again for your report.

b41sh avatar Jul 05 '24 15:07 b41sh