ComposantsComponents

ComposantsComponents › TraitementProcessing

tExtractDynamicFields

tExtractDynamicFields

TraitementProcessing

Sort d'une colonne Dynamic des colonnes nommées et typées. Une colonne Dynamic porte des colonnes connues seulement à l'exécution : celles de l'en-tête d'un fichier, du résultat d'une requête. Le tExtractDynamicFields en tire celles dont le job a besoin, par leur nom, et les convertit dans le type du schéma ; le reste peut suivre dans une colonne Dynamic de sortie. Après lui, le flux est ordinaire : tous les composants l'acceptent. L'inverse est le tWriteDynamicFields. Takes named and typed columns out of a Dynamic column. A Dynamic column carries columns only known at run time: those of the header of a file, of the result of a query. The tExtractDynamicFields takes out those the job needs, by their name, and converts them to the type of the schema; the rest can follow in a Dynamic output column. After it, the flow is an ordinary one: all components accept it. The reverse is the tWriteDynamicFields.

EntréeInput

Main un flux avec une colonne Dynamic (obligatoire)one flow with a Dynamic column (required)

SortieOutput

Main un flux : une ligne par ligne reçue, avec les colonnes du schémaone flow: one row per row received, with the columns of the schema

Déclencheurs en sortieOutput triggers

On Component Ok On Component Error Run if

UtilisationUsage

row1 (Main) row2 (Main) row3 (Main) tFileInputDelimited_1 tExtractDynamicFields_1 tSortRow_1 tLogRow_1

Le fichier est lu avec une colonne Dynamic qui prend toutes ses colonnes, nommées par son en-tête. Le tExtractDynamicFields en sort name et city ; le tSortRow, qui n'accepte pas le type Dynamic, peut alors trier sur elles. The file is read with a Dynamic column that takes all its columns, named by its header. The tExtractDynamicFields takes out name and city; the tSortRow, which does not accept the Dynamic type, can then sort on them.

  1. Dans le composant d'entrée (un tFileInputDelimited avec une ligne d'en-tête, par exemple), déclarez les colonnes connues, puis une dernière colonne de type Dynamic. In the input component (a tFileInputDelimited with a header line, for example), declare the known columns, then a last column of type Dynamic.
  2. Déposez le tExtractDynamicFields depuis la famille Traitement de la palette et reliez-lui le flux. Drop the tExtractDynamicFields from the Processing family of the palette and connect the flow to it.
  3. Dans son Schema, ajoutez une colonne par champ à extraire, du même nom que dans le Dynamic (casse comprise), avec son type ; un motif pour une date. In its Schema, add one column per field to extract, with the same name as in the Dynamic (case included), with its type; a pattern for a date.
  4. Pour garder les autres champs, ajoutez en dernier une colonne Dynamic : elle reçoit tout ce qui n'a pas été extrait. To keep the other fields, add a Dynamic column last: it gets everything that was not extracted.

Le type Dynamic dans TalaxieThe Dynamic type in Talaxie

Talend Open Studio n'avait pas le type Dynamic. Talaxie l'ajoute, avec ces deux composants. Une colonne Dynamic est un conteneur : pour chaque ligne, la liste des champs (nom, type, type en base, longueur…) et leurs valeurs. Avant de générer le code, Talaxie vérifie les schémas et s'arrête avec un message si une règle n'est pas tenue. Talend Open Studio did not have the Dynamic type. Talaxie adds it, with these two components. A Dynamic column is a container: for each row, the list of fields (name, type, database type, length…) and their values. Before generating the code, Talaxie checks the schemas and stops with a message if a rule is not met.

