Hi,
I need to group my result based on the accountNumber and sort them on the basis of due date. I have written a udf that is grouping correctly, but i am not able to sort on the basis of duedate. Can anyone help me in writing correct udf which performs both the operations.
Udf :
function getData(touples)
local function mapper(rec)
local element = map()
element["id"] = rec["accountNumber"];
element['doc'] = map()
element['doc']["accountNumber"] = rec["accountNumber"]
element['doc']["clientCode"] = rec["clientCode"]
element['doc']["amountDue"] = rec["amountDue"];
element['doc']["fileName"] = rec["fileName"];
element['doc']["dueDate"] = rec["dueDate"];
element['doc']["dueDateTimstamp"] = rec["dueDateTimstamp"];
if rec['authToken1'] then
element['doc']['authToken1'] = rec['authToken1'];
end
if rec['authToken2'] then
element['doc']['authToken2'] = rec['authToken2'];
end
if rec['authToken3'] then
element['doc']['authToken3'] = rec['authToken3'];
end
return element
end
local function accumulate(currentList, nextElement)
local sensorType = nextElement["accountNumber"]
local element = map();
element = mapper(nextElement);
if currentList[sensorType] == nil then
currentList[sensorType] = list()
end
list.append(currentList[sensorType], element)
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:aggregate(map{}, accumulate) : reduce(reducer)
end
Result I am getting :
[
{
"key": null,
"bins": {
"1-319": [
{
"doc": {
"amountDue": 1313,
"fileName": null,
"dueDate": "04-JUN-20",
"accountNumber": "******",
"dueDateTimstamp": null,
"clientCode": "a"
},
"id": "1-319"
},
{
"doc": {
"amountDue": 11130,
"fileName": null,
"dueDate": "08-JUN-20",
"accountNumber": "1-319",
"dueDateTimstamp": null,
"clientCode": "a"
},
"id": "1-319"
},
{
"doc": {
"amountDue": 1113,
"fileName": null,
"dueDate": "05-JUN-20",
"accountNumber": "1-319",
"dueDateTimstamp": null,
"clientCode": "a"
},
"id": "1-319"
}
],
"2-219": [
{
"doc": {
"amountDue": 161130,
"fileName": null,
"dueDate": "04-JUN-20",
"accountNumber": "2-219",
"dueDateTimstamp": null,
"clientCode": "a"
},
"id": "919911996-219"
},
{
"doc": {
"amountDue": 11130,
"fileName": null,
"dueDate": "08-JUN-20",
"accountNumber": "2-219",
"dueDateTimstamp": null,
"clientCode": "q"
},
"id": "2-219"
}
]
}
}
]
I also want to sort it on the basis of dueDate