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

support of aggregation and grouping of array fields #3394

Closed
eshubin opened this issue Mar 31, 2016 · 5 comments
Closed

support of aggregation and grouping of array fields #3394

eshubin opened this issue Mar 31, 2016 · 5 comments

Comments

@eshubin
Copy link

eshubin commented Mar 31, 2016

I have a table with array field. When I try to count records where this field is not null, I get an error

SQLActionException[Cannot select non-indexed column 'signals' within grouping or aggregations]

the query is:

select count(signals) from devices;


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

@joemoe
Copy link
Contributor

joemoe commented Apr 1, 2016

hi @eshubin, you can rewrite this query to SELECT COUNT(*) FROM devices WHERE signals IS NOT NULL;. another possiblity
as objects are not indexed you need to access a specific field of an object.
e.g. SELECT COUNT(signals[0]) FROM devices;

@joemoe joemoe added the question label Apr 1, 2016
@eshubin
Copy link
Author

eshubin commented Apr 1, 2016

Well, basically I have a custom aggregation function, which needs to accept array field as an argument, it causes the same error.
Wanted to simplify the ticket description.

@joemoe
Copy link
Contributor

joemoe commented Apr 1, 2016

ok. we already have this on our backlog. i upvoted it.

@joemoe joemoe added enhancement Enhancement that doesn't fit into a more specific feature label. Try avoid using this and removed question labels Apr 1, 2016
@saulius
Copy link

saulius commented May 15, 2016

This would be great addition, looking forward to it! We would like to give crate a serious try but support for grouping and aggregating on array columns is one of the main requirements in our BI workflow.

@mfussenegger mfussenegger added feature: sql: aggregations and removed enhancement Enhancement that doesn't fit into a more specific feature label. Try avoid using this labels Feb 7, 2018
@mfussenegger
Copy link
Member

Support for this has been implemented:

cr8 run-crate 2.2.x -- @crash <<EOF
    create table t (x int, signals array(int));
    insert into t (x, signals) values (1, [1, 2]), (2, [3, 4]), (3, null);
    refresh table t;
    select count(signals) from t;
EOF
CREATE OK, 1 row affected  (0.273 sec)
INSERT OK, 3 rows affected  (0.082 sec)
REFRESH OK, 1 row affected  (0.101 sec)
+----------------+
| count(signals) |
+----------------+
|              2 |
+----------------+
SELECT 1 row in set (0.061 sec)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants