Skip to main content
Chakkara
Silver ⭐️⭐️
July 6, 2021
Solved

Handle date column with spaces in nifi

I am trying to  format the date field which contains spaces in replace text processor from a csv file. 

 

Got the error as it is unable to parse the date column which is spaces for first record. Please let me know how to handle this

 

Error message: Replace text failed to process session due to Cannot parse attribute value as a date; date format ddMMyyyy; attribute value:      

 

Input csv:

 

1,        , 123

2,02091997,234

 

Search value : (.{1}),(.{8}), (.{3}) 

Replacement value : $1, ${'$2':toDate("ddMMyyyy") :format("yyyy-MM-dd HH:mm:ss.SSS") }, $3

Replacement strategy : Regex Replace

Evaluation mode : Entire Text

 

aakulov
aakulovAnswer
Platinum ⭐️
July 7, 2021

Hi @Chakkara ,

 

What would you like the parser to do when it encounters an invalid date value? If this is a recurring problem, where multiple lines in your file have the same number of spaces to indicate missing date, then you can use ifElse in your replacement value command (something like this). 

 

 

Hope that helps,

Alex

2 replies

aakulov
Platinum ⭐️
aakulovAnswer
Platinum ⭐️
July 7, 2021

Hi @Chakkara ,

 

What would you like the parser to do when it encounters an invalid date value? If this is a recurring problem, where multiple lines in your file have the same number of spaces to indicate missing date, then you can use ifElse in your replacement value command (something like this). 

 

 

Hope that helps,

Alex

Translate
Chakkara
ChakkaraAuthor
Silver ⭐️⭐️
July 7, 2021

Thanks for the response and it works!! 

Translate