Member since
09-27-2017
11
Posts
1
Kudos Received
0
Solutions
11-17-2017
02:26 PM
@rakesh chow Use PutSQL processor instead of ExecuteSQL processor, PutSQL processor does inserts and updates to mysql. You can have refer below links https://community.hortonworks.com/articles/91849/design-nifi-flow-for-using-putsql-processor-to-per.html https://community.hortonworks.com/questions/54538/nifi-ingesting-a-file-from-sftp-and-insert-into-my.html
... View more
10-18-2017
03:03 PM
Hi @rakesh chow, as ExecuteScripts are experimental in NiFi but you can acheive same results by using another processors as follows. 1.EvaluateJsonPath //Extract all the contents to attributes
2.UpdateAttribute //Update time stamps attributes with new format(yyyy-mm-dd hh...etc)
3.AttributesToJson //Recreate Json content by specifying all the attributes EvaluateJsonPath configs:- My input sample content is {
"ID":"1",
"CID":"1",
"DiscoveredTime":"Mon Sep 11 19:56:13 IST 2017",
"LastDiscoveredTime":"Mon Oct 09 23:38:55 IST 2017"
} in eval json processor extract all the contents of the flowfile to the attributes of flowfile by changing Destination property to flowfile-attribute and add new properties by clicking + sign at right corner. ID $.ID DiscoveredTime $.DiscoveredTime CId
$.CId LastDiscoveredTime
$.LastDiscoveredTime so i have extracted all the content of ff as attributes of ff, in your case you need to add all your json content keys of contents here and this processor keeps all the values of content to attributes. Config Screenshot:- UpdateAttribute Processor Configs:- This processor will helps to update the attributes on the fly we are changing our DiscoveredTime,LastDiscoveredTime attributes on the fly. add new properties 1.DiscoveredTime ${DiscoveredTime:toDate('EEE MMM dd HH:mm:ss ZZZ yyyy'):toNumber():plus(21600000):format("yyyy-MM-dd HH:mm:ss.SSS")} in this expression we are checking which timezone it is and converting that to number and adding 6 hrs(i think you don't need to do :plus(21600000)), after that i'm converting to yyyy-MM-dd HH:mm:ss.SSS format Your expression probably will be ${DiscoveredTime:toDate('EEE MMM dd HH:mm:ss ZZZ yyyy'):toNumber():format("yyyy-MM-dd HH:mm:ss.SSS")} 2. add new property for LastDiscoveredTime ${LastDiscoveredTime:toDate('EEE MMM dd HH:mm:ss ZZZ yyyy'):toNumber():plus(21600000):format("yyyy-MM-dd HH:mm:ss.SSS")} Your expression:- ${LastDiscoveredTime:toDate('EEE MMM dd HH:mm:ss ZZZ yyyy'):toNumber():format("yyyy-MM-dd HH:mm:ss.SSS")} Configs:- AttributesToJson Processor:- in Attributes list property add all the available attributes it will prepare a json messages with the attributes that you have mentioned here. ID,CID,DiscoveredTime,LastDiscoveredTime Change Destination property to flowfile-content Configs:- Input:- {
"ID":"1",
"CID":"1",
"DiscoveredTime":"Mon Sep 11 19:56:13 IST 2017",
"LastDiscoveredTime":"Mon Oct 09 23:38:55 IST 2017"
} Output:- {
"ID" : "1",
"LastDiscoveredTime" : "2017-10-09 23:38:55.000",
"DiscoveredTime" : "2017-09-11 19:56:13.000",
"CID" : ""
} In your case you need to mention all your attributes in attributes to json processor and it will prepare new json content with all your attributes, if you left this property as empty then all the attributes associated with the ff will be part of your json content. Flow Screenshot:-
... View more