Component |
Processing/Fields |
|
Function |
tWriteDynamicFields creates an output |
|
Purpose |
tWriteDynamicFields allows you to |
|
Basic |
Schema and |
A schema is a row description, it defines Since version 5.6, both the Built-In mode and the Repository mode are Click Edit schema to make changes to the schema. If the
Click Sync |
|
|
Built-in: |
|
|
Repository: |
Advanced |
tStatCatcher |
Select this check box to gather the Job |
Global Variables |
ERROR_MESSAGE: the error message generated by the NB_LINE: the number of rows read by an input component or 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 |
|
Usage |
This component handles flow of data |
|
Log4j |
The activity of this component can be logged using the log4j feature. For more information on this feature, see Talend Studio User For more information on the log4j logging levels, see the Apache documentation at http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/Level.html. |
|
Limitation |
n/a |
This Java scenario contains five components. It aims at creating a Dynamic
type column from a schema and extracting the columns contained in this
dynamic column. These transformation results are displayed into the
console.
-
From the Palette to
the design workspace, drag and drop the following
components:– a tRowGenerator to
generate a flow containing customer information,– a tWriteDynamicFields to replace columns
with a Dynamic column,– two tLogRow to
display the results into the console,– a tExtractDynamicFields to extract
content from the dynamic column. -
Connect tRowGenerator
to tWriteDynamicFields using a Row > Main link. -
Connect tWriteDynamicFields to the first
tLogRow using a
Row >
Main link. -
Connect tLogRow to
tExtractDynamicFields using a
Row >
Main link. -
Connect tExtractDynamicFields to the second
tLogRow using a
Row >
Main link. -
Rename both tLogRow
by double-clicking them.Type in their new name,
dynamicColumn and
standard column
respectively.
-
In the design workspace, double-click the tRowGenerator to open its
editor. -
Click seven times on the [+] button to add seven columns to the
schema. Name them id,
firstName,
lastName,
street,
city,
States and
otherData,
respectively. -
In the Type column,
select Integer for
id and String for all other fields.In the Functions
columns, select the function you want to
apply to each column in the schema.Click OK to validate
the configuration and close the editor.A pop-up window opens and asks you to propagate the
changes. Click Yes. -
In the design workspace, double-click tWriteDynamicFields
component to display its Basic
settings view.Click the […]
button next to Edit
schema to set the schema of the
component. -
In the schema editor, click on
otherData column, then click to add the column on the output
side.This way, the column will be displayed in the output,
but it will not be included into the dynamic
column. -
Click the [+] button
in the output area to add a column.Name it columnDynamic and set
its Type to
Dynamic.Warning
The dynamic column must be defined
in the last row of the schema.Warning
The column names must be exactly the
same on both sides of the editor, otherwise the
output columns will not be
recognised. -
Click OK to validate
your changes and close the editor.Warning
The dynamic schema
feature is only supported in Built-In mode.All columns that are not in the output area in the
editor will be included into the dynamic
column. -
In the design workspace, double-click the first
tLogRow to
display its Basic
settings view.In the Mode area,
select the Table (print value
in cells of a table) option. -
In the design workspace, double-click tWriteDynamicFields
component to display ots Basic
settings view.Click the […]
button next to Edit
schema. -
Select in the left area the columns you want to add to
the tExtractDynamicFields schema and click
the button to copy them.Click OK to close the
editor. -
In the design workspace, double-click the tExtractDynamicFields
component to display its Basic
settings view.Click the […]
button next to Edit
schema.In the schema editor, click the button in the output area to
paste the columns copied from tWriteDynamicFields component.In the input area, click the Dynamic column and click
the button to add the dynamic
column to the output schema.Click OK to validate
your changes and close the editor. -
In the design workspace, double-click the second
tLogRow to
display its Basic
settings view. -
In the Mode area,
select Table (print value in
cells of a table) option.
-
Press Ctrl+S to save
the Job. -
Press F6 to execute
it.The first tLogRow
component displays in the console the dynamic column
in addition to the otherData
column you have already defined in the output schema
of the tWriteDynamicFields component.The second tLogRow
displays in the console all the extracted columns
(id,
firstName and
lastName) from the dynamic
one, the otherData column that
has not been included into the dynamic column and
the dynamic column which still contains all columns
voluntarily not extracted.
In this scenario, a dynamic column is created via tWriteDynamicFields and its contents are then extracted
by the customized code in tJavaRow.
-
Drop tFixedFlowInput,
tWriteDynamicFields, tLogRow and tJavaRow onto the
workspace. -
Link tFixedFlowInput
to tWriteDynamicFields using the
Row > Main connection. -
Link tWriteDynamicFields to tLogRow using the Row > Main connection.
-
Link tLogRow to
tJavaRow using
the Row > Main connection.
-
Double-click tFixedFlowInput to open its Basic settings view.
-
Select Use Inline Content
(delimited file) in the Mode area. -
In the Content field,
enter the data to pass to tWriteDynamicFields, for
example:121;Andy;Doc2;Anderson;Dev -
Click the Edit schema
button to open the schema editor. -
Click the [+] button
to add three columns, namely id, name, and dept, of the Integer and String types
respectively. -
Click OK to validate
the setup and close the editor. -
Double-click tWriteDynamicFields to open its
Basic settings
view. -
Click the Edit schema
button to open the schema editor. -
Click the [+] button
in the right panel to add two columns, namely
id and
dynamic, of the
Integer and Dynamic types respectively.The column id
contains the value of the column id from tFixedFlowInput and the
column dynamic
contains the values of the columns name and dept from tFixedFlowInput. -
Click OK to validate
the setup and close the editor. -
Double-click tLogRow
to open its Basic
settings view.Select Table (print values in
cells of a table) for a better display
of the results. -
Double-click tJavaRow
to open its Basic
settings view. -
In the Code field,
enter the Java code to extract the contents of the
dynamic column dynamic:1234567Dynamic columns = row3.dynamic;for (int i = 0; i < columns.getColumnCount(); i++) {DynamicMetadata columnMetadata = columns.getColumnMetadata(i);System.out.println(columnMetadata.getName() + ": " +columns.getColumnValue(i) + "; " + columnMetadata.getType());}The dynamic column dynamic of the flow row3 is specified for
retrieving the names, values and types of columns
that it contains.