Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

add plus minutes to a date time value with the jolt transform json processor

avatar
Contributor

 

 

Hi all,

I want to add 15 minutes to a date-time value using the transform json processor, but with my configuration I get the same value as before. I expect for the end field to have 15 minutes more than the start field. Does anyone have any idea?

 

[ {
  "store_id" : 1001,
  "date" : 20220918,
  "start" : "2022-09-18 00:15:00",
  "end" : "2022-09-18 00:15:00",
  "out" : 0
}, {
  "store_id" : 1001,
  "date" : 20220918,
  "start" : "2022-09-18 00:30:00",
  "end" : "2022-09-18 00:30:00",
  "out" : 0
}]

 

My jolt Specification

 

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
     "*":{
           "end": "=${end:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
      }
    }
  }
]

 

The result is the same

 

 

[ {
  "store_id" : 1001,
  "date" : 20220918,
  "start" : "2022-09-18 00:15:00",
  "end" : "2022-09-18 00:15:00",
  "out" : 0
}, {
  "store_id" : 1001,
  "date" : 20220918,
  "start" : "2022-09-18 00:30:00",
  "end" : "2022-09-18 00:30:00",
  "out" : 0
}

 

 

 

2 ACCEPTED SOLUTIONS

avatar
Super Guru

Hi,

I dont think the following formula is correct:

 

      "end": "=${end:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"

 

You are trying to use Expression Language in the Jolt Expression and that is not going to work. Also the expression ${end...} assumes that you have an attribute called "end" which I don think its the case. I think what you need to do is the following (assuming you will need to split each json record into its own flowfile):

 

1- SplitJson

2- Use EvaluateJsonPath to extract the "end" date as an attribute

3- Use JoltTransformationJson  where you utilize the attribute from above to do the addition as follows:

 

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
     
           "end": "${end_attribute:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
     
    }
  }
]

 

Hope that helps, if it does please accept solution.

 

View solution in original post

avatar
Contributor

Hi @SAMSAL,

thanks, i have try this out and it works. I thought you can directly edit the value of the JSON file. Now I have to merge all split JSON files into one again

View solution in original post

2 REPLIES 2

avatar
Super Guru

Hi,

I dont think the following formula is correct:

 

      "end": "=${end:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"

 

You are trying to use Expression Language in the Jolt Expression and that is not going to work. Also the expression ${end...} assumes that you have an attribute called "end" which I don think its the case. I think what you need to do is the following (assuming you will need to split each json record into its own flowfile):

 

1- SplitJson

2- Use EvaluateJsonPath to extract the "end" date as an attribute

3- Use JoltTransformationJson  where you utilize the attribute from above to do the addition as follows:

 

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
     
           "end": "${end_attribute:toDate('yyyy-MM-dd HH:mm:ss'):toNumber():plus(900000):format('yyyy-MM-dd HH:mm:ss')}"
     
    }
  }
]

 

Hope that helps, if it does please accept solution.

 

avatar
Contributor

Hi @SAMSAL,

thanks, i have try this out and it works. I thought you can directly edit the value of the JSON file. Now I have to merge all split JSON files into one again