ComposantsComponents › TraitementProcessing
Trie un flux avec un programme sort extérieur à Java : le composant écrit les lignes dans un fichier délimité, lance la commande sort de GNU sur ce fichier, puis relit le fichier trié. Il suppose une commande sort de GNU ; sous Windows, celle du système ne convient pas, et le composant ne le signale pas (voir l'exemple).
Sorts a flow with a sort program outside Java: the component writes the rows to a delimited file, runs the GNU sort command on this file, then reads the sorted file back. It assumes a GNU sort command; on Windows, the system one does not suit, and the component does not report it (see the example).
EntréeInput
Main un fluxone flow
SortieOutput
Main un flux : les lignes relues du fichier triéone flow: the rows read back from the sorted file
Déclencheurs en sortieOutput triggers
On Component Ok On Component Error Run if
Dans le code généré, le composant devient deux composants : In the generated code, the component becomes two components:
tExternalSortRow_1_ESO écrit chaque ligne dans un fichier temporaire : les valeurs telles quelles, séparées par le séparateur de champs, une ligne terminée par \r\n, une valeur nulle écrite vide. À la fin du flux, il lance sort sur ce fichier, attend sa fin, et recopie dans la console ce que la commande écrit.
tExternalSortRow_1_ESO writes each row to a temporary file: the values as they are, separated by the field separator, a row ended with \r\n, a null value written empty. At the end of the flow, it runs sort on this file, waits for its end, and copies to the console what the command writes.
tExternalSortRow_1_FID, un tFileInputDelimited, relit le fichier trié (Nom de fichier) avec le schéma et le séparateur du composant, ses autres réglages restant ceux par défaut, dont l'encodage ISO-8859-15.
tExternalSortRow_1_FID, a tFileInputDelimited, reads the sorted file (File name) back with the schema and the separator of the component, its other settings being the default ones, including the ISO-8859-15 encoding.
La commande lancée, d'après le code généré pour le premier exemple (dossier de travail remplacé par C:/work) :
The command run, from the code generated for the first example (working folder replaced with C:/work):
String[] sb_tExternalSortRow_1_ESO = new String[] {
"sort",
"--buffer-size="+"200M",
"--field-separator="+";",
"--key=3,3",
"--key=4,4rn",
"--output="+"C:/work/extsort/default.txt",
""+tempFile_tExternalSortRow_1_ESO.getAbsolutePath()+""
};
sort de GNU dans Chemin de la commande externe "sort", par exemple celui que livre Git for Windows : "C:/Program Files/Git/usr/bin/sort.exe" (GNU coreutils 8.32 dans nos essais).
On Windows, give a GNU sort in External command "sort" path, for example the one shipped with Git for Windows: "C:/Program Files/Git/usr/bin/sort.exe" (GNU coreutils 8.32 in our tests).
tExternalSortRow_1_FID_NB_LINE : à 0, la commande a échoué (voir Variables globales).
After the job, check tExternalSortRow_1_FID_NB_LINE: at 0, the command failed (see Global variables).
Les libellés sont ceux de l'onglet Composant ; le nom technique, en gris, est celui du paramètre dans le fichier du job. Les chemins sont des expressions Java : gardez les guillemets. Labels are those of the Component tab; the technical name, in grey, is the parameter name in the job file. The paths are Java expressions: keep the quotes.
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| SchémaSchemaSCHEMA | — | ToujoursAlways | Les colonnes du flux, reprises du lien entrant. Il sert à l'écriture du fichier temporaire comme à la relecture du fichier trié ; donnez un modèle aux colonnes Date, utilisé dans les deux sens. The flow columns, taken from the incoming link. It is used to write the temporary file as well as to read the sorted file back; give a pattern to the Date columns, used both ways. |
| Nom de fichierFile nameFILENAME | chemin par défaut + /sorted.txtdefault path + /sorted.txt |
ToujoursAlways |
Le fichier trié, écrit par sort (--output=) puis relu. S'il n'existe pas, le composant crée son dossier et un fichier vide dès le début du job : si la commande échoue, il reste vide. Écrivez le chemin avec des / (voir Pièges).
The sorted file, written by sort (--output=) then read back. If it does not exist, the component creates its folder and an empty file at the start of the job: if the command fails, it stays empty. Write the path with / (see Pitfalls).
|
| Séparateur de champsField SeparatorFIELDSEPARATOR | ";" |
ToujoursAlways |
Placé entre les valeurs, passé à sort (--field-separator=) et à la relecture. Un seul caractère : sort refuse les autres. Les valeurs ne sont ni entre guillemets ni protégées : une valeur qui contient le séparateur ou un retour à la ligne décale les colonnes à la relecture.
Put between the values, passed to sort (--field-separator=) and to the reading. A single character: sort refuses the others. The values are neither quoted nor escaped: a value that contains the separator or a line break shifts the columns when read back.
|
| Chemin de la commande externe "sort"External command "sort" pathSORT_CMDPATH | videempty | ToujoursAlways |
Le programme lancé, entre guillemets. Vide, le code lance sort : sous Windows, c'est C:\Windows\System32\sort.exe, qui ne comprend pas les options de GNU (exemple). Un chemin qui n'existe pas arrête le job.
The program run, in quotes. Empty, the code runs sort: on Windows, this is C:\Windows\System32\sort.exe, which does not understand the GNU options (example). A path that does not exist stops the job.
|
| CritèresCriteriaCRITERIA | videempty | ToujoursAlways |
Une ligne par colonne de tri, dans l'ordre d'importance : Colonne du schéma, Type de tri (num par défaut, ou alpha) et Ordre (asc par défaut, ou DESC). Chaque ligne devient une option --key=N,N, N étant la position de la colonne dans le schéma, suivie de r pour desc et de n pour num. Il n'y a pas de tri par date : alpha sur une date suit le texte de son modèle.
One line per sort column, in order of importance: Schema column, Sort type (num by default, or alpha) and Order (asc by default, or desc). Each line becomes a --key=N,N option, N being the position of the column in the schema, followed by r for desc and n for num. There is no date sort: alpha on a date follows the text of its pattern.
|
| ParamètreSetting | DéfautDefault | VisibleShown | Description |
|---|---|---|---|
| Mémoire maximaleMaximum memoryMAX_MEMORY | "200M" |
ToujoursAlways |
La mémoire de la commande sort, passée telle quelle (--buffer-size=) : la syntaxe est celle de sort ("10M", "1G"…). Elle ne touche pas la mémoire du job.
The memory of the sort command, passed as it is (--buffer-size=): the syntax is the sort one ("10M", "1G"…). It does not affect the job memory.
|
| Répertoire temporaireTemporary directoryTEMP_DIR | videempty | ToujoursAlways |
Le dossier des fichiers de travail de sort (--temporary-directory=). Vide, l'option n'est pas passée et sort choisit.
The folder of the work files of sort (--temporary-directory=). Empty, the option is not passed and sort chooses.
|
| Définir un répertoire temporaire de fichiers d'entréeSet temporary input file directorySET_INPUT_TEMP_DIR | NonNo | ToujoursAlways |
Décochée, le fichier temporaire des lignes à trier est créé dans le dossier temporaire du système (tExternalSortRow_1_ESO…tmp). Cochée, dans le dossier du champ voisin, sans libellé (INPUT_TEMP_DIR, visible case cochée), qui doit exister : sinon le job s'arrête avant la première ligne (java.io.IOException levée par File.createTempFile). Dans les deux cas, le fichier est supprimé à la fin du job.
Unchecked, the temporary file of the rows to sort is created in the system temporary folder (tExternalSortRow_1_ESO…tmp). Checked, in the folder of the next field, without a label (INPUT_TEMP_DIR, shown with the box checked), which must exist: otherwise the job stops before the first row (java.io.IOException raised by File.createTempFile). In both cases, the file is deleted at the end of the job.
|
| Ajouter une fin de ligne facticeAdd a dummy EOF lineADD_EOF | NonNo | ToujoursAlways |
Ajoute après le tri une ligne à la fin du fichier trié. Ses valeurs, d'après le modèle : le MIN_VALUE de Java pour Integer, Long, Short, Byte (leur plus petite valeur), Float et Double (leur plus petit nombre positif) ; false pour un booléen, T pour un caractère ; rien pour les autres types (textes, dates, BigDecimal…). Elle est relue comme les autres et sort dans le flux (exemple).
Adds after the sort a line at the end of the sorted file. Its values, per the template: the Java MIN_VALUE for Integer, Long, Short, Byte (their smallest value), Float and Double (their smallest positive number); false for a boolean, T for a character; nothing for the other types (texts, dates, BigDecimal…). It is read back like the others and leaves in the flow (example).
|
Les jobs ont été exécutés dans Talaxie (Java 21), sous Windows 11. Un tFixedFlowInput envoie les sept lignes ci-dessous au tExternalSortRow, suivi d'un tLogRow en mode simple ; un tJava relié par On Subjob Ok affiche ensuite les variables globales. Sorties copiées depuis la console : Talaxie y met entre crochets, devant un message qu'un composant écrit sur la sortie d'erreur, le nom de ce composant. Sauf mention, seules les lignes du tLogRow sont reprises. Le nom du job est remplacé par MyJob, le dossier de travail par C:\work, les traces sont abrégées.
The jobs were run in Talaxie (Java 21), on Windows 11. A tFixedFlowInput sends the seven rows below to the tExternalSortRow, followed by a tLogRow in basic mode; a tJava connected with On Subjob Ok then prints the global variables. Outputs copied from the console: Talaxie puts there in brackets, in front of a message that a component writes on the error output, the name of this component. Unless stated, only the tLogRow lines are shown. The job name is replaced with MyJob, the working folder with C:\work, the traces are shortened.
| idInteger | nameString | cityString | amountInteger |
|---|---|---|---|
| 1 | Léa | Lyon | 30 |
| 2 | adam | Paris | 5 |
| 3 | Bob | Lyon | 120 |
| 4 | Zoé | null | 30 |
| 5 | eve | Paris | null |
| 6 | élise | Lyon | 30 |
| 7 | Chloé | Paris | 9 |
Critères city alpha asc, amount num desc. Windows lance son propre sort.exe, qui prend les options de GNU pour des noms de fichiers et répond « Fichier d’entrée spécifié deux fois. » dans le jeu de caractères de la console Windows, d'où les �. Le job se termine sans erreur, le fichier trié est vide et aucune ligne ne sort. Console complète :
Criteria city alpha asc, amount num desc. Windows runs its own sort.exe, which takes the GNU options for file names and answers “Input file specified twice.” (in French here) in the character set of the Windows console, hence the �. The job ends without an error, the sorted file is empty and no row leaves. Full console:
[tExternalSortRow_1_ESO] Fichier d�entr�e sp�cifi� deux fois. [tExternalSortRow_1_ESO] [tExternalSortRow_1_ESO] tExternalSortRow_1_NB_LINE = null Global variables: 2 tExternalSortRow_1_ESO_NB_LINE = 7 tExternalSortRow_1_FID_NB_LINE = 0
Même résultat avec "C:/Windows/System32/sort.exe" indiqué en clair.
Same result with "C:/Windows/System32/sort.exe" given explicitly.
Mêmes critères, Chemin de la commande externe "sort" : "C:/Program Files/Git/usr/bin/sort.exe". L'ordre est juste : la ville vide d'abord, Lyon par montant décroissant, puis Paris, le montant vide en dernier. Mais les lettres accentuées sont abîmées à la relecture (voir Pièges) :
Same criteria, External command "sort" path: "C:/Program Files/Git/usr/bin/sort.exe". The order is right: the empty city first, Lyon by descending amount, then Paris, the empty amount last. But the accented letters are damaged when read back (see Pitfalls):
4|Zoé||30 3|Bob|Lyon|120 1|Léa|Lyon|30 6|élise|Lyon|30 7|Chloé|Paris|9 2|adam|Paris|5 5|eve|Paris|
Le fichier trié, lui, est juste (UTF-8, lignes terminées par \r\n) :
The sorted file itself is right (UTF-8, lines ended with \r\n):
4;Zoé;;30 3;Bob;Lyon;120 1;Léa;Lyon;30 6;élise;Lyon;30 7;Chloé;Paris;9 2;adam;Paris;5 5;eve;Paris;
name alpha asc. La commande hérite de l'environnement du job. Sans variable LANG ni LC_ALL, le cas courant sous Windows, sort compare les octets : majuscules d'abord, élise en dernier.
name alpha asc. The command inherits the job environment. Without a LANG or LC_ALL variable, the usual case on Windows, sort compares the bytes: upper case first, élise last.
3|Bob|Lyon|120 7|Chloé|Paris|9 1|Léa|Lyon|30 4|Zoé||30 2|adam|Paris|5 5|eve|Paris| 6|élise|Lyon|30
Le même job, avec la variable d'environnement LANG=fr_FR.UTF-8 définie avant de lancer Talaxie : l'ordre du dictionnaire.
The same job, with the LANG=fr_FR.UTF-8 environment variable set before starting Talaxie: the dictionary order.
2|adam|Paris|5 3|Bob|Lyon|120 7|Chloé|Paris|9 6|élise|Lyon|30 5|eve|Paris| 1|Léa|Lyon|30 4|Zoé||30
Les mêmes lignes envoyées à l'envers (7 à 1), critère city alpha asc. Les trois lignes de Lyon arrivent dans l'ordre 6, 3, 1 et sortent dans l'ordre 1, 3, 6 : sort départage les égalités en comparant les lignes entières, ici par leur id, au début de la ligne. Le tSortRow, lui, garde l'ordre d'arrivée.
The same rows sent in reverse (7 to 1), criterion city alpha asc. The three Lyon rows arrive in the order 6, 3, 1 and come out in the order 1, 3, 6: sort breaks the ties by comparing the whole lines, here by their id, at the start of the line. The tSortRow keeps the order of arrival.
4|Zoé||30 1|Léa|Lyon|30 3|Bob|Lyon|120 6|élise|Lyon|30 2|adam|Paris|5 5|eve|Paris| 7|Chloé|Paris|9
amount num asc, Ajouter une fin de ligne factice cochée. La ligne ajoutée (-2147483648;;;-2147483648 dans le fichier) devient une huitième ligne du flux. Console complète :
amount num asc, Add a dummy EOF line checked. The added line (-2147483648;;;-2147483648 in the file) becomes an eighth row of the flow. Full console:
5|eve|Paris| 2|adam|Paris|5 7|Chloé|Paris|9 1|Léa|Lyon|30 4|Zoé||30 6|élise|Lyon|30 3|Bob|Lyon|120 -2147483648|||-2147483648 tExternalSortRow_1_NB_LINE = null Global variables: 2 tExternalSortRow_1_ESO_NB_LINE = 7 tExternalSortRow_1_FID_NB_LINE = 8
Ici, le montant vide d'eve passe avant 5 (sort -n). Avec Mémoire maximale à "10M", un Répertoire temporaire et un répertoire de fichiers d'entrée choisis, le tri sans ligne factice donne les sept mêmes premières lignes, et les deux dossiers sont vides après le job.
Here, eve's empty amount comes before 5 (sort -n). With Maximum memory at "10M", a Temporary directory and an input file directory chosen, the sort without dummy line gives the same first seven rows, and both folders are empty after the job.
Le composant déclare NB_LINE, que la liste des variables propose, mais tExternalSortRow_1_NB_LINE n'est jamais rempli et vaut null (défaut du composant, constaté avec Talaxie 9.0.6). Les deux parties du composant rangent leurs propres compteurs, Integer, disponibles après le composant :
The component declares NB_LINE, which the variable list offers, but tExternalSortRow_1_NB_LINE is never filled and is null (component defect, found with Talaxie 9.0.6). The two parts of the component store their own counters, Integer, available after the component:
tExternalSortRow_1_ESO_NB_LINE : les lignes écrites dans le fichier à trier ;
tExternalSortRow_1_ESO_NB_LINE: the rows written to the file to sort;
tExternalSortRow_1_FID_NB_LINE : les lignes relues du fichier trié, donc envoyées dans le flux. Différent du premier, il signale un échec de la commande (0) ou une ligne factice (+1).
tExternalSortRow_1_FID_NB_LINE: the rows read back from the sorted file, so sent in the flow. Different from the first one, it signals a failure of the command (0) or a dummy line (+1).
Le tJava des exemples affiche tExternalSortRow_1_NB_LINE, puis toutes les variables dont le nom commence par tExternalSortRow_1 :
The tJava of the examples prints tExternalSortRow_1_NB_LINE, then all the variables whose name starts with tExternalSortRow_1:
System.out.println("tExternalSortRow_1_NB_LINE = " + globalMap.get("tExternalSortRow_1_NB_LINE"));
java.util.List<String> keys = new java.util.ArrayList<String>();
for (Object k : globalMap.keySet()) {
if (String.valueOf(k).startsWith("tExternalSortRow_1")) keys.add(String.valueOf(k));
}
java.util.Collections.sort(keys);
System.out.println("Global variables: " + keys.size());
for (String k : keys) System.out.println(k + " = " + globalMap.get(k));
Le fichier à trier est écrit dans l'encodage par défaut de Java, UTF-8 avec Java 21 et dans les jobs lancés par Talaxie ; la relecture se fait en ISO-8859-15, que le composant ne permet pas de changer. Chaque lettre accentuée devient deux caractères (é → é), comme dans les exemples. Défaut du composant, constaté avec Talaxie 9.0.6. Avec une ancienne version de Java sous un Windows occidental, l'encodage par défaut était proche de l'ISO-8859-15 (non vérifié). Pour des textes accentués, préférez le tSortRow et son tri sur le disque.
The file to sort is written in the Java default encoding, UTF-8 with Java 21 and in the jobs run by Talaxie; the reading is done in ISO-8859-15, which the component does not let you change. Each accented letter becomes two characters (é → é), as in the examples. Component defect, found with Talaxie 9.0.6. With an older Java version on a Western Windows, the default encoding was close to ISO-8859-15 (not checked). For accented texts, prefer the tSortRow and its sort on disk.
sort n'arrête pas le jobA sort error does not stop the job
Le composant ne lit pas le code de retour de la commande : comme pour le sort de Windows, une erreur de sort s'écrit dans la console et le job continue avec un fichier vide. Séparateur "||", avec le sort de GNU. Console complète :
The component does not read the return code of the command: as for the Windows sort, a sort error is written in the console and the job goes on with an empty file. Separator "||", with GNU sort. Full console:
[tExternalSortRow_1_ESO] /usr/bin/sort: multi-character tab '||' tExternalSortRow_1_NB_LINE = null Global variables: 2 tExternalSortRow_1_ESO_NB_LINE = 7 tExternalSortRow_1_FID_NB_LINE = 0
Nom de fichier écrit "C:\\work\\extsort\\backslash.txt", fichier encore absent : pour créer son dossier, le composant coupe le chemin au dernier /, qu'il ne trouve pas. Le job s'arrête avant la première ligne (133 : la longueur du chemin réel de l'essai, abrégé ici en C:\work).
File name written "C:\\work\\extsort\\backslash.txt", file not there yet: to create its folder, the component cuts the path at the last /, which it does not find. The job stops before the first row (133: the length of the real path of the test, shortened here to C:\work).
Exception in component tExternalSortRow_1_ESO (MyJob) java.lang.StringIndexOutOfBoundsException: Range [0, -1) out of bounds for length 133 … at java.base/java.lang.String.substring(String.java:2823) at demo.myjob_0_1.MyJob.tFixedFlowInput_1Process(MyJob.java:1288) …
Écrivez les chemins avec des /, qui marchent aussi sous Windows ; un nom de fichier seul, sans dossier, a le même problème.
Write the paths with /, which also work on Windows; a file name alone, without a folder, has the same problem.
Chemin de la commande externe "sort" : "C:/nowhere/sort.exe". Là, le job s'arrête ; le message du système est celui d'un Windows en français.
External command "sort" path: "C:/nowhere/sort.exe". There, the job stops; the system message is the one of a French Windows.
Exception in component tExternalSortRow_1_ESO (MyJob) java.io.IOException: Cannot run program "C:/nowhere/sort.exe": CreateProcess error=2, Le fichier spécifié est introuvable at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1170) …
La commande n'est pas lancée avec --stable : les lignes égales sur les critères sont rangées par la ligne entière, pas par leur ordre d'arrivée. Ajoutez un dernier critère qui les départage, ou prenez le tSortRow.
The command is not run with --stable: the rows equal on the criteria are ordered by the whole line, not by their order of arrival. Add a last criterion that breaks the ties, or take the tSortRow.
Une valeur nulle est écrite vide : elle se trie comme un texte vide, donc en premier en alpha asc, et avant les nombres positifs en num. À la relecture, un texte vide et une nulle ne se distinguent plus dans le tLogRow.
A null value is written empty: it is sorted as an empty text, so first in alpha asc, and before the positive numbers in num. When read back, an empty text and a null can no longer be told apart in the tLogRow.
Il sert surtout sur un serveur Linux, où sort est en général celui de GNU (non essayé ici), pour des volumes que la mémoire du job ne tiendrait pas. Le tSortRow avec Trier sur le disque fait le même travail en Java, sans programme extérieur ni problème d'encodage.
It is mostly useful on a Linux server, where sort is usually the GNU one (not tried here), for volumes the job memory would not hold. The tSortRow with Sort on disk does the same work in Java, without an external program or an encoding problem.
Le fichier à trier est supprimé à la fin du job, le fichier trié non : il est remplacé à l'exécution suivante. Supprimez-le au besoin avec un tFileDelete. The file to sort is deleted at the end of the job, the sorted file is not: it is replaced at the next run. Delete it if needed with a tFileDelete.
tSortRow · trier en Java, en mémoire ou sur le disquesort in Java, in memory or on disktFileInputDelimited · la relecture du fichier triéthe reading of the sorted filetSystem · lancer une commande du systèmerun a system commandtAggregateSortedRow · regrouper un flux déjà triégroup a flow already sortedtLogRow · afficher les lignes d'un fluxdisplay the rows of a flow