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!

How to validate/ignore optional value while validating it using 'Validate CSV' processor in Apache NiFi?

avatar
New Contributor

I'm new to Apache Nifi Community and I got stuck at one point - please help me for the below problem :

In 'Validate CSV' processor I'm giving below schema(schema_used) to validate the CSV input. But, processor is showing error(err_screenshot).

Validate CSV -

AidenMartin_0-1709718794627.png

Schema_Used - StrNotNullOrEmpty(), ParseDate("MM/dd/yyyy"), StrNotNullOrEmpty(), StrNotNullOrEmpty(), Optional(), StrNotNullOrEmpty(), StrNotNullOrEmpty(), StrNotNullOrEmpty(), StrNotNullOrEmpty(), Optional(), Optional(), StrNotNullOrEmpty()

The above schema is showing below error -

err_screenshot -

AidenMartin_1-1709718875207.png

Note: The Schema is working totally fine, if I remove 'Optional()'.

Problem - Please tell me how can I use 'Validate CSV' processor in Apache Nifi and validate Mandatory/Optional Fields of CSV. Also, suggest/share any script(groovy/python) if that can validate the CSV.

1 ACCEPTED SOLUTION

avatar
Super Guru

Hi @AidenMartin ,

According to the documentation of the validate csv apply processors, the Optional has to take  a type parameter :

"

...

Schema property: Null, ParseDate("dd/MM/yyyy"), Optional(ParseDouble())
Meaning: the input CSV has three columns, the first one can be null and has no specification, the second one must be a date formatted as expected, and the third one must a double or null (no value).

...

"

If you are not sure of the data type then just use Null instead of Optional, which means the value can be provided or not.

reference: https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.23.2/org.apach...

If you find this is helpful please accept solution.

 

View solution in original post

1 REPLY 1

avatar
Super Guru

Hi @AidenMartin ,

According to the documentation of the validate csv apply processors, the Optional has to take  a type parameter :

"

...

Schema property: Null, ParseDate("dd/MM/yyyy"), Optional(ParseDouble())
Meaning: the input CSV has three columns, the first one can be null and has no specification, the second one must be a date formatted as expected, and the third one must a double or null (no value).

...

"

If you are not sure of the data type then just use Null instead of Optional, which means the value can be provided or not.

reference: https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.23.2/org.apach...

If you find this is helpful please accept solution.