Apache Pig – Java UDF to Validate Date Format

java pig udf

This Java UDF checks if a date string matches a specific expected date format. In this scenario, the “MM/dd/yyyy” format is expected, and it will return true/false if it matches the criteria.

Dates could be tricky sometimes. This UDF could help you process all the date fields as string and then later you can FILTER on your Pig Script the records where only TRUE is returned.

if you want to check the unit testing for this UDF, please click here.

Java UDF to Validate Date Format

Please remember that once your process enters the UDF, you can fully use all the date manipulation capabilities that you use in Java. This is why UDFs are so powerful!

This UDF could be modified to accept another parameter in case you need to specify the date format on the PIG script. However, I am assuming you will only need to use one date format that you used across your company or project.

Here is a collection of UDFs