ComposantsComponents

ComposantsComponents › Qualité de donnéesData Quality

tAddCRCRow

tAddCRCRow

Qualité de donnéesData Quality

Ajoute à chaque ligne d'un flux une colonne CRC : un code de contrôle (CRC32 par défaut) calculé sur les colonnes choisies. Deux lignes aux mêmes valeurs ont le même CRC ; il sert à repérer les lignes qui ont changé d'un chargement à l'autre, ou à comparer des lignes sur une seule colonne. Adds to every row of a flow a CRC column: a check code (CRC32 by default) computed on the chosen columns. Two rows with the same values have the same CRC; it helps to spot the rows that changed from one load to the next, or to compare rows on a single column.

EntréeInput

Main un fluxone flow

SortieOutput

Main un flux : les mêmes lignes, plus la colonne CRC (Long)one flow: the same rows, plus the CRC column (Long)

Déclencheurs en sortieOutput triggers

On Component Ok On Component Error Run if

UtilisationUsage

row1 (Main) row2 (Main) tFileInputDelimited_1 tAddCRCRow_1 tFileOutputDelimited_1

Chaque ligne part aussitôt, avec son CRC dans la dernière colonne. Les valeurs des colonnes cochées sont mises bout à bout, dans l'ordre du schéma, puis passées au calcul du CRC. Each row leaves at once, with its CRC in the last column. The values of the checked columns are put end to end, in the schema order, then passed to the CRC computation.

  1. Reliez la sortie d'un composant au tAddCRCRow, puis le tAddCRCRow au composant suivant. Le schéma, en lecture seule, prend les colonnes de l'entrée, suivies de la colonne CRC. Connect the output of a component to the tAddCRCRow, then the tAddCRCRow to the next component. The schema, read-only, takes the input columns, followed by the CRC column.
  2. Dans Implication, cochez Utiliser dans le CRC pour chaque colonne qui doit compter. In Implication, check Use in CRC for each column that must count.
  3. Au besoin, changez le Type de CRC dans les paramètres avancés. If needed, change the CRC Type in the advanced settings.

ParamètresSettings

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 OngletTab Description
SchémaSchemaSCHEMA colonne CRC (Long)CRC column (Long) Paramètres simplesBasic settings En lecture seule : les colonnes de l'entrée, recopiées telles quelles, puis CRC. Le composant écrit le CRC dans la dernière colonne du schéma. Read-only: the input columns, copied as is, then CRC. The component writes the CRC in the last column of the schema.
ImplicationIMPLICATION aucune colonne cochéeno column checked Paramètres simplesBasic settings Une ligne par colonne du schéma, avec la case Utiliser dans le CRC (USE_IN_CRC). Les valeurs cochées sont converties en texte et mises bout à bout, sans séparateur : une nulle devient null, un BigDecimal perd ses zéros de fin. La ligne de la colonne CRC elle-même n'a pas d'effet. Sans aucune colonne cochée, le CRC32 vaut 0. One line per column of the schema, with the Use in CRC box (USE_IN_CRC). The checked values are converted to text and put end to end, without a separator: a null becomes null, a BigDecimal loses its trailing zeros. The line of the CRC column itself has no effect. With no column checked, the CRC32 is 0.
Type de CRCCRC TypeCRC_TYPE CRC32 Paramètres avancésAdvanced settings CRC32 (crc32) : le CRC32 de Java (java.util.zip.CRC32), de 0 à 4 294 967 295. CRC16 (crc16) et CRC8 (crc8) : ceux de la bibliothèque OneWireAPI, de 0 à 65 535 et de 0 à 255. Voir CRC8 et CRC16. CRC32 (crc32): Java's CRC32 (java.util.zip.CRC32), from 0 to 4,294,967,295. CRC16 (crc16) and CRC8 (crc8): those of the OneWireAPI library, from 0 to 65,535 and from 0 to 255. See CRC8 and CRC16.

Variable globaleGlobal variable

NB_LINE (Integer, disponible après le composant) : le nombre de lignes traitées. NB_LINE (Integer, available after the component): the number of rows processed.

((Integer) globalMap.get("tAddCRCRow_1_NB_LINE"))

ExemplesExamples

Un tFixedFlowInput envoie six lignes au tAddCRCRow, suivi d'un tLogRow ; le CRC est la dernière valeur de chaque ligne. Un tJava relié par On Subjob Ok affiche NB_LINE. Type de CRC : CRC32. Sorties copiées depuis une exécution du job. A tFixedFlowInput sends six rows to the tAddCRCRow, followed by a tLogRow; the CRC is the last value of each row. A tJava connected with On Subjob Ok prints NB_LINE. CRC type: CRC32. Outputs copied from a run of the job.

row1 (Main) row2 (Main) tFixedFlowInput_1 tAddCRCRow_1 tLogRow_1
idInteger nameString cityString
1AdaParis
2adaParis
3AdaParis
4nullLyon
5"null"Lyon
6AdaParis

Ligne 4 : name est nulle ; ligne 5 : name vaut le texte null. Row 4: name is null; row 5: name is the text null.

CRC de name et cityCRC of name and city

Les lignes 1 et 6 ont les mêmes valeurs, donc le même CRC ; la casse compte (ligne 2). Les lignes 3 (« AdaP » + « aris ») et 4/5 (nulle ou texte null) montrent les pièges du calcul. Rows 1 and 6 have the same values, so the same CRC; the case counts (row 2). Rows 3 (“AdaP” + “aris”) and 4/5 (null or the text null) show the pitfalls of the computation.

1|Ada|Paris|2911615720
2|ada|Paris|1425922238
3|AdaP|aris|2911615720
4||Lyon|4285155436
5|null|Lyon|4285155436
6|Ada|Paris|2911615720
NB_LINE=6

Toutes les colonnesAll the columns

id, name et city cochées : id diffère d'une ligne à l'autre, tous les CRC aussi. id, name and city checked: id differs from one row to the next, so do all the CRCs.

1|Ada|Paris|401253822
2|ada|Paris|3608279853
3|AdaP|aris|958172472
4||Lyon|261886581
5|null|Lyon|417793590
6|Ada|Paris|1938540663
NB_LINE=6

Aucune colonne cochéeNo column checked

Le CRC32 d'un texte vide : 0 partout, sans message. The CRC32 of an empty text: 0 everywhere, without a message.

1|Ada|Paris|0
2|ada|Paris|0
3|AdaP|aris|0
4||Lyon|0
5|null|Lyon|0
6|Ada|Paris|0
NB_LINE=6

BigDecimalBigDecimal

Schéma id (Integer), amount (BigDecimal), CRC de amount. Les zéros de fin sont retirés avant le calcul : 1.5 et 1.50 ont le même CRC, 100 et 100.00 aussi. Mais 100 est haché sous la forme 1E+2, pas 100. Une nulle donne le CRC du texte null. Schema id (Integer), amount (BigDecimal), CRC of amount. Trailing zeros are removed before the computation: 1.5 and 1.50 have the same CRC, so do 100 and 100.00. But 100 is hashed in the form 1E+2, not 100. A null gives the CRC of the text null.

1|1.5|2270993338
2|1.50|2270993338
3|100|2703598362
4|100.00|2703598362
5||634125391
NB_LINE=5

DateDate

Colonne day (Date, modèle "yyyy-MM-dd") qui vaut le 14 novembre 2026. Le tLogRow l'affiche selon le modèle, mais le CRC est celui de Sat Nov 14 00:00:00 CET 2026, l'écriture de Java : elle contient le fuseau horaire de la machine. day column (Date, pattern "yyyy-MM-dd") set to November 14, 2026. The tLogRow prints it with the pattern, but the CRC is the one of Sat Nov 14 00:00:00 CET 2026, the Java writing: it contains the time zone of the machine.

1|2026-11-14|2451657271
NB_LINE=1

CRC8 et CRC16 : bibliothèque introuvableCRC8 and CRC16: library not found

Le composant demande toujours la bibliothèque mvn:org.talend.libraries/OneWireAPI/6.0.0, quel que soit le type de CRC. Elle n'est ni sur Maven Central ni sur le dépôt Nexus de Talaxie. Le CRC32 n'en a pas besoin : lancé avec Talaxie, le job affiche « bibliothèque introuvable », puis compile et tourne normalement (exemples ci-dessus). En CRC8 ou en CRC16, le code généré appelle ses classes com.dalsemi.onewire.utils.CRC8 et CRC16, et la compilation échoue : The component always asks for the mvn:org.talend.libraries/OneWireAPI/6.0.0 library, whatever the CRC type. It is neither on Maven Central nor on the Talaxie Nexus repository. CRC32 does not need it: run with Talaxie, the job prints “library not found”, then compiles and runs normally (examples above). In CRC8 or CRC16, the generated code calls its com.dalsemi.onewire.utils.CRC8 and CRC16 classes, and the compilation fails:

Library not found: mvn:org.talend.libraries/OneWireAPI/6.0.0
The job failed to compile:
…\MyJob.java:1438: error: package com.dalsemi.onewire.utils does not exist
                    crcComputedValuetAddCRCRow_1 = new Long(com.dalsemi.onewire.utils.CRC8.compute(strBuffer_tAddCRCRow_1.toString().getBytes()));
                                                                                     ^
