Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

NiFi processor: Convert string(datetime format) to long(unix_timestamp) in CSV field

avatar
Expert Contributor

Hello,

Is there a processor help with converting a string(Datetime format: 2017-01-18 13:28:17) to long(133434444545) in a csv field?

Thanks.

1 ACCEPTED SOLUTION

avatar
Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login
5 REPLIES 5

avatar
Guru
hide-solution

This problem has been solved!

Want to get a detailed solution you have to login/registered on the community

Register/Login

avatar
Expert Contributor

@Sonu Sahi

Thank you for your response.

${now():toNumber():format('yyyy-MM-dd')}

It seems above expression works for attributes.

How to use it to convert a column in csv file?

Thanks.

avatar
Guru

Hi @Alvin Jin

You could use a combination of ExtractText and ReplaceText with some RegEx, though it might be a bit tedious. There is a good example here with screens that you can use as a guide:

https://community.hortonworks.com/articles/66861/nifi-etl-removing-columns-filtering-rows-changing.h...

avatar
Master Guru

As of NiFi 1.3.0, you can use UpdateRecord for this. If your incoming field name is "createdOn", you can add a user-defined property named "/createdOn" whose value is the following:

${field.value:toDate('yyyy-mm-dd HH:mm:ss.SSS'):toNumber()}

Note that you may need to change the type of createdOn from String (in the Reader's schema) to Long (in the Writer's schema).

avatar

How would I use this with a literal letter in my timestamp format? My timestamp format looks like this:

yyyy-mm-dd'T'HH:mm:ss.SSS