0

In Cassandra to get the aggregated data like sum,avg,min,max we use a query like,:

SELECT avg(race_points) FROM cycling.cyclist_points WHERE id=e3b19ec4-774a-4d1c-9e5a-decec1e30aac;

But, in cqlengine how is this be done.? I have columns with name and age. I want to get the average age from the list. Kindly help me to retrieve avg(age) in cqlengine.

Ashraful Islam
  • 12,470
  • 3
  • 32
  • 53

1 Answers1

0

Could not find any aggregate in cql engine, we need to iterate the queryset one after the other, use values_list to reduce memory usage for big queryset.

live_data = list(LiveStats.objects.all().values_list('cpuinfo', 'memused'))                                                                                                      
total_count = len(live_data)
        if total_count > 0:
            cpu_info, mem_used = 0, 0
            for live in live_data:
                cpu_info += live[0]
                mem_used += live[1]
            avg_cpu = cpu_info / total_count
            avg_memory = mem_used / total_count
Thomas John
  • 2,138
  • 2
  • 22
  • 38