ComposantsComponents

ComposantsComponents › Qualité de donnéesData Quality

tIntervalMatch

tIntervalMatch

Qualité de donnéesData Quality

Pour chaque ligne du flux principal, cherche dans un flux Lookup l'intervalle, entre une borne min et une borne max, où tombe la valeur d'une colonne, et ajoute à la ligne une valeur de cet intervalle (colonne LOOKUP). Pour classer par tranches : âges, montants, codes, ou dates de validité d'un tarif. Pour une clé égale, prenez un tJoin. For each row of the main flow, looks up in a Lookup flow the interval, between a min and a max bound, that the value of a column falls into, and adds a value of this interval to the row (LOOKUP column). To classify by ranges: ages, amounts, codes, or validity dates of a rate. For an equal key, take a tJoin.

EntréeInput

Main les valeurs à classer, obligatoirethe values to classify, required

Lookup les intervalles, obligatoirethe intervals, required

SortieOutput

Main un flux au moins : les colonnes principales, plus LOOKUP ; d'autres flux reçoivent la même ligneat least one flow: the main columns, plus LOOKUP; other flows get the same row

Déclencheurs en sortieOutput triggers

On Component Ok On Component Error Run if

UtilisationUsage

row1 (Main) row2 (Main) row3 (Lookup) tFileInputDelimited_1 tIntervalMatch_1 tFileOutputDelimited_1 tFileInputDelimited_2

Le Lookup est lu en entier, gardé en mémoire et trié par borne min, puis max, avant la première ligne du flux principal : il peut arriver dans n'importe quel ordre. Chaque valeur principale y est ensuite cherchée par dichotomie, ce qui suppose des intervalles qui ne se chevauchent pas. Une ligne principale sort toujours, une seule fois. The Lookup is read entirely, kept in memory and sorted by min bound, then max, before the first row of the main flow: it may arrive in any order. Each main value is then looked up in it by binary search, which assumes intervals that do not overlap. A main row always goes out, only once.

  1. Reliez d'abord le flux principal au tIntervalMatch, puis les intervalles : arrivant en second, ce flux devient le Lookup. Il a une colonne pour la borne min, une pour la borne max, et la valeur à rendre. First connect the main flow to the tIntervalMatch, then the intervals: arriving second, this flow becomes the Lookup. It has a column for the min bound, one for the max bound, and the value to return.
  2. Schéma de sortie : les colonnes du flux principal, sous les mêmes noms, et la colonne LOOKUP, du type de la valeur rendue. Output schema: the main flow columns, under the same names, and the LOOKUP column, of the type of the returned value.
  3. Choisissez la Colonne de recherche du flux principal, puis, dans le Lookup, les colonnes des bornes (du même type) et la Colonne (LOOKUP) à rendre. Choose the Search Column of the main flow, then, in the Lookup, the bound columns (of the same type) and the Column (LOOKUP) to return.
  4. Par défaut, un intervalle contient sa borne min et pas sa borne max : des tranches 0–18, 18–65, 65–120 ne se recouvrent pas. By default, an interval contains its min bound and not its max bound: ranges 0–18, 18–65, 65–120 do not overlap.

Paramètres simplesBasic settings

Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Tous les paramètres sont toujours visibles ; la troisième colonne donne leur onglet. Le composant n'a pas de paramètres avancés propres. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. All the settings are always shown; the third column gives their tab. The component has no advanced settings of its own.

ParamètreSetting DéfautDefault OngletTab Description
SchémaSchemaSCHEMA LOOKUP (String) Paramètres simplesBasic settings Les colonnes du flux principal, recopiées par nom, et la colonne LOOKUP, qui reçoit la valeur de l'intervalle trouvé, ou null s'il n'y en a pas. Donnez-lui le type de la Colonne (LOOKUP). The main flow columns, copied by name, and the LOOKUP column, which gets the value of the interval found, or null if there is none. Give it the type of the Column (LOOKUP).
Colonne de rechercheSearch ColumnMAIN_COLUMN videempty Paramètres simplesBasic settings La colonne du flux principal à classer. Byte, Short, Integer, Long, Float, Double et Date se comparent comme des valeurs ; String dans l'ordre de compareTo (casse comprise : les majuscules avant les minuscules) ; tout autre type, BigDecimal compris, comme du texte (voir Pièges). Une valeur null donne LOOKUP à null. The main flow column to classify. Byte, Short, Integer, Long, Float, Double and Date are compared as values; String in the compareTo order (case included: capitals before lowercase letters); any other type, BigDecimal included, as text (see Pitfalls). A null value gives LOOKUP set to null.
Colonne (LOOKUP)Column (LOOKUP)LOOKUP_COLUMN videempty Paramètres simplesBasic settings La colonne du Lookup dont la valeur, pour l'intervalle trouvé, est copiée dans LOOKUP. The Lookup column whose value, for the interval found, is copied into LOOKUP.
Colonne Lookup (min)Lookup Column (min)LOOKUP_MIN videempty Paramètres simplesBasic settings La colonne du Lookup qui donne la borne basse, du type de la colonne de recherche. Une borne null laisse l'intervalle ouvert de ce côté. The Lookup column that gives the lower bound, of the type of the search column. A null bound leaves the interval open on that side.
Inclure la borne (min)Include the bound (min)LOOKUP_MIN_BOUNDS OuiYes Paramètres simplesBasic settings Cochée : une valeur égale à la borne min est dans l'intervalle (>=). Décochée : elle n'y est pas (>). Checked: a value equal to the min bound is in the interval (>=). Unchecked: it is not (>).
Colonne Lookup (max)Lookup Column (max)LOOKUP_MAX videempty Paramètres simplesBasic settings La colonne du Lookup qui donne la borne haute, du même type. Une borne null laisse l'intervalle ouvert de ce côté. The Lookup column that gives the upper bound, of the same type. A null bound leaves the interval open on that side.
Inclure la borne (max)Include the bound (max)LOOKUP_MAX_BOUNDS NonNo Paramètres simplesBasic settings Cochée : une valeur égale à la borne max est dans l'intervalle (<=). Décochée : elle n'y est pas (<). Checked: a value equal to the max bound is in the interval (<=). Unchecked: it is not (<).

Variable globaleGlobal variable

NB_LINE (Integer, disponible après le composant) : le nombre de lignes du flux principal traitées, avec ou sans intervalle trouvé. NB_LINE (Integer, available after the component): the number of main flow rows processed, with or without an interval found.

((Integer) globalMap.get("tIntervalMatch_1_NB_LINE"))

ExemplesExamples

Deux tFixedFlowInput : sept personnes et leur âge, et trois tranches d'âge, données dans le désordre. Colonne de recherche : age ; bornes : min et max ; Colonne (LOOKUP) : label. Un tLogRow en mode tableau affiche le résultat ; un tJava relié par On Subjob Ok affiche NB_LINE. Sorties copiées depuis une exécution du job. Two tFixedFlowInput: seven people and their age, and three age ranges, given out of order. Search Column: age; bounds: min and max; Column (LOOKUP): label. A tLogRow in table mode prints the result; a tJava connected with On Subjob Ok prints NB_LINE. Outputs copied from a run of the job.

row1 (Main) row3 (Main) row2 (Lookup) tFixedFlowInput_1 tIntervalMatch_1 tLogRow_1 tFixedFlowInput_2

Flux principalMain flow

nameString ageInteger
Léa7
Tom0
Hugo18
Marc42
Anne65
Paul120
Zoénull

Lookup

minInteger maxInteger labelString
65120senior
018child
1865adult

Borne min incluse, max exclue (par défaut)Min bound included, max excluded (default)

18 est dans 18–65 et 65 dans 65–120 : chaque borne n'appartient qu'à un intervalle. 120, borne max exclue, n'est dans aucun : LOOKUP vaut null, comme pour l'âge inconnu de Zoé. 18 is in 18–65 and 65 in 65–120: each bound belongs to one interval only. 120, max bound excluded, is in none: LOOKUP is null, as for the unknown age of Zoé.

.----+---+------.
|   tLogRow_1   |
|=---+---+-----=|
|name|age|LOOKUP|
|=---+---+-----=|
|Léa |7  |child |
|Tom |0  |child |
|Hugo|18 |adult |
|Marc|42 |adult |
|Anne|65 |senior|
|Paul|120|null  |
|Zoé |null|null  |
'----+---+------'

tIntervalMatch_1_NB_LINE = 7

Les deux bornes inclusesBoth bounds included

120 trouve maintenant senior. Mais 18 et 65 sont chacun dans deux intervalles : le composant rend celui où sa dichotomie tombe d'abord, ici adult les deux fois : pour 18 le second des deux intervalles, pour 65 le premier. 120 now finds senior. But 18 and 65 are each in two intervals: the component returns the one its binary search hits first, here adult both times: for 18 the second of the two intervals, for 65 the first one.

.----+---+------.
|   tLogRow_1   |
|=---+---+-----=|
|name|age|LOOKUP|
|=---+---+-----=|
|Léa |7  |child |
|Tom |0  |child |
|Hugo|18 |adult |
|Marc|42 |adult |
|Anne|65 |adult |
|Paul|120|senior|
|Zoé |null|null  |
'----+---+------'

tIntervalMatch_1_NB_LINE = 7

Borne min exclue, max incluseMin bound excluded, max included

Les tranches deviennent ]0, 18], ]18, 65], ]65, 120] : 18 passe dans child, 65 dans adult, et 0 n'est plus dans aucune. The ranges become ]0, 18], ]18, 65], ]65, 120]: 18 moves to child, 65 to adult, and 0 is no longer in any.

.----+---+------.
|   tLogRow_1   |
|=---+---+-----=|
|name|age|LOOKUP|
|=---+---+-----=|
|Léa |7  |child |
|Tom |0  |null  |
|Hugo|18 |child |
|Marc|42 |adult |
|Anne|65 |adult |
|Paul|120|senior|
|Zoé |null|null  |
'----+---+------'

tIntervalMatch_1_NB_LINE = 7

Intervalles ouverts : bornes nullOpen intervals: null bounds

Lookup : null–18 child, 18–65 adult, 65–null senior ; réglages par défaut. Les âges de −3 et 130 trouvent une tranche. Lookup: null–18 child, 18–65 adult, 65–null senior; default settings. The ages −3 and 130 find a range.

.----+---+------.
|   tLogRow_1   |
|=---+---+-----=|
|name|age|LOOKUP|
|=---+---+-----=|
|Léa |7  |child |
|Ève |-3 |child |
|Paul|120|senior|
|Jean|130|senior|
'----+---+------'

tIntervalMatch_1_NB_LINE = 4

Intervalles de texteText intervals

Colonne de recherche surname (String) ; Lookup : "A"–"H" A-G, "H"–"P" H-O, "P"–"Z" P-Y. L'ordre est celui des caractères : hugo, en minuscules, vient après "Z" ; Zola aussi, et la borne max est exclue. Search column surname (String); Lookup: "A"–"H" A-G, "H"–"P" H-O, "P"–"Z" P-Y. The order is the one of the characters: hugo, lowercase, comes after "Z"; so does Zola, and the max bound is excluded.

.--+-------+------.
|    tLogRow_1    |
|=-+-------+-----=|
|id|surname|LOOKUP|
|=-+-------+-----=|
|a |Dupont |A-G   |
|b |Hugo   |H-O   |
|c |hugo   |null  |
|d |Martin |H-O   |
|e |Petit  |P-Y   |
|f |Zola   |null  |
'--+-------+------'

tIntervalMatch_1_NB_LINE = 6

Périodes de validitéValidity periods

Colonne de recherche day (Date) ; Lookup : du 2025-01-01 au 2026-01-01 2025 rate, à partir du 2026-01-01 (borne max null) 2026 rate. Borne max exclue : le 1er janvier 2026 n'a qu'un tarif. Search column day (Date); Lookup: from 2025-01-01 to 2026-01-01 2025 rate, from 2026-01-01 on (null max bound) 2026 rate. Max bound excluded: January 1st, 2026 has only one rate.

.--+----------+---------.
|       tLogRow_1       |
|=-+----------+--------=|
|id|day       |LOOKUP   |
|=-+----------+--------=|
|a |2025-12-31|2025 rate|
|b |2026-01-01|2026 rate|
|c |2026-07-14|2026 rate|
'--+----------+---------'

tIntervalMatch_1_NB_LINE = 3

Pièges et conseilsPitfalls and tips

Défaut du modèle : BigDecimal comparé comme du texteTemplate flaw: BigDecimal compared as text

Le modèle ne compare comme des nombres que Byte, Short, Integer, Long, Float et Double ; un BigDecimal est converti en texte (String.valueOf), et "5" vient après "10". Colonne de recherche amount (BigDecimal) ; Lookup : 0–10 small, 10–100 medium, 100–1000 large. Aucune valeur ne trouve sa tranche : The template compares as numbers only Byte, Short, Integer, Long, Float and Double; a BigDecimal is converted to text (String.valueOf), and "5" comes after "10". Search column amount (BigDecimal); Lookup: 0–10 small, 10–100 medium, 100–1000 large. No value finds its range:

.--+------+------.
|   tLogRow_1    |
|=-+------+-----=|
|id|amount|LOOKUP|
|=-+------+-----=|
|a |5     |null  |
|b |20    |null  |
|c |150   |null  |
|d |9.5   |null  |
'--+------+------'

tIntervalMatch_1_NB_LINE = 4

Convertissez la colonne de recherche et les bornes en Double avant le composant, avec un tConvertType par exemple. Convert the search column and the bounds to Double before the component, with a tConvertType for example.

Défaut du modèle : un Lookup vide arrête le jobTemplate flaw: an empty Lookup stops the job

Sans aucune ligne dans le Lookup, la recherche lit quand même le premier intervalle : la première ligne principale lève une exception et le job s'arrête avec le code 1 (trace abrégée) : With no row in the Lookup, the search still reads the first interval: the first main row throws an exception and the job stops with exit code 1 (trace shortened):

Exception in component tIntervalMatch_1 (JOB_DocBInterval6)
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
	at demo.job_docbinterval6_0_1.JOB_DocBInterval6$1Util_tIntervalMatch_1.getLookup(JOB_DocBInterval6.java:1676)
	at demo.job_docbinterval6_0_1.JOB_DocBInterval6.tFixedFlowInput_1Process(JOB_DocBInterval6.java:1840)

Si le Lookup peut être vide (table de référence pas encore remplie), chargez-le d'abord dans un tHashOutput, et ne lancez le sous-job du tIntervalMatch, qui le relit par un tHashInput, que si son NB_LINE est positif (lien Run if). If the Lookup may be empty (reference table not filled yet), first load it into a tHashOutput, and only start the subjob of the tIntervalMatch, which reads it again with a tHashInput, if its NB_LINE is positive (Run if link).

Des intervalles qui ne se chevauchent pasIntervals that do not overlap

La recherche par dichotomie rend un seul intervalle, sans ordre de préférence. Si une valeur peut tomber dans deux intervalles (bornes communes toutes deux incluses, tranches qui se recouvrent), le résultat dépend du nombre et de la place des intervalles. Gardez une borne incluse et l'autre exclue. The binary search returns a single interval, with no order of preference. If a value may fall into two intervals (shared bounds both included, overlapping ranges), the result depends on the number and place of the intervals. Keep one bound included and the other excluded.

Une seule valeur rendueOnly one value returned

Le composant ne rend qu'une colonne du Lookup. Pour en récupérer d'autres, rendez un identifiant de l'intervalle, puis joignez sur cet identifiant avec un tJoin. The component returns only one Lookup column. To get others, return an identifier of the interval, then join on this identifier with a tJoin.

Rapide sur un grand LookupFast on a large Lookup

Le Lookup est trié une fois ; chaque valeur principale n'en lit ensuite que quelques intervalles. Seule la mémoire limite sa taille : ne gardez que les trois colonnes utiles. The Lookup is sorted once; each main value then reads only a few of its intervals. Only memory limits its size: keep just the three useful columns.

Les valeurs hors de toute trancheValues outside any range

Elles sortent avec LOOKUP à null. Pour les mettre à part, filtrez ensuite sur LOOKUP == null avec un tFilterRow. They go out with LOOKUP set to null. To set them apart, then filter on LOOKUP == null with a tFilterRow.

Voir aussiSee also