【问题标题】:Pentaho spoon transformation from excel file从excel文件转换Pentaho勺子
【发布时间】:2015-10-15 11:33:07
【问题描述】:

我的 excel 文件中有这样格式的年度数据:

Country \ Years   1980   1981   ...   2010
Abkhazia           234    334   ...    456
Afghanistan        466    789   ...    732
...

这是图片

我希望我的数据转换为 3 个不同的表并将其加载到 postgres 数据库。

表格应该是这样的

第一个表 - 国家:

id | name
1  | Abkhazia
2  | Afghanistan

二表日期:

id | date
1  | 1980
2  | 1981

第三个是根据国家和日期存储所有数据的表格:

country_id    date_id   data
         1          1    234
         1          2    334
         2          1    466
         2          2    789
       ...        ...    ...

有什么想法可以实现我的目标吗?

【问题讨论】:

  • 您的输入似乎不清楚。请告诉我实际的源文件结构。
  • @WorkingHard.. 嗨,我添加了截图,希望对您有所帮助

标签: postgresql pentaho etl kettle


【解决方案1】:

假设源excel结构如下(我已经定制了这个)

您的问题基本上有 3 个部分。为了更好地理解,我将转换分解为部分:

1.加载表 - 国家

根据 excel 中给出的数据,这非常简单。只需一个

Excel Input >> Add a sequence step. Give the Sequence name as Country ID >> Select only the Country Name and Country ID >> Load into the Country Table using Table Output.

2。加载表 - 年份:

这里的想法是以行格式显示年份 ID,而不是给定 excel 源数据的列。 PDI 5 及更高版本为您提供了一个非常有用的步骤,称为Metadata Structure。此步骤允许您获取表的结构。在这种情况下,我们需要拉出年份列,忽略国家列。

按照以下步骤操作:

Read the Excel Data >> Get the Metadata structure of your source >> Filter Out the Country Column (which is available in row at position=1) >> Add a Sequence Number. Name it YearID >> Finally Load the Year Table.

3.加载决赛桌 - 国家和年份以及数据:

在 PDI 中将所有列数据值显示到行级别的方法是使用Row Normalizer 步骤。使用此步骤显示标准化输出。现在按照以下步骤操作:

Read the Excel source data >> use Row Normalizer Step to normalize the rows based on the Years >> Do a Stream Lookup with the Above Country and Year tables to fetch the CountryID and YearID respectively >> Finally Load the necessary column data into Table Output

希望对你有帮助:)


我已将代码与我使用的数据文件一起放在 github repo 中。它的here

另外,刚刚意识到我根据您的问题给出了错误的命名约定。将 date_id 视为 YearID,而不是 id,我给出了 countryid 和 yearid。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-12-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 2020-05-15
    相关资源
    最近更新 更多