Help me in writing aggregation (groupBy,orderBy) Lua script for Aerospike

I have a following lua script that groups the data with ‘sensorType’ and print ‘clientId’ in each group of ‘sensorType’.

function orderby(touples)
  local function mapper(rec)
  local element = map()
    element["clientId"] = rec["clientId"];
    element["sensorType"] = rec["sensorType"]
  return element
end

local function accumulate(currentList, nextElement)
   local sensorType = nextElement["sensorType"]
   local clientId = nextElement["clientId"]
     if currentList[sensorType] == nil then
         currentList[sensorType] = list()
     end
    
    list.append(currentList[sensorType],clientId)
  
  return currentList
end
local function mymerge(a, b)
   return list.merge(a, b)
end
local function reducer(this, that)
   return map.merge(this, that, mymerge)
end
return touples:map(mapper):aggregate(map{}, accumulate):reduce(reducer)
end

I also want groupBy with clientId like ‘groupBy sensorType, clientId’. Please help me to prepare a script that can accept any number of columns for groupBy clause and do grouping with that.

currently my result is-

{ BEACON: [ 'client2', 'client2', 'client2', 'client2', 'client2', 'client2' ],
  SSID: 
   [ '100',
     '100',
     '100',
     '100',
     '100',
     '100',
     '100',
     '102',
     '100',
     '100',
     '101',
     '100' ] }

I want the result in this format -

{ BEACON: [ ‘client2’ ], SSID: [ ‘100’, ‘102’, ‘101’, ] }