ETL - 如何将 table 标题作为字段值添加到 Pentaho Spoon 中的每一行

ETL - How to add table titles as field values to every following row in Pentaho Spoon

我是 Pentaho Spoon(K​​ettle)的新手,有以下任务:

有一个excel table,它可能是这样的:

history class
name      first name    id
Doe       John          213
Muster    Max           118
biology class
name      first name    id
Parker    Peter         844

问题是一个 xls-file 里面实际上有更多的 table。在此示例中,历史专业 class 和生物学专业 class.

的学生 table

我需要的输出:所有学生的 table 每个学生都有一个新字段,上面写着 class 他是哪个学生的一部分。示例:

name      first name   id        class
Doe       John         213       history class
Muster    Max          118       history class
Parker    Peter        884       biology class

(我的例子被极度简化了)

如何将输入 table 转换为输出 table? 感谢您的帮助!

在 pentaho 中,您通常无法用多个表解析 excel。 IE。最好的方法是为不同的表设置多个 sheet。

如果不可能,那么至少有两个选择:

  1. 查找最大列数并手动指定列为字符串类型(因为一列的内容可能不同——数字、字符串等),然后根据一些规则解析行
  2. 使用 POI 提取 sheet 内容到文本 - new XSSFExcelExtractor(new XSSFWorkbook(new File(fileName))).getText() - 然后使用 [=51= 解析它].

这是选项 1。对于您的简单案例:

  1. Excel 输入字段(header 未选中!):

  1. 添加包含当前 class 名称的 className 字段的 JS 步骤:

第二步后的结果:

  1. 最后一步 - 我们过滤掉 header 行(即名字为空或 = "first name".

结果: