PDI - 基于文件名中的日期的多个文件输入

PDI - Multiple file input based on date in filename

我正在使用 Kettle (PDI) 处理一个项目。 我必须输入多个 .csv 或 .xls 文件并将其插入数据库。

文件名为 AAMMDDBBBB,其中 AA 是城市代码,BBBB 是商店代码。 MMDD 是类似 MM-DD 的日期格式。例如 LA0326F5CA.csv.

我在输入文件步骤中使用的 Regexp 看起来像 LA.\*\.csvDT.*\.xls,即 return 所有要插入到数据库中的文件。

你能告诉我如何 select 昨天的文件(基于文件名的 MMDD)。

由于您在选择中需要一些 "complex" 逻辑,因此您不能仅基于正则表达式进行过滤。我建议您先读取所有文件名,然后根据文件名过滤文件名 "age",然后根据选定的文件名读取文件。

详细:

  1. Get File Names 步骤与您当前使用的相同正则表达式(LA.*\.csvDT.*\.xls)结合使用。在那个阶段,您可能会使用像 LA\d\d\d\d.....csv 这样的正则表达式来限制更多,以确保 MM 和 DD 是数字,而 DDDD 恰好是 4 个字符。

  2. 根据日期过滤。您可以使用 Java Filter 执行此操作,但使用 Javascript Script 计算文件的 "age" 然后使用 Filter rows 会容易一个数量级只保留昨天的文件。

    要计算文件的年龄,提取 MM 和 DD,您可以使用(其他方法可用):

    var regexp = filename.match(/..(\d\d)(\d\d).*/);
    if(regexp){
        var age = new Date() - new Date(2018, regexp[1], regexp[2]);
        age = age /1000 /60 /60 /24;
        };
    

If you are not familiar with Javascript regexp: the match will test the filename against the regexp and keep the values of the parenthesis in an array. If the test succeed (which you must explicitly check to avoid run time failure), use the values of the match to compute the corresponding date, and subtract the date of today to get the age. This age is in milliseconds, which is converted in days.

  1. 使用 Text File InputExcel Input 选项 Accept file from previous step。注意CSV Input没有这个选项,但是更强大的Text File Input有。

好吧,我用修改后的 Java 脚本值更改了 Java 过滤器,现在它可以正常工作了。 另一个问题,如何提高当前转换的性能和速度(现在我有 2 个城市的 2 个转换)?我的插入更新使我的转换变慢,需要将近 1 小时 30 分钟来处理 500k 行数据,其中包含大量字段 (300mb) 和我的数据不仅如此,如果它工作得更快并且我的公司喜欢使用它,我会用 10TB 的 data/years 及其大量的 trans 和行来完成。我需要关于它的建议