I have a use case, where i need to generate timestamp in Epoch UTC format till seconds 1662371646, and perform Substract operation for generate one minute ago time in same format.
below is my Jolt Spec :
[
{
"operation": "default",
"spec": {
"currenttime": "${now():toNumber()}"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"timeOneMinu": "=Subtract(@(1,currenttime),60)"
}
}
]
Expected Output
{
"currenttime": "1662372281",
"timeOneMinu": "1662372221"
}
Please suggest, How we can do this.
CodePudding user response:
There's no function called Subtract but intSum, but prefer using it for an integer with less than ten digits. Split by using substring function in order to do this, and then remove extra created attributes such as
[
{
"operation": "default",
"spec": {
"currenttime": "${now():toNumber()}"
}
},
{
"operation": "modify-overwrite-beta",
"spec": {
"ct1": "=substring(@(1,currenttime),0,4)",
"ct2_": "=substring(@(1,currenttime),4,13)",
"ct2": "=intSum(-60,@(1,ct2_))",
"timeOneMinute": "=concat(@(1,ct1),@(1,ct2))"
}
},
{
"operation": "remove",
"spec": {
"ct*": ""
}
}
]
the demo on apache ni-fi is :