Pentaho 数据集成 从 DB 导入大型数据集 [英] Pentaho Data Integration Import large dataset from DB

查看:52
本文介绍了Pentaho 数据集成 从 DB 导入大型数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将大量数据从一个数据库导入到另一个数据库(MSSQL 到 MySQL).转换执行以下操作:获取数据的子集,通过检查哈希来检查它是更新还是插入,映射数据并使用 API 调用将其插入到 MySQL 数据库中.目前的子集部分是严格手动的,有没有办法设置 Pentaho 为我做,有点迭代.我用来获取子集的查询是

I'm trying to import a large set of data from one DB to another (MSSQL to MySQL). The transformation does this: gets a subset of data, check if it's an update or an insert by checking hash, map the data and insert it into MySQL DB with an API call. The subset part for the moment is strictly manual, is there a way to set Pentaho to do it for me, kind of iteration. The query I'm using to get the subset is

select t1.* 
from (
    select *, ROW_NUMBER() as RowNum over (order by id)
    from mytable
) t1 
where RowNum between @offset and @offset + @limit;

有没有办法让 PDI 可以设置偏移量并重申整个?

Is there a way that PDI can set the offset and reiterate the whole?

谢谢

推荐答案

您可以(尽管有警告)在父作业中创建一个循环,在 Javascript 步骤中的每次迭代中增加偏移变量.我使用这样的设置来使用具有未知数量结果的网络服务,每次获得完整页面后都会移动偏移量,并在获得较少时停止.

You can (despite the warnings) create a loop in a parent job, incrementing the offset variable each iteration in a Javascript step. I've used such a setup to consume webservices with an unknown number of results, shifting the offset each time I after get a full page and stopping when I get less.

设置变量

在作业属性中,定义参数 Offset 和 Limit,因此您可以(重新)从任何偏移量开始,甚至从具有特定偏移量和限制的命令行调用作业.也可以通过变量步骤来完成,但参数可以完成所有相同的事情,而且您可以为测试设置默认值.

In the job properties, define parameters Offset and Limit, so you can (re)start at any offset even invoke the job from the commandline with specific offset and limit. It can be done with a variables step too, but parameters do all the same things plus you can set defaults for testing.

转换中的处理

主转换应该启用将参数值传递给子转换",这是默认设置.

在转换内部(见图像的下半部分),您从使用变量替换的表输入开始,将 ${Offset} 和 ${Limit} 放在您有 @offset 和 @limit 的位置.

Inside the transformation (see lower half of the image) you start with a Table Input that uses variable substitution, putting ${Offset} and ${Limit} where you have @offset and @limit.

来自表输入的流然后进入处理,但也被复制到分组依据步骤以对行进行计数.将组字段留空并创建一个对所有行进行计数的字段.选中该框以始终返回结果行.

The stream from Table Input then goes to processing, but also is copied to a Group By step for counting rows. Leave the group field empty and create a field that counts all rows. Check the box to always give back a result row.

将流从 Group By 发送到 Set Variables 步骤,并在父作业的范围内设置 NumRows 变量.

Send the stream from Group By to a Set Variables step and set the NumRows variable in the scope of the parent job.

循环往复

在主要工作中,从转换到简单评估步骤,将 NumRows 变量与限制进行比较.如果 NumRows 小于 ${Limit},则您已到达最后一批,成功!

In the main job, go from the transformations to a Simple Evaluation step to compare the NumRows variable to the Limit. If NumRows is smaller than ${Limit}, you've reached the last batch, success!

如果没有,继续执行 Javascript 步骤以增加偏移量,如下所示:

If not, proceed to a Javascript step to increment the Offset like this:

var offset = parseInt(parent_job.getVariable("Offset"),0);
var limit = parseInt(parent_job.getVariable("Limit"),0);
offset = offset + limit;
parent_job.setVariable("Offset",offset);
true;

然后作业流程继续执行虚拟步骤,然后再次使用新的偏移值进行转换.

The job flow then proceeds to the dummy step and then the transformation again, with the new offset value.

注意事项

  • 与转换不同,您可以在同一作业中设置和使用变量.
  • JS 步骤需要true;"作为最后一条语句,以便向作业报告成功.

这篇关于Pentaho 数据集成 从 DB 导入大型数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