简体   繁体   中英

Value to table header in Pentaho

Hi I'm quite new in Pentaho Spoon and I have a problem: I have a table like this:

model |  type | color| q 
--1---| --1-- | blue | 1 
--1---| --2-- | blue | 2 
--1---| --1-- | red  | 1
--1---| --2-- | red  | 3
--2---| --1-- | blue | 4
--2---| --2-- | blue | 5 

And I would like to create a single table (to export in csv or excel) for each model grouped by type with the value of the group as header and as value the q value:

table-1.csv

type | blue | red
--1--| -1-- | -1- 
--2--| -2-- | -3- 

table-2.csv

type |  blue 
--1--| -4- 
--2--| -5- 

I tried with row denormalizer but nothing. Any suggestion?

Typically it's helpful to see what you have done in order to offer help, but I know how counterintuitive the "help" on this step is.

Make sure you sort the rows on Model and Type before sending them to the denormalizer step. Then give this a try:

在此输入图像描述

As for splitting the output into files, there are a few ways to handle that. Take a look at the Switch/Case step using the Model field.

Also, if you haven't found them already, take a look at the sample files that come with the PDI download. They should be in ...pdi-ce-6.1.0.1-196\\data-integration\\samples. They can be more helpful than the online documentation sometimes.

Row denormalizer can't be used here if number of colors is unknown, also, you can't define text output fields dynamically.

There are few ways that I can see without using java and js steps. One of them is based on the following idea: we can prepare rows with two columns:

Row              Model
type|blue|red    1
1|1|1            1
2|2|3            1
type|blue        2
1|4              2
2|5              2

Then we can prepare filename for each row using Model field and then easily output all rows using text output where file name is taken from filename field. In this case all records will be exported into two files without additional efforts.

Here you can find sample transformation: copy-paste me into new transformation

Please note that it's a sample solution that works only with csv. Also it works only if you have the same number of colors for each type inside model. It's just a hint how to use spoon, it's not a complete solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM