|
Component Family |
Custom Code |
|
|
Function |
tJavaRow allows you to enter |
|
|
Purpose |
tJavaRow allows you to broaden |
|
|
Basic settings |
Schema and Edit |
A schema is a row description. It defines the number of fields to be processed and passed on Since version 5.6, both the Built-In mode and the Repository mode are This component offers the advantage of the dynamic schema feature. This allows you to This dynamic schema feature is designed for the purpose of retrieving unknown columns |
|
|
|
Built-In: You create and store the schema locally for this |
|
|
|
Repository: You have already created the schema and When the schema to be reused has default values that are integers or functions, ensure that For more details, see https://help.talend.com/display/KB/Verifying+default+values+in+a+retrieved+schema. |
|
Click Edit schema to make changes to the schema. If the
Click Sync columns to retrieve the schema from the |
||
|
|
Code |
Enter the Java code to be applied to each line of the data |
|
Advanced settings |
Import |
Enter the Java code required to import, if required, the external |
|
|
tStatCatcher Statistics |
Select this check box to collect the log data at a component |
|
Global Variables |
NB_LINE: the number of rows read by an input component or ERROR_MESSAGE: the error message generated by the A Flow variable functions during the execution of a component while an After variable To fill up a field or expression with a variable, press Ctrl + For further information about variables, see Talend Studio To enter a global variable (for example COUNT of |
|
|
Usage |
This component is used as an intermediary between two other |
|
|
Limitation |
Knowledge of Java language is necessary. |
|
In this scenario, the information of a few cities read from an input delimited file is
transformed using Java code through the tJavaRow
component and printed on the console.

-
Drop a tFileInputDelimited component and
a tJavaRow component from the Palette onto the design workspace, and label them
to better identify their roles in the Job. -
Connect the two components using a Row >
Main connection.
-
Double-click the tFileInputDelimited
component to display its Basic settings
view in the Component tab.
-
In the File name/Stream field, type in
the path to the input file in double quotation marks, or browse to the path
by clicking the […] button, and define
the first line of the file as the header.In this example, the input file has the following content:
123456City;Population;LandArea;PopDensityBeijing;10233000;1418;7620Moscow;10452000;1081;9644Seoul;10422000;605;17215Tokyo;8731000;617;14151New York;8310000;789;10452 -
Click the […] button next to Edit
schema to open the [Schema] dialog box, and
define the data structure of the input file. Then, click OK to validate the schema setting and close the
dialog box.
-
Double-click the tJavaRow component to
display its Basic settings view in the
Component tab.
-
Click Sync columns to make sure that the
schema is correctly retrieved from the preceding component. -
In the Code field, enter the code to be
applied on each line of data based on the defined schema columns.In this example, we want to transform the city names to upper case, group
digits of numbers larger than 1000 using the thousands separator for ease of
reading, and print the data on the console:12345678910111213System.out.print("" + input_row.City.toUpperCase() + ":");System.out.print("- Population: "+ FormatterUtils.format_Number(String.valueOf(input_row.Population), ',', '.') + " people");System.out.print("- Land area: "+ FormatterUtils.format_Number(String.valueOf(input_row.LandArea), ',', '.')+ " km2");System.out.print("- Population density: "+ FormatterUtils.format_Number(String.valueOf(input_row.PopDensity), ',', '.') + " people/km2");Note
In the Code field, input_row refers to the link that connects to
tJavaRow.
This scenario describes a three-component Job that uses Java code through a tJavaRow component to display the content of an input file
and pass it to the output component. As all the components in this Job support the
dynamic schema feature, we can leverage this feature to save the time of configuring
each column of the schema.
-
Drop tFileInputDelimited, tJavaRow, and tFileOutputDelimited from the Palette onto the design workspace, and label them according
to their roles in the Job. -
Connect the components in a series using Row > Main links.

-
Double-click the tFileInputDelimited
component, which is labeled Source, to
display its Basic settings view.
Warning
The dynamic schema feature is only supported in Built-In mode and requires the input file
to have a header row. -
In the File name/Stream field, type in
the path to the input file in double quotation marks, or browse to the path
by clicking the […] button. -
In the Header field, type in 1 to define the first line of the file as the
header. -
Click the […] button next to Edit schema to open the [Schema] dialog box.

-
Click the [+] button to add a column,
give a name to the column, dyna in this
example, and select Dynamic from the
Type list. This dynamic column will
retrieve the three columns, FirstName,
LastName and Address, of the input file. -
Click OK to validate the setting and
close the dialog box. -
Double-click the tFileOutputDelimited
component, which is labeled Target, to
display its Basic settings view.
-
Define the output file path in the File
Name field. -
Select the Include Header check box to
include the header in the output file. Leave all the other settings are they
are.
-
Double-click tJavaRow to display its
Basic settings view and define the
components properties.
-
Click Sync columns to make sure that the
schema is correctly retrieved from the preceding component. -
In the Code field, enter the following
code to display the content of the input file and pass the data to the next
component based on the defined dynamic schema column:12System.out.println(input_row.dyna);output_row.dyna = input_row.dyna;Note
In the Code field, input_row and output_row correspond to the links to and from tJavaRow.

