Execute a "like SQL" GROUP BY on Cassandra

#1

Hi, I need to execute in Cassandra a query like sql GROUP BY.

I’m trying with this commands

spec={projection:"statusCode, count(id)", group:"statusCode",filter:"parent.id=='XXXX'",limit:-1}

c3Grid(PointMeasurement.evaluate(spec))

But I received the error
group in evaluate spec for CassandraConnection is not yet supported

How can I solve this problem? I want to group and count the number of record related to a particular parent.id by the statusCode value.

Thanks,
Laura

0 Likes

#2

Grouping on Cassandra types like PointMeasurement is not supported, see Evaluate with group on timeComponent

Try the following javascript example instead:

var pms = PointMeasurement.fetch({
  filter: "parent.id=='XXXX'",
  limit:-1,
  include: 'statusCode'}).at('objs');
var grouped = _.groupBy(pms, 'statusCode');
var countByStatus = Object.keys(grouped).reduce(function(dict, status) {
  dict[status] = grouped[status].length;
  return dict;
}, {});
1 Like

#3

Thanks! In this way I’m able to solve my problem :slight_smile:

0 Likes