1 error

Le nom du job est remplacé par MyJob, le chemin du code est abrégé. CRC8 et CRC16 sont donc décrits d'après le modèle du composant, sans essai. Gardez CRC32, qui distingue aussi beaucoup mieux les lignes. The job name is replaced with MyJob, the code path is shortened. CRC8 and CRC16 are therefore described from the component template, without trying them. Keep CRC32, which also tells rows apart much better.

Pièges et conseilsPitfalls and tips

Pas de séparateur entre les valeursNo separator between the values

Les valeurs sont collées l'une à l'autre : « Ada » + « Paris » et « AdaP » + « aris » donnent le même texte, AdaParis, donc le même CRC (lignes 1 et 3 du premier exemple). Défaut du modèle de Talaxie (tAddCRCRow_main.javajet). Pour l'éviter, préparez dans un tMap ou un tJavaRow une colonne qui joint les valeurs avec un séparateur, et ne cochez qu'elle. The values are stuck to each other: “Ada” + “Paris” and “AdaP” + “aris” give the same text, AdaParis, hence the same CRC (rows 1 and 3 of the first example). Defect of the Talaxie template (tAddCRCRow_main.javajet). To avoid it, prepare in a tMap or a tJavaRow a column that joins the values with a separator, and check only that one.

Une nulle vaut le texte « null »A null is worth the text “null”

Une valeur nulle est hachée comme le texte null : une colonne vide et une colonne qui contient « null » ont le même CRC (lignes 4 et 5). Si la différence compte, remplacez les nulles avant le tAddCRCRow par une valeur qui ne peut pas apparaître. A null value is hashed as the text null: an empty column and a column that contains “null” have the same CRC (rows 4 and 5). If the difference matters, replace the nulls before the tAddCRCRow with a value that cannot appear.

Un CRC n'est pas une clé uniqueA CRC is not a unique key

Deux lignes différentes peuvent avoir le même CRC. En CRC32 (environ 4,3 milliards de valeurs), une telle collision devient probable dès quelques dizaines de milliers de lignes ; en CRC16, dès quelques centaines ; en CRC8, dès une vingtaine. Le CRC dit qu'une ligne a sans doute changé ; pour une clé, ou pour un contrôle sûr, comparez aussi les colonnes, ou calculez une empreinte plus longue (SHA-256) dans un tJavaRow. Two different rows can have the same CRC. In CRC32 (about 4.3 billion values), such a collision becomes likely from a few tens of thousands of rows; in CRC16, from a few hundred; in CRC8, from about twenty. The CRC tells that a row has probably changed; for a key, or for a safe check, also compare the columns, or compute a longer fingerprint (SHA-256) in a tJavaRow.

Un CRC qui dépend de la machineA CRC that depends on the machine

Le texte est converti en octets avec l'encodage par défaut de la JVM (UTF-8 avec Java 18 et plus, ou avec -Dfile.encoding=UTF-8) : un texte accentué peut changer de CRC d'une machine à l'autre. Une date est hachée avec son fuseau horaire (exemple Date). Pour comparer des CRC calculés à des moments ou sur des machines différents, gardez le même encodage et le même fuseau, ou hachez la date déjà mise en texte. The text is converted to bytes with the default encoding of the JVM (UTF-8 with Java 18 and later, or with -Dfile.encoding=UTF-8): an accented text can change its CRC from one machine to another. A date is hashed with its time zone (Date example). To compare CRCs computed at different times or on different machines, keep the same encoding and the same time zone, or hash the date already turned into text.

Repérer les lignes modifiéesSpotting the changed rows

Calculez le CRC des colonnes à surveiller (pas de la clé, ni des dates de chargement), gardez-le avec la ligne, et comparez-le au prochain chargement, joint par la clé : un CRC différent signale une ligne modifiée. Compute the CRC of the columns to watch (not of the key, nor of the load dates), keep it with the row, and compare it at the next load, joined on the key: a different CRC flags a changed row.

Type de la colonne CRCType of the CRC column

Un CRC32 dépasse souvent 2 147 483 647 : la colonne est un Long. Gardez un entier de 64 bits jusqu'à la base (BIGINT) : un INTEGER de 32 bits ne peut pas le contenir. A CRC32 often exceeds 2,147,483,647: the column is a Long. Keep a 64-bit integer down to the database (BIGINT): a 32-bit INTEGER cannot hold it.

Voir aussiSee also