如何使用Talend仅处理过去一小时的文件?

时间:2017-08-07 15:08:55

标签: talend

我每隔5分钟就会以文件的形式传输连续的传感器数据。我想只选择过去一小时的文件并进行必要的处理。 例如:talend作业在下午12:01运行,它仅从上午11:00到中午12:00选择所有文件。

任何人都可以建议我应该采取的方法,以便在talend内实现这一目标。是否有任何内置组件可以选择前一小时的文件?

这是流程。 enter image description here

enter image description here

enter image description here

enter image description here

2 个答案:

答案 0 :(得分:2)

使用tFileProperties,您将获得名为mstring_name的内置模式。通过使用此列,您将获得文件的最后修改时间,在tJava或tJavaRow中,您可以使用talendDate函数检查此时间是否在过去一小时之间

enter image description here

迭代所有文件,并在tJavaRow中编写此代码:

Date lastModifiedDate = TalendDate.parseDate("EEE MMM dd HH:mm:ss zzz yyyy", input_row.mtime_string);

Date current_date = TalendDate.getCurrentDate();


if(TalendDate.diffDate(current_date, lastModifiedDate,"HH") <= 1) {

output_row.abs_path = input_row.abs_path;
}

通过这个,您将获得过去一小时之间的所有文件。

希望这会有所帮助..

这是完整的工作设计:

tFileList ---&gt;(iterate)----&gt; tFileProperties ----&gt;(row1 main)----&gt; tJavaRow ----&gt; if ----&gt; tFileInputDelimited ----&GT;主-----&GT; TMAP ----&GT;主-----&GT; tFileOutput

您正在设置tJavaRow的上下文,在if条件中检查其可为空性:

context.getProperty(&#34; file&#34;)!= null&amp;&amp; !context.getProperty(&#34;文件&#34)。的isEmpty()

在此之后使用上下文

答案 1 :(得分:0)

没有内置组件可以根据时间为您提供文件。

但是,您可以使用tFileList - &gt; tFileProperties来完成此操作。配置tFileList按上次修改日期排序,然后tFileProperties将为您提供修改日期。从那里,您可以根据日期值进行过滤 - 如果超过一小时,则停止,否则进行处理。