ComposantsComponents › Traitement › ChampsProcessing › Fields
Découpe une colonne de texte en plusieurs colonnes avec une expression régulière Java : chaque groupe entre parenthèses remplit une colonne de sortie, dans l'ordre, converti dans son type. L'expression est cherchée dans la valeur, et chaque correspondance donne une ligne de sortie. Une valeur qui ne correspond pas, ou dont un groupe ne se convertit pas, peut partir par un lien Reject avec son message d'erreur. Splits a text column into several columns with a Java regular expression: each group between parentheses fills an output column, in order, converted to its type. The expression is searched in the value, and each match gives an output row. A value that does not match, or whose group does not convert, can leave through a Reject link with its error message.
EntréeInput
Main un fluxone flow
SortieOutput
Main un flux, obligatoire : une ligne par correspondanceone flow, required: one row per match
Reject facultatif, Arrêter en cas d'erreur décoché : lignes sans correspondance ou en erreuroptional, Die on error unchecked: rows without a match or in error
Déclencheurs en sortieOutput triggers
On Component Ok On Component Error Run if
L'expression est compilée une fois, au début. Pour chaque ligne entrante, elle est cherchée dans la colonne choisie ; chaque correspondance produit une ligne de sortie : les colonnes recopiées de l'entrée, puis les groupes. Une valeur nulle ne produit rien. The expression is compiled once, at the start. For each incoming row, it is searched in the chosen column; each match produces an output row: the columns copied from the input, then the groups. A null value produces nothing.
( ) par colonne à remplir.
Choose the Field to split, then write the Regex: a Java string, backslashes doubled, with one ( ) group per column to fill.
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file.
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Champ à scinderField to splitFIELD | 1re colonne d'entrée1st input column | ToujoursAlways | La colonne du flux entrant où chercher l'expression, une colonne String. Si elle est nulle, la ligne ne produit rien, pas même un rejet. The column of the incoming flow where the expression is searched, a String column. If it is null, the row produces nothing, not even a reject. |
| RegexREGEX | "^\\[(\\w+)\\]([^\\[]+)\\[priority:\\s*(\\w+)\\]\\s*\\[place:\\s*([^\\]]+)\\]" |
ToujoursAlways |
L'expression régulière Java, écrite comme une chaîne Java (une expression de contexte est possible). Elle est cherchée dans la valeur (find), pas comparée à toute la valeur : sans ^ et $, elle peut correspondre à un morceau, et à plusieurs endroits (une ligne de sortie par correspondance). Le groupe 1 va à la première colonne à remplir, le 2 à la deuxième… Un texte sous le champ rappelle ce que reconnaît l'expression par défaut : [Monday] meeting with John [priority: high] [place: office].
The Java regular expression, written as a Java string (a context expression is possible). It is searched in the value (find), not compared to the whole value: without ^ and $, it can match a piece, and at several places (one output row per match). Group 1 goes to the first column to fill, group 2 to the second… A text under the field recalls what the default expression matches: [Monday] meeting with John [priority: high] [place: office].
|
| SchémaSchemaSCHEMA | videempty | ToujoursAlways |
Les colonnes de sortie. Celles qui ont le nom d'une colonne d'entrée sont recopiées de l'entrée, même le champ à scinder ; les autres sont les colonnes à remplir, qui reçoivent les groupes dans leur ordre. Un groupe String est pris tel quel ; un autre type est converti (avec le modèle de date de la colonne pour une Date). Un groupe vide, ou absent de l'expression, donne "" à une colonne String, la valeur par défaut de la colonne à une autre (0 pour un int, null pour un type nullable).
The output columns. Those with the name of an input column are copied from the input, even the field to split; the others are the columns to fill, which get the groups in their order. A String group is taken as is; another type is converted (with the date pattern of the column for a Date). An empty group, or one missing from the expression, gives "" to a String column, the default value of the column to another one (0 for an int, null for a nullable type).
|
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Arrêter en cas d'erreurDie on errorDIE_ON_ERROR | OuiYes | ToujoursAlways | Coché : un groupe qui ne se convertit pas (ou l'erreur de Vérifier la structure) arrête le job. Décoché : la correspondance en erreur part par le lien Reject, ou, sans lui, son message est écrit sur la sortie d'erreur et elle est perdue ; le job continue. Le lien Reject n'est proposé que décoché. Une valeur sans correspondance n'est pas une erreur : sans lien Reject, elle est perdue sans message, coché ou non. Checked: a group that does not convert (or the error of Check each row structure) stops the job. Unchecked: the match in error leaves through the Reject link, or, without it, its message is written on the error output and it is lost; the job goes on. The Reject link is only offered when unchecked. A value without a match is not an error: without a Reject link, it is lost without a message, checked or not. |
| Vérifier la structure de chaque ligne par rapport au schémaCheck each row structure against schemaCHECK_FIELDS_NUM | NonNo | ToujoursAlways |
Compare le nombre de groupes de l'expression à celui des colonnes à remplir : moins de groupes, erreur Column(s) missing ; plus, Too many columns. Le compte porte sur l'expression, pas sur la valeur : toutes les correspondances sont en erreur, ou aucune. Coché, les dates sont aussi lues strictement : sans la case, 32-01-2020 devient le 1er février (voir les exemples).
Compares the number of groups of the expression to the number of columns to fill: fewer groups, Column(s) missing error; more, Too many columns. The count is about the expression, not the value: all the matches are in error, or none. Checked, dates are also read strictly: without the box, 32-01-2020 becomes February 1st (see the examples).
|
Son schéma est celui de la sortie, suivi de deux colonnes ajoutées par le Studio, errorCode et errorMessage.
Its schema is the output one, followed by two columns added by the Studio, errorCode and errorMessage.
errorMessage vaut <valeur> doesn't match regex:<expression>.
Without a match: only the columns copied from the input are filled; errorMessage is <value> doesn't match regex:<expression>.
errorMessage = le message de Java suivi de - Line: n (voir Pièges).
Conversion error: the columns filled before the error, and errorMessage = the Java message followed by - Line: n (see Pitfalls).
errorCode n'est jamais rempli.
errorCode is never filled.
Le composant ne déclare pas de variable globale. Le code généré range le message de la dernière erreur de conversion dans tExtractRegexFields_1_ERROR_MESSAGE ; une valeur sans correspondance ne la remplit pas.
The component declares no global variable. The generated code stores the message of the last conversion error in tExtractRegexFields_1_ERROR_MESSAGE; a value without a match does not fill it.
((String) globalMap.get("tExtractRegexFields_1_ERROR_MESSAGE"))
Un tFixedFlowInput envoie les lignes au tExtractRegexFields, suivi d'un tLogRow ; avec un lien Reject, il mène à tLogRow_2 et les deux tLogRow affichent leur nom unique. Un tJava relié par On Subjob Ok affiche ERROR_MESSAGE : System.out.println("ERROR_MESSAGE=" + globalMap.get("tExtractRegexFields_1_ERROR_MESSAGE"));. Sorties copiées depuis une exécution du job.
A tFixedFlowInput sends the rows to the tExtractRegexFields, followed by a tLogRow; with a Reject link, it leads to tLogRow_2 and both tLogRow print their unique name. A tJava connected with On Subjob Ok prints ERROR_MESSAGE: System.out.println("ERROR_MESSAGE=" + globalMap.get("tExtractRegexFields_1_ERROR_MESSAGE"));. Outputs copied from a run of the job.
EntréeInput
| idInteger | lineString |
|---|---|
| 1 | [Monday] meeting with John [priority: high] [place: office] |
| 2 | [Friday] diner with kids [priority: highest] [place: home] |
| 3 | Saturday: rest |
| 4 | null |
RéglagesSettings
Champ à scinder : line ; Regex par défaut (quatre groupes). Schéma de sortie : id (recopiée de l'entrée), puis day, subject, priority, place, String, qui reçoivent les groupes 1 à 4.
Field to split: line; default Regex (four groups). Output schema: id (copied from the input), then day, subject, priority, place, String, which get groups 1 to 4.
Arrêter en cas d'erreur coché, pas de lien Reject. Les deux premières lignes sont découpées ; le groupe 2 garde ses espaces. La ligne 3, sans correspondance, et la ligne 4, nulle, disparaissent sans message, et le job se termine normalement. Die on error checked, no Reject link. The first two rows are split; group 2 keeps its spaces. Row 3, without a match, and row 4, null, disappear without a message, and the job ends normally.
1|Monday| meeting with John |high|office 2|Friday| diner with kids |highest|home ERROR_MESSAGE=null
Arrêter en cas d'erreur décoché, lien Reject vers tLogRow_2 (schéma de sortie + errorCode, errorMessage). La ligne 3 y part avec son id ; la ligne 4, nulle, n'apparaît nulle part.
Die on error unchecked, Reject link to tLogRow_2 (output schema + errorCode, errorMessage). Row 3 leaves there with its id; row 4, null, appears nowhere.
[tLogRow_1] 1|Monday| meeting with John |high|office [tLogRow_1] 2|Friday| diner with kids |highest|home [tLogRow_2] 3||||||Saturday: rest doesn't match regex:^\[(\w+)\]([^\[]+)\[priority:\s*(\w+)\]\s*\[place:\s*([^\]]+)\] ERROR_MESSAGE=null
Lignes 1 et 2, réglages par défaut, schéma de sortie id, day, line, subject, priority, place. line existe dans l'entrée : elle est recopiée, et les groupes sautent cette colonne.
Rows 1 and 2, default settings, output schema id, day, line, subject, priority, place. line exists in the input: it is copied, and the groups skip this column.
1|Monday|[Monday] meeting with John [priority: high] [place: office]| meeting with John |high|office 2|Friday|[Friday] diner with kids [priority: highest] [place: home]| diner with kids |highest|home
EntréeInput
| idInteger | lineString |
|---|---|
| 1 | a=1, b=22 |
| 2 | c=x, d=4 |
| 3 | e=5 |
RéglagesSettings
Regex : "(\\w+)=(\\w+)", sans ^ ni $. Schéma de sortie : id, key (String), value (Integer). Chaque paire « clé=valeur » est une correspondance, donc une ligne ; x ne se convertit pas en Integer.
Regex: "(\\w+)=(\\w+)", without ^ or $. Output schema: id, key (String), value (Integer). Each “key=value” pair is a match, hence a row; x does not convert to Integer.
Arrêter en cas d'erreur décoché, lien Reject. La ligne 1 donne deux lignes. c=x part en rejet avec ce qui était déjà rempli ; d=4, de la même valeur, sort normalement, mais le rejet de c=x est émis une seconde fois avec lui (voir Pièges).
Die on error unchecked, Reject link. Row 1 gives two rows. c=x is rejected with what was already filled; d=4, from the same value, goes out normally, but the reject of c=x is sent a second time with it (see Pitfalls).
[tLogRow_1] 1|a|1 [tLogRow_1] 1|b|22 [tLogRow_2] 2|c|||For input string: "x" - Line: 2 [tLogRow_1] 2|d|4 [tLogRow_2] 2|c|||For input string: "x" - Line: 2 [tLogRow_1] 3|e|5 ERROR_MESSAGE=For input string: "x"
Coché (défaut), sans lien Reject : le job s'arrête sur c=x, après les lignes déjà sorties (trace abrégée).
Checked (default), without a Reject link: the job stops on c=x, after the rows already sent (trace shortened).
1|a|1 1|b|22 Exception in component tExtractRegexFields_1 (JOB_DocC_XR_E) java.lang.NumberFormatException: For input string: "x" at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67) at java.base/java.lang.Integer.parseInt(Integer.java:662) at java.base/java.lang.Integer.parseInt(Integer.java:778) at routines.system.ParserUtils.parseTo_int(ParserUtils.java:122) at routines.system.ParserUtils.parseTo_Integer(ParserUtils.java:137) …
Décoché, sans lien Reject : le message de Java est écrit sur la sortie d'erreur (3e ligne), c=x est perdu et le job continue.
Unchecked, without a Reject link: the Java message is written on the error output (3rd line), c=x is lost and the job goes on.
1|a|1 1|b|22 For input string: "x" 2|d|4 3|e|5 ERROR_MESSAGE=For input string: "x"
Lignes 1 et 3, Regex "(\\w+)=(\\d+)", schéma id, key, value, extra (String), lien Reject. Sans vérification, extra reçoit "" :
Rows 1 and 3, Regex "(\\w+)=(\\d+)", schema id, key, value, extra (String), Reject link. Without the check, extra gets "":
[tLogRow_1] 1|a|1| [tLogRow_1] 1|b|22| [tLogRow_1] 3|e|5|
Vérifier la structure de chaque ligne par rapport au schéma coché : deux groupes pour trois colonnes à remplir, toutes les correspondances sont rejetées. Check each row structure against schema checked: two groups for three columns to fill, all the matches are rejected.
[tLogRow_2] 1|a|1|||Column(s) missing - Line: 0 [tLogRow_2] 1|b|22|||Column(s) missing - Line: 1 [tLogRow_2] 3|e|5|||Column(s) missing - Line: 2
Une ligne, a=1, b= ; Regex "(\\w+)=(\\d*)" ; value de type int (Nullable décoché). Le groupe 2 de b= est vide : value prend la valeur par défaut du type, 0.
One row, a=1, b=; Regex "(\\w+)=(\\d*)"; value of type int (Nullable unchecked). Group 2 of b= is empty: value takes the default value of the type, 0.
[tLogRow_1] 1|a|1 [tLogRow_1] 1|b|0
Lignes born=10-12-2020 et born=32-01-2020 ; Regex "(\\w+)=([\\d-]+)" ; born de type Date, modèle "dd-MM-yyyy" ; lien Reject. Sans vérification, le 32 janvier devient le 1er février :
Rows born=10-12-2020 and born=32-01-2020; Regex "(\\w+)=([\\d-]+)"; born of type Date, pattern "dd-MM-yyyy"; Reject link. Without the check, January 32nd becomes February 1st:
[tLogRow_1] 1|born|10-12-2020 [tLogRow_1] 2|born|01-02-2020
Vérifier la structure de chaque ligne par rapport au schéma coché (deux groupes, deux colonnes à remplir) : la date est refusée. Check each row structure against schema checked (two groups, two columns to fill): the date is refused.
[tLogRow_1] 1|born|10-12-2020 [tLogRow_2] 2|born|||Unparseable date: "32-01-2020" - Line: 1
Les trois premiers encadrés décrivent des défauts du modèle de Talaxie (tExtractRegexFields_main.javajet), constatés à l'exécution.
The first three boxes describe defects of the Talaxie template (tExtractRegexFields_main.javajet), seen at run time.
Le lien Reject n'est vidé qu'à chaque nouvelle ligne d'entrée, pas à chaque correspondance. Quand une correspondance est rejetée, chacune des suivantes de la même valeur renvoie ce rejet avec elle (c=x deux fois dans l'exemple Rejet de la conversion). Avec plusieurs correspondances par valeur, dédoublonnez les rejets, ou ancrez l'expression (^…$) pour n'en avoir qu'une.
The Reject link is only emptied at each new input row, not at each match. When a match is rejected, each of the following ones of the same value sends this reject again with it (c=x twice in the Reject of the conversion example). With several matches per value, remove the duplicate rejects, or anchor the expression (^…$) to get only one.
Un groupe qui ne participe pas à la correspondance, comme (\\d+)?, vaut null. Une colonne String le reçoit tel quel ; pour un autre type, le code généré lit sa longueur et échoue. Une ligne a=1, b=, Regex "(\\w+)=(\\d+)?", value Integer, lien Reject :
A group that takes no part in the match, like (\\d+)?, is null. A String column gets it as is; for another type, the generated code reads its length and fails. One row a=1, b=, Regex "(\\w+)=(\\d+)?", value Integer, Reject link:
[tLogRow_1] 1|a|1 [tLogRow_2] 1|b|||Cannot invoke "String.length()" because "<local29>" is null - Line: 1
Écrivez plutôt (\\d*) : le groupe est alors vide, et la colonne prend sa valeur par défaut (exemple Groupe vide).
Write (\\d*) instead: the group is then empty, and the column takes its default value (Empty group example).
Le n de - Line: n est le nombre de correspondances déjà traitées par le composant, à partir de 0, pas le rang de la ligne d'entrée. Dans les exemples, c=x, troisième correspondance, donne Line: 2 ; avec la vérification de la structure, les correspondances des lignes 1, 1 et 3 donnent Line: 0, 1 et 2. Pour retrouver la ligne, gardez une colonne d'identifiant (id) dans la sortie : elle passe dans le rejet.
The n of - Line: n is the number of matches already processed by the component, from 0, not the rank of the input row. In the examples, c=x, third match, gives Line: 2; with the structure check, the matches of rows 1, 1 and 3 give Line: 0, 1 and 2. To find the row, keep an identifier column (id) in the output: it goes into the reject.
Avec les réglages par défaut, une valeur qui ne correspond pas disparaît : Arrêter en cas d'erreur ne la voit pas (premier exemple). Une valeur nulle disparaît toujours, même avec un lien Reject. Pour les compter, décochez Arrêter en cas d'erreur et reliez le Reject ; pour les nulles, filtrez-les avant, avec un tFilterRow. With the default settings, a value that does not match disappears: Die on error does not see it (first example). A null value always disappears, even with a Reject link. To count them, uncheck Die on error and connect the Reject; for the null ones, filter them first, with a tFilterRow.
La Regex est du code Java : entre guillemets, chaque antislash doublé ("\\d+" pour \d+, "\\[" pour un crochet). (?i) en tête ignore la casse. Pour qu'elle porte sur toute la valeur, encadrez-la de ^ et $.
The Regex is Java code: between quotes, each backslash doubled ("\\d+" for \d+, "\\[" for a bracket). A leading (?i) ignores the case. For it to cover the whole value, surround it with ^ and $.
Chaque groupe ( ) compte, même ceux qui ne servent qu'à regrouper une alternative : (lun|mar) prend une colonne. Écrivez (?:lun|mar) pour un groupe qui ne remplit rien.
Every ( ) group counts, even those that only group an alternative: (mon|tue) takes a column. Write (?:mon|tue) for a group that fills nothing.
tReplace · remplacer du texte, expressions régulières comprisesreplace text, regular expressions includedtReplaceList · remplacer d'après une liste lue dans un Lookupreplace according to a list read from a LookuptConvertType · convertir des colonnes d'un type à un autreconvert columns from one type to anothertFilterRow · garder les lignes qui remplissent des conditionskeep the rows that meet conditionstLogRow · afficher les lignes d'un fluxdisplay the rows of a flow