Suppose that I have a collection with schema [:col1, :col2, :col3].
What's the best way to do the equivalent of
SELECT COUNT(DISTINCT(col2)) FROM table GROUP BY col1;
Thanks.
Something like this should work for count distinct (though I agree a built-in would be nice):
scratch :b_vals, [:grp, :vals]
# collect the distinct vals in a hash for each group
b_vals <= t.reduce({}) { |memo,o| memo[o.a] ||= {}; memo[o.a][o.d]=true; memo }
# count the distinct vals
b <= b_vals {|t| [t.grp, t.vals.length]}