Règles des schémasSchema rules

  • Une seule colonne Dynamic par schéma : Il ne doit y avoir qu'un seul type Dynamique dans ce schéma.Only one Dynamic column per schema: There should be only one Dynamic type in one schema.
  • La dernière : La colonne Dynamic doit être la dernière colonne du schéma. (le schéma d'un Reject garde ses colonnes d'erreur après elle).The last one: The Dynamic column must be the last column in the schema. (the schema of a Reject keeps its error columns after it).
  • Seulement dans les composants qui la prennent en charge : Ce composant ne supporte pas le type Dynamique (en anglais : This component doesn't support Dynamic Type).Only in the components that support it: This component doesn't support Dynamic Type (in French: Ce composant ne supporte pas le type Dynamique).
  • Un composant qui transmet la colonne (tMap, tFilterRow…) la garde sous le même nom et le même type.A component passing the column on (tMap, tFilterRow…) keeps it with the same name and the same type.

Composants qui l'acceptentComponents accepting it

Essayés pour ces pages (Talaxie 9.0.6, Java 21) : tFileInputDelimited (colonnes nommées par l'en-tête), tLogRow (colonnes dépliées), tJavaRow, tFileOutputDelimited (en-tête et valeurs dépliés), tMap (colonne transmise sans la renommer), tExtractDynamicFields, tWriteDynamicFields. Tried for these pages (Talaxie 9.0.6, Java 21): tFileInputDelimited (columns named by the header), tLogRow (columns unfolded), tJavaRow, tFileOutputDelimited (header and values unfolded), tMap (column passed on without renaming it), tExtractDynamicFields, tWriteDynamicFields.

Acceptés aussi par Talaxie, non essayés ici : tFilterRow, tFilterColumns, tReplicate, tBufferOutput, tHashInput, tHashOutput, tRunJob (sans processus indépendant ni job dynamique) ; tMysqlInput, tOracleInput, tPostgresqlInput, tMSSqlInput et leurs Output, sans connexion existante et avec des restrictions de réglages. Le tFileInputDelimited ne l'accepte pas avec Utiliser dynamique existant, le tFileOutputDelimited ni en Sortie en mode ligne, ni parallélisé. Also accepted by Talaxie, not tried here: tFilterRow, tFilterColumns, tReplicate, tBufferOutput, tHashInput, tHashOutput, tRunJob (without independent process nor dynamic job); tMysqlInput, tOracleInput, tPostgresqlInput, tMSSqlInput and their Output, without existing connection and with restrictions on settings. The tFileInputDelimited does not accept it with Use existing dynamic, nor the tFileOutputDelimited in Output in row mode or parallelized.

Les autres composants refusent un schéma Dynamic. Un tSortRow derrière un tFileInputDelimited dynamique, par exemple, arrête la génération : tSortRow_1 : Ce composant ne supporte pas le type Dynamique. C'est ce qui rend utile le tExtractDynamicFields : sans colonne Dynamic en sortie, son flux passe partout. The other components refuse a Dynamic schema. A tSortRow after a dynamic tFileInputDelimited, for example, stops the generation: tSortRow_1 : Ce composant ne supporte pas le type Dynamique. This is what makes the tExtractDynamicFields useful: without a Dynamic output column, its flow goes everywhere.

ParamètresSettings

Le composant n'a qu'un paramètre, son schéma ; le libellé est le même en français et en anglais. Il n'a pas de paramètres avancés. The component has only one setting, its schema; the label is the same in French and in English. It has no advanced settings.

ParamètreSetting DéfautDefault VisibleShown Description
SchemaSCHEMA videempty ToujoursAlways Les colonnes de sortie. Chacune est prise, dans l'ordre : The output columns. Each one is taken, in this order:
  • dans la colonne d'entrée ordinaire de même nom, s'il y en a une ;from the ordinary input column of the same name, if there is one;
  • sinon dans le champ du Dynamic de même nom, casse comprise, converti dans le type de la colonne ; un champ absent donne null ;otherwise from the field of the Dynamic with the same name, case included, converted to the type of the column; a missing field gives null;
  • une colonne de type Dynamic, en dernier, reçoit les champs du Dynamic qui n'ont pas été extraits, dans leur ordre.a column of type Dynamic, last, gets the fields of the Dynamic that were not extracted, in their order.

ConversionsConversions

  • Un texte vide donne null dans une colonne numérique, Boolean, Character ou Date ; il reste vide dans une colonne String.An empty text gives null in a numeric, Boolean, Character or Date column; it stays empty in a String column.
  • Dans une colonne non nullable, un champ absent ou vide arrête le job : Missing value for required id_Integer field, Empty value for required id_Integer field.In a non-nullable column, a missing or empty field stops the job: Missing value for required id_Integer field, Empty value for required id_Integer field.
  • Un texte qui ne se convertit pas arrête le job (NumberFormatException).A text that does not convert stops the job (NumberFormatException).
  • Une date lue d'un texte demande le motif de la colonne, lu strictement ("yyyy-MM-dd") : sans lui, A date pattern is required. Une valeur déjà de type Date est reprise telle quelle.A date read from a text needs the pattern of the column, read strictly ("yyyy-MM-dd"): without it, A date pattern is required. A value already of type Date is taken as it is.

Variable globaleGlobal variable

NB_LINE (Integer, disponible après l'exécution du composant) : nombre de lignes traitées. NB_LINE (Integer, available after the component has run): number of rows processed.

((Integer) globalMap.get("tExtractDynamicFields_1_NB_LINE"))

Le composant n'a pas de lien Reject : une erreur de conversion arrête le job. The component has no Reject link: a conversion error stops the job.

ExemplesExamples

Un tFileInputDelimited lit C:\data\people.csv (séparateur ;, une ligne d'en-tête) avec le schéma id (Integer), fields (Dynamic). Les sorties sont copiées depuis des exécutions des jobs dans Talaxie (Java 21). A tFileInputDelimited reads C:\data\people.csv (; separator, one header line) with the schema id (Integer), fields (Dynamic). The outputs are copied from runs of the jobs in Talaxie (Java 21).

Le fichier et ce que contient le DynamicThe file and what the Dynamic holds

id;name;city;age;since
1;Ada;London;36;2020-01-15
2;Alan;;41;
3;Grace;New York;;2019-07-01

Un tJavaRow liste les champs de fields, puis un tLogRow en tableau affiche les lignes : A tJavaRow lists the fields of fields, then a tLogRow as a table prints the rows:

routines.system.Dynamic dyn = input_row.fields;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < dyn.getColumnCount(); i++) {
    routines.system.DynamicMetadata m = dyn.getColumnMetadata(i);
    Object v = dyn.getColumnValue(i);
    sb.append(i == 0 ? "" : ", ").append(m.getName()).append(" (").append(m.getType()).append(", ").append(v == null ? "null" : v.getClass().getSimpleName()).append(")=").append(v);
}
System.out.println("fields: " + sb);
output_row.id = input_row.id;
output_row.fields = input_row.fields;
fields: name (id_String, String)=Ada, city (id_String, String)=London, age (id_String, String)=36, since (id_String, String)=2020-01-15
fields: name (id_String, String)=Alan, city (id_String, String)=, age (id_String, String)=41, since (id_String, String)=
fields: name (id_String, String)=Grace, city (id_String, String)=New York, age (id_String, String)=, since (id_String, String)=2019-07-01
tLogRow_1
+----+-------+----------+-----+------------+
| id | name  | city     | age | since      |
+----+-------+----------+-----+------------+
| 1  | Ada   | London   | 36  | 2020-01-15 |
| 2  | Alan  |          | 41  |            |
| 3  | Grace | New York |     | 2019-07-01 |
+----+-------+----------+-----+------------+

Lus d'un fichier, tous les champs sont des textes ; une case vide est un texte vide. id, déclaré dans le schéma, n'est pas dans le Dynamic. Read from a file, all the fields are texts; an empty cell is an empty text. id, declared in the schema, is not in the Dynamic.

Extraire et garder le resteExtract and keep the rest

row1 (Main) row2 (Main) tFileInputDelimited_1 tExtractDynamicFields_1 tLogRow_1

Schéma : id (Integer), name (String), age (Integer), since (Date, motif "yyyy-MM-dd"), country (String), rest (Dynamic). Un tJava affiche NB_LINE. Schema: id (Integer), name (String), age (Integer), since (Date, pattern "yyyy-MM-dd"), country (String), rest (Dynamic). A tJava prints NB_LINE.

tLogRow_1
+----+-------+------+------------+---------+----------+
| id | name  | age  | since      | country | city     |
+----+-------+------+------------+---------+----------+
| 1  | Ada   | 36   | 2020-01-15 | null    | London   |
| 2  | Alan  | 41   | null       | null    |          |
| 3  | Grace | null | 2019-07-01 | null    | New York |
+----+-------+------+------------+---------+----------+
tExtractDynamicFields_1_NB_LINE: 3

age et since sont convertis ; un texte vide y donne null. country, absent du fichier, vaut null sans erreur. Le Dynamic rest ne contient plus que city, qui reste un texte (vide pour Alan). age and since are converted; an empty text gives null there. country, missing from the file, is null without error. The rest Dynamic only holds city, which stays a text (empty for Alan).

Sans Dynamic en sortie, puis un triWithout Dynamic output, then a sort

Schéma id, city, NAME : le nom en majuscules ne correspond à aucun champ. Schema id, city, NAME: the upper-case name matches no field.

.--+--------+----.
|   tLogRow_1    |
|=-+--------+---=|
|id|city    |NAME|
|=-+--------+---=|
|1 |London  |null|
|2 |        |null|
|3 |New York|null|
'--+--------+----'

Schéma id, name, city, suivi d'un tSortRow sur name, alphabétique, décroissant : Schema id, name, city, followed by a tSortRow on name, alphabetical, descending:

.--+-----+--------.
|    tLogRow_1    |
|=-+-----+-------=|
|id|name |city    |
|=-+-----+-------=|
|3 |Grace|New York|
|2 |Alan |        |
|1 |Ada  |London  |
'--+-----+--------'

Sans colonne Dynamic, le tLogRow revient à son tableau habituel, et le tSortRow accepte le flux. Without a Dynamic column, the tLogRow goes back to its usual table, and the tSortRow accepts the flow.

Relire un Dynamic construit par tWriteDynamicFieldsReading back a Dynamic built by tWriteDynamicFields

Un tWriteDynamicFields range name, city, age (Integer) et since (Date) dans fields ; le tExtractDynamicFields en reprend age (Integer) et since (Date, motif "dd/MM/yyyy"), et garde fields : A tWriteDynamicFields puts name, city, age (Integer) and since (Date) in fields; the tExtractDynamicFields takes back age (Integer) and since (Date, pattern "dd/MM/yyyy"), and keeps fields:

tLogRow_1
+----+-----+------------+------+--------+
| id | age | since      | name | city   |
+----+-----+------------+------+--------+
| 1  | 36  | 15/01/2020 | Ada  | London |
| 2  | 41  | null       | Alan | null   |
+----+-----+------------+------+--------+

Les valeurs gardent leur type Java : la date n'est pas relue d'un texte, le motif de la colonne ne sert qu'à l'affichage du tLogRow. Values keep their Java type: the date is not read from a text, the pattern of the column only serves the display of the tLogRow.

ErreursErrors

Même fichier. Le nom du job est remplacé par MyJob et les traces d'exception sont abrégées ; chaque erreur d'exécution donne le code de sortie 1. Same file. The job name is replaced with MyJob and exception traces are shortened; each run-time error gives exit code 1.

Entier obligatoire videEmpty required integer

Schéma id, age (Integer, non nullable), tLogRow en mode simple. La troisième ligne n'a pas d'âge : Schema id, age (Integer, not nullable), tLogRow in basic mode. The third row has no age:

1|36
2|41
Exception in component tExtractDynamicFields_1 (MyJob)
java.lang.IllegalArgumentException: Empty value for required id_Integer field
	at routines.system.DynamicFields.convert(DynamicFields.java:50)
	…

Date sans motif, texte non numériqueDate without pattern, non-numeric text

Colonne since (Date) sans motif : since column (Date) without pattern:

Exception in component tExtractDynamicFields_1 (MyJob)
java.lang.IllegalArgumentException: A date pattern is required
	at routines.system.DynamicFields.convert(DynamicFields.java:69)
	…

Colonne city déclarée Integer : city column declared Integer:

Exception in component tExtractDynamicFields_1 (MyJob)
java.lang.NumberFormatException: For input string: "London"
	at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:67)
	…
	at routines.system.DynamicFields.convert(DynamicFields.java:56)
	…

Entrée sans colonne DynamicInput without a Dynamic column

Un tFixedFlowInput (id, name, city) relié au tExtractDynamicFields : la génération s'arrête, le job ne démarre pas. Ce message n'existe qu'en anglais. A tFixedFlowInput (id, name, city) connected to the tExtractDynamicFields: the generation stops, the job does not start. This message only exists in English.

tExtractDynamicFields_1 : tExtractDynamicFields requires a Dynamic input column.

Conseils et limitesTips and limits

Les noms comptent, casse compriseNames matter, case included

Un champ se trouve par son nom exact : NAME ne trouve pas name, et un nom mal écrit donne null sans message. Si une colonne est indispensable, rendez-la non nullable : son absence arrêtera le job au lieu de passer inaperçue. A field is found by its exact name: NAME does not find name, and a misspelt name gives null without message. If a column is essential, make it not nullable: its absence will stop the job instead of going unnoticed.

Pas de rejetNo reject

Une valeur qui ne se convertit pas arrête le job. Pour écarter les lignes douteuses, extrayez les champs en String, puis convertissez-les avec un tConvertType, qui a un lien Reject. A value that does not convert stops the job. To set aside doubtful rows, extract the fields as String, then convert them with a tConvertType, which has a Reject link.

Voir aussiSee also