Skip to content

Feature: add list function like duckdb #10497

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
l1t1 opened this issue Mar 11, 2023 · 7 comments
Open

Feature: add list function like duckdb #10497

l1t1 opened this issue Mar 11, 2023 · 7 comments
Assignees
Labels
C-feature Category: feature good first issue Category: good first issue

Comments

@l1t1
Copy link

l1t1 commented Mar 11, 2023

Summary
list(a)
fill rows of column a into a list/array
also support group by and order by
eg.

D select list(i)from range(10)t(i);
┌────────────────────────────────┐
│            list(i)             │
│            int64[]             │
├────────────────────────────────┤
│ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] │
└────────────────────────────────┘
D select i%3,list(i)from range(10)t(i)group by i%3;
┌─────────┬──────────────┐
│ (i % 3) │   list(i)    │
│  int64  │   int64[]    │
├─────────┼──────────────┤
│       0 │ [0, 3, 6, 9] │
│       1 │ [1, 4, 7]    │
│       2 │ [2, 5, 8]    │
└─────────┴──────────────┘
@l1t1 l1t1 added the C-feature Category: feature label Mar 11, 2023
@l1t1
Copy link
Author

l1t1 commented Mar 11, 2023

D select i%3,list(i order by i desc)from range(10)t(i)group by i%3;
┌─────────┬─────────────────────────┐
│ (i % 3) │ list(i ORDER BY i DESC) │
│  int64  │         int64[]         │
├─────────┼─────────────────────────┤
│       0 │ [9, 6, 3, 0]            │
│       1 │ [7, 4, 1]               │
│       2 │ [8, 5, 2]               │
└─────────┴─────────────────────────┘

@sundy-li
Copy link
Member

sundy-li commented Mar 11, 2023

This is a kind of aggregate function, it's an easy task I think.

@sundy-li sundy-li added the good first issue Category: good first issue label Mar 11, 2023
@wangjili8417
Copy link

/assignme

@l1t1
Copy link
Author

l1t1 commented Mar 13, 2023

WITH SAMPLE_DATA AS (
    SELECT 'A' as var1, 'X' as var2
    UNION ALL
    SELECT 'A' as var1, NULL as var2
    UNION ALL
    SELECT 'B' as var1, 'X' as var2
    UNION ALL
    SELECT 'B' as var1, 'Y' as var2
    UNION ALL
    SELECT 'B' as var1, 'X' as var2
)
SELECT
    var1
    , list(var2) as agg_var2_1
    , list(var2 ORDER BY var2 nulls first) as agg_var2_2
    , list(DISTINCT var2) as agg_var2_3
    , list(DISTINCT var2 ORDER BY var2 nulls last) as agg_var2_4
FROM SAMPLE_DATA
GROUP BY ALL
ORDER BY var1
;

┌─────────┬────────────┬────────────┬────────────┬────────────┐
│  var1   │ agg_var2_1 │ agg_var2_2 │ agg_var2_3 │ agg_var2_4 │
│ varcharvarchar[]  │ varchar[]  │ varchar[]  │ varchar[]  │
├─────────┼────────────┼────────────┼────────────┼────────────┤
│ A       │ [X, NULL]  │ [NULL, X]  │ [X, NULL]  │ [X, NULL]  │
│ B       │ [X, Y, X]  │ [X, X, Y]  │ [X, Y]     │ [X, Y]     │
└─────────┴────────────┴────────────┴────────────┴────────────┘

@b41sh
Copy link
Member

b41sh commented Mar 22, 2023

@wangjili8417 Since we need to use it, I implemented the list function first, and you can continue to do the list with the order by inner values.

@kesavkolla
Copy link

Can we also add lambda functions to list? That way we can do filters on lists. I think this lambda type thing will probably can help in both filter and map.

functions like list_filter, array_filter, list_any_value from duckdb.

@b41sh
Copy link
Member

b41sh commented Mar 26, 2023

Can we also add lambda functions to list? That way we can do filters on lists. I think this lambda type thing will probably can help in both filter and map.

functions like list_filter, array_filter, list_any_value from duckdb.

Yes, we plan to add lambda expressions to the array function in issue #7931, but the priority is low and we will add them in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: feature good first issue Category: good first issue
Projects
None yet
Development

No branches or pull requests

5 participants