In this tutorial you will read the modified films file and validate the genres field.
rownum
. Genres
as the Field to evaluate, and type genres_ok
as the Result Fieldname. [A-Za-zs-]*(|[A-Za-zs-]*)*
. String
constant named err_code
with value GEN_INV
and a String
constant named err_desc
with value Invalid list of genres
. ${LABSOUTPUT}/films_err.txt
file, with the fields rownum, err_code
, and err_desc
. ${LABSOUTPUT}/films_ok.txt
file, with the fields film, Year, Genres, Director
, and Actors
. films_ok.txt
file. Send false data to the other stream. films_err.txt
file looks like the following:rownum;err_code;err_desc 12;GEN_INV;Invalid list of genres 18;GEN_INV;Invalid list of genres 20;GEN_INV;Invalid list of genres 21;GEN_INV;Invalid list of genres 22;GEN_INV;Invalid list of genres 33;GEN_INV;Invalid list of genres 34;GEN_INV;Invalid list of genres ...
The films_ok.txt
file looks like this:
film;Year;Genres;Director;Actors Persepolis;2007;Animation | Comedy | Drama | History;Vincent Paronnaud, Marjane Satrapi;Chiara Mastroianni, Catherine Deneuve, Danielle Darrieux Trois couleurs - Rouge;1994;Drama;Krzysztof Kieslowski;Irène Jacob, Jean-Louis Trintignant, Frédérique Feder, Jean-Pierre Lorit, Samuel Le Bihan Les Misérables;1933;Drama | History;Raymond Bernard; ...
You read the films file and checked that the Genres
field was a list of strings separated by |
. You created two files:
Genres
field. Note that the rownum
field you added when you read the file is used here for identifying the wrong lines.In order to check the validity of the Genres
field, you used a regular expression. The expression you typed accepts any combination of characters, spaces, or hyphens separated by a pipe. The *
symbol allows empty genres as well. For a detailed explanation of regular expressions, please refer to Chapter 2.
As said, you would validate data mainly for two reasons:
For example, consider some of the sample data from previous chapters:
If your data doesn't meet these requirements, it is possible that you don't have errors but you will still be working with invalid data.
In the last tutorial you just validated one of the fields. If you want to validate more than one field, you have a specific step that simplifies that work: The Data Validator.
3.12.163.180