Skip to content
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

Trouble getting fancy with ARRAY_AGG (DISTINCT ARRAY_AGG) #6743

Closed
bellwether-softworks opened this issue Jun 22, 2023 · 5 comments · Fixed by #7385
Closed

Trouble getting fancy with ARRAY_AGG (DISTINCT ARRAY_AGG) #6743

bellwether-softworks opened this issue Jun 22, 2023 · 5 comments · Fixed by #7385
Labels
bug Something isn't working

Comments

@bellwether-softworks
Copy link

Describe the bug

ARRAY_AGG usage in SQL results in an error when used in conjunction with DISTINCT parameter alongside another aggregate field.

To Reproduce

  1. Establish example data:
CREATE TABLE example(id INT, parent_id INT, tag VARCHAR) AS VALUES
    (1, 0, 'bob'),
    (2, 0, 'cat'),
    (3, 1, 'tom'),
    (4, 1, 'cat'),
    (5, 1, 'tom');
  1. Execute query using ARRAY_AGG and DISTINCT parameter:
SELECT
        parent_id,
        COUNT(id) AS count_of,
        ARRAY_AGG(DISTINCT tag) AS tags
    FROM example
    GROUP BY parent_id;

Executing the above results in the following message:

ArrowError(ExternalError(Internal("Inconsistent types in ScalarValue::iter_to_array. Expected Utf8, got List([tom,cat])")))

Expected behavior

Desired output should be similar to the following:

parent_id count_of tags
1 3 [tom, cat]
0 2 [bob, cat]

Additional context

Omitting either the COUNT field, or the DISTINCT clause in ARRAY_AGG, allows the query to complete successfully.

The above was initially discovered in v17.0.0 and verified to still be presenting in v26.0.0.

@bellwether-softworks bellwether-softworks added the bug Something isn't working label Jun 22, 2023
@alamb alamb changed the title Trouble getting fancy with ARRAY_AGG Trouble getting fancy with ARRAY_AGG (DISTINCT ARRAY_AGG) Jun 23, 2023
@alamb
Copy link
Contributor

alamb commented Jun 23, 2023

I am confusing where the sv defined.

In the code you referenced this is basically the catch all meaning "if the type doesn't match one of the other branches"

@alamb
Copy link
Contributor

alamb commented Jun 23, 2023

Thanks for the report @bellwether-softworks -- I added this to #2326

@parkma99
Copy link
Contributor

In the code you referenced this is basically the catch all meaning "if the type doesn't match one of the other branches"

Sorry I make a stupid question.😂

@alamb
Copy link
Contributor

alamb commented Jun 24, 2023

Sorry I make a stupid question.😂

Not at all -- we are all learning here together!

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants