Talend- 使用 tmap 组件解析日期时的空字符串处理

Talend- Empty string handling when parsing dates using tmap component

我的工作是将 CSV 加载到 MySQL table。我使用 t-map 组件与日期配对的字段中有一些记录为空字符串。在将字符串解析为日期时,我需要将那些空字符串转换为当前日期。我已经在 tmap 组件中尝试过这个表达式,但没有成功。我的字段名称是 "Payroll_Pay_Date" 这是表达式:

row1.Payroll_Pay_Date equals("")?TalendDate.getCurrentDate():TalendDate.parseDate("MM/dd/yyyy",row1.Payroll_Pay_date)

我已经尝试了几次迭代。实际上,我真正想要的是用 "current date - 7 days" 替换空字符串,但我想我会从上面开始。任何建议将不胜感激。

你可以这样做:

row1.Payroll_Pay_Date == null ||  row1.Payroll_Pay_Date.trim().isEmpty() ? TalendDate.getCurrentDate() : TalendDate.parseDate("MM/dd/yyyy",row1.Payroll_Pay_date)

在这里,我首先测试字符串是否为空,或者它是否为空或仅包含空格,在这种情况下,我 return 当前日期。否则我解析日期。

要使当前日期减去 7 天,您可以这样做:

TalendDate.addDate(TalendDate.getCurrentDate(), -7, "dd")