Converting rows to columns

 Overview

In this article you will learn how to convert rows to columns.

Environment

This procedure was written with:

  • Talend Open Studio for Date Integration release: 4.2.3
  • JDK version: Sun JDK build 1.6.0_26-b03
  • Operating system: Windows XP SP3

Talend verified this procedure to be compatible with:

  • Talend Open Studio for Date Integration release: 4.2.3, 4.2.4, 5.0, 5.0.2, 5.1.1, 5.1.2, 5.2.0

Example

In this procedure the following source file will be converted:

id question answer
1 Name Shong
2 Name Ross
3 Name Elise
1 Sex M
2 Sex M
3 Sex F
1 Surgery Yes
2 Surgery No
3 Surgery Yes

The rows are converted to columns as follows:

id;Name;Sex;Surgery
1;Shong;M;Yes
2;Ross;M;No
3;Elise;F;Yes

Procedure

First Step

Create a simple Job as seen below: 

 

The tPivotToColumnsDelimited is used to convert the rows to columns. It requires at least three columns in the input schema: the Pivot column, the Aggregation column and one or more Group keys.

Icon

This Job is also available in the attachments list.

 

Second Step

Execute the Job. The output file will be as follows:

id;Name;Sex;Surgery
1;Shong;M;Yes
2;Ross;M;No
3;Elise;F;Yes

It is not currently possible to output the result as a data flow that doesn't require an output file. If necessary you can use a tFileInputDelimited component to read the result back into the next Job from the output file created by tPivotToColumnsDelimited.

 Related Files

  File Modified
  ZIP Archive pivotrowstocolumnexample.zip Nov 19, 2012 byShicong Hong
Version History
Revision #:
1 of 1
Last update:
‎04-17-2017 07:30 PM
Updated by:
 
Labels (1)
Contributors