Pentaho数据集成-如何在筛选行步骤中使用用户定义的日期变量



如果有人能迅速回答这个问题,我将永远感激,哈哈。

我正在尝试过滤CSV文件中的所有数据,只查找日期早于6个月前的行。到目前为止,为了实现这一点,我创建了一个名为";sixMoDate";使用Pentaho中的以下步骤。目标是在"筛选行"步骤中使用此变量。

  1. 获取系统信息:Name-Today;类型-今天00:00:00
  2. 计算器:使用新字段常量";减去6";值为-6;今天"从前面的步骤和"0"的计算步骤;日期A+B月";以计算变量sixMoDate=";今天"+"减去6";。sixMoDate的值类型为Date
  3. 选择值:更改sixMoDate的元数据以确保值类型为Date。我知道这不应该是必需的,但正如你在下面看到的,这个变量似乎被视为字符串而不是日期,所以我把它放进去看看它是否能解决这个问题——它没有
  4. 设置变量

以上所有操作都能正确运行,甚至写入日志也会显示以正确日期格式写入的变量。然而,当我试图";获取变量";在链接转换中(稍后在"筛选行"步骤中使用(,我得到下面的错误日志(其中"类型"设置为"日期"。只有当"类型"被设置为"字符串"时,它才会运行而没有错误,但在筛选行步骤中,我得到的错误与我将字符串与筛选条件中的日期进行比较时相同。

2021/06/17 12:20:59 - Get variables.0 - ERROR (version 9.1.0.0-324, build 9.1.0.0-324 from 2020-09-07 05.09.05 by buildguy) : Unexpected error
2021/06/17 12:20:59 - Get variables.0 - ERROR (version 9.1.0.0-324, build 9.1.0.0-324 from 2020-09-07 05.09.05 by buildguy) : org.pentaho.di.core.exception.KettleValueException: 
2021/06/17 12:20:59 - Get variables.0 - SixMonthDate String(13) : couldn't convert string [$(SixMonthDate)] to a date using format [yyyy/MM/dd HH:mm:ss.SSS] on offset location 0
2021/06/17 12:20:59 - Get variables.0 - $(SixMonthDate)
2021/06/17 12:20:59 - Get variables.0 - 
2021/06/17 12:20:59 - Get variables.0 -     at org.pentaho.di.core.row.value.ValueMetaBase.convertStringToDate(ValueMetaBase.java:943)
2021/06/17 12:20:59 - Get variables.0 -     at org.pentaho.di.core.row.value.ValueMetaBase.getDate(ValueMetaBase.java:2306)
2021/06/17 12:20:59 - Get variables.0 -     at org.pentaho.di.core.row.value.ValueMetaBase.convertData(ValueMetaBase.java:3862)
2021/06/17 12:20:59 - Get variables.0 -     at org.pentaho.di.trans.steps.getvariable.GetVariable.processRow(GetVariable.java:109)
2021/06/17 12:20:59 - Get variables.0 -     at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
2021/06/17 12:20:59 - Get variables.0 -     at java.lang.Thread.run(Thread.java:748)
2021/06/17 12:20:59 - Get variables.0 - Caused by: java.text.ParseException: $(6MonthDate)
2021/06/17 12:20:59 - Get variables.0 -     at org.pentaho.di.core.row.value.ValueMetaBase.convertStringToDate(ValueMetaBase.java:934)
2021/06/17 12:20:59 - Get variables.0 -     ... 5 more

我尝试过:更改日期的格式、转换掩码、日期区域设置、时区;将变量获取为字符串,然后稍后在"选择值"步骤中使用元数据转换为日期(我得到相同的"无法将字符串[$(6MonthDate(]转换为使用格式[yyyy/MM/dd HH:MM:ss.SSS]的日期"(;错误(。

我浏览了每一篇关于基于环境变量过滤、设置/获取变量、将字符串转换为日期等的论坛帖子。我觉得解决方案必须是使用带有str2date((的修改后的Javascript值步骤,但由于某种原因,我无法实现这一点(我对Javascript有点陌生(。我在Javascript步骤var output = str2date(SixMonthDate, "MM/dd/yyyy")中尝试了这段代码,得到了以下错误:

2021/06/17 12:43:06 - Modified JavaScript value.0 - ERROR (version 9.1.0.0-324, build 9.1.0.0-324 from 2020-09-07 05.09.05 by buildguy) : Unexpected error
2021/06/17 12:43:06 - Modified JavaScript value.0 - ERROR (version 9.1.0.0-324, build 9.1.0.0-324 from 2020-09-07 05.09.05 by buildguy) : org.pentaho.di.core.exception.KettleValueException: 
2021/06/17 12:43:06 - Modified JavaScript value.0 - Javascript error: 
2021/06/17 12:43:06 - Modified JavaScript value.0 - Could not apply the given format MM/dd/yyyy on the string for Thu Dec 17 00:00:00 MST 2020 : Format.parseObject(String) failed (script#2)
2021/06/17 12:43:06 - Modified JavaScript value.0 - 
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:476)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.processRow(ScriptValuesMod.java:548)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at java.lang.Thread.run(Thread.java:748)
2021/06/17 12:43:06 - Modified JavaScript value.0 - Caused by: org.mozilla.javascript.EvaluatorException: Could not apply the given format MM/dd/yyyy on the string for Thu Dec 17 00:00:00 MST 2020 : Format.parseObject(String) failed (script#2)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:109)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.Context.reportRuntimeError(Context.java:945)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.Context.reportRuntimeError(Context.java:1001)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesAddedFunctions.str2date(ScriptValuesAddedFunctions.java:1049)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at java.lang.reflect.Method.invoke(Method.java:498)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:161)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:413)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:97)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.gen.script_5._c_script_0(script:2)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.gen.script_5.call(script)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3178)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.gen.script_5.call(script)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.mozilla.javascript.gen.script_5.exec(script)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     at org.pentaho.di.trans.steps.scriptvalues_mod.ScriptValuesMod.addValues(ScriptValuesMod.java:388)
2021/06/17 12:43:06 - Modified JavaScript value.0 -     ... 3 more

注意:我已经尝试确保指定的日期格式与源";字符串"正在按照这个线程的建议使用,但没有效果:如何在Pentaho中将字符串转换为日期类型?

请帮忙!!!

变量仅为字符串类型,因此在读取变量的链接转换中,您必须将该变量转换为日期。"设置变量"步骤的转换必须接收一个字符串值,该值的格式为您在链接转换中所期望的格式,以再次反转从字符串到日期的转换。

相关内容

  • 没有找到相关文章

最新更新