【问题标题】:Get last digit of year in Pentaho Data Integration 8 CE在 Pentaho Data Integration 8 CE 中获取年份的最后一位数字
【发布时间】:2019-02-15 01:02:17
【问题描述】:

我有一个名为 yearInteger 字段,其中包含当前年份:

2019

我想提取年份的最后一位数字。在这种情况下,9,输出将是 String(单个字符)。

我试过User defined Java Expression如下:

Integer.toString(year).substring(Integer.toString(year).length() - 1)

但它给出了以下错误。 我怎样才能得到年份的最后一位数字?

2019/02/14 09:43:38 - Get last digit of month.0 - ERROR (version 8.2.0.0-342, build 8.2.0.0-342 from 2018-11-14 10.30.55 by buildguy) : Unexpected error
2019/02/14 09:43:38 - Get last digit of month.0 - ERROR (version 8.2.0.0-342, build 8.2.0.0-342 from 2018-11-14 10.30.55 by buildguy) : org.pentaho.di.core.exception.KettleException: 
2019/02/14 09:43:38 - Get last digit of month.0 - org.pentaho.di.core.exception.KettleValueException: 
2019/02/14 09:43:38 - Get last digit of month.0 - org.codehaus.janino.CompileException: Line 1, Column 17: No applicable constructor/method found for actual parameters "java.lang.Long"; candidates are: "java.lang.String java.lang.Integer.toString(int, int)", "java.lang.String java.lang.Integer.toString()", "java.lang.String java.lang.Integer.toString(int)", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()"
2019/02/14 09:43:38 - Get last digit of month.0 - Line 1, Column 17: No applicable constructor/method found for actual parameters "java.lang.Long"; candidates are: "java.lang.String java.lang.Integer.toString(int, int)", "java.lang.String java.lang.Integer.toString()", "java.lang.String java.lang.Integer.toString(int)", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()"
2019/02/14 09:43:38 - Get last digit of month.0 - 
2019/02/14 09:43:38 - Get last digit of month.0 - 
2019/02/14 09:43:38 - Get last digit of month.0 - org.codehaus.janino.CompileException: Line 1, Column 17: No applicable constructor/method found for actual parameters "java.lang.Long"; candidates are: "java.lang.String java.lang.Integer.toString(int, int)", "java.lang.String java.lang.Integer.toString()", "java.lang.String java.lang.Integer.toString(int)", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()"
2019/02/14 09:43:38 - Get last digit of month.0 - Line 1, Column 17: No applicable constructor/method found for actual parameters "java.lang.Long"; candidates are: "java.lang.String java.lang.Integer.toString(int, int)", "java.lang.String java.lang.Integer.toString()", "java.lang.String java.lang.Integer.toString(int)", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()"
2019/02/14 09:43:38 - Get last digit of month.0 - 
2019/02/14 09:43:38 - Get last digit of month.0 - 
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.pentaho.di.trans.steps.janino.Janino.processRow(Janino.java:113)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.pentaho.di.trans.step.RunThread.run(RunThread.java:62)
2019/02/14 09:43:38 - Get last digit of month.0 -   at java.lang.Thread.run(Unknown Source)
2019/02/14 09:43:38 - Get last digit of month.0 - Caused by: org.pentaho.di.core.exception.KettleValueException: 
2019/02/14 09:43:38 - Get last digit of month.0 - org.codehaus.janino.CompileException: Line 1, Column 17: No applicable constructor/method found for actual parameters "java.lang.Long"; candidates are: "java.lang.String java.lang.Integer.toString(int, int)", "java.lang.String java.lang.Integer.toString()", "java.lang.String java.lang.Integer.toString(int)", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()"
2019/02/14 09:43:38 - Get last digit of month.0 - Line 1, Column 17: No applicable constructor/method found for actual parameters "java.lang.Long"; candidates are: "java.lang.String java.lang.Integer.toString(int, int)", "java.lang.String java.lang.Integer.toString()", "java.lang.String java.lang.Integer.toString(int)", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()"
2019/02/14 09:43:38 - Get last digit of month.0 - 
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.pentaho.di.trans.steps.janino.Janino.calcFields(Janino.java:220)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.pentaho.di.trans.steps.janino.Janino.processRow(Janino.java:104)
2019/02/14 09:43:38 - Get last digit of month.0 -   ... 2 more
2019/02/14 09:43:38 - Get last digit of month.0 - Caused by: org.codehaus.janino.CompileException: Line 1, Column 17: No applicable constructor/method found for actual parameters "java.lang.Long"; candidates are: "java.lang.String java.lang.Integer.toString(int, int)", "java.lang.String java.lang.Integer.toString()", "java.lang.String java.lang.Integer.toString(int)", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()", "java.lang.String java.lang.Object.toString()"
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compileError(UnitCompiler.java:8185)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:6052)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:5923)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:5862)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:4424)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.access$11400(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler$16.visitMethodInvocation(UnitCompiler.java:4066)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2649)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:4086)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:5862)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.getType2(UnitCompiler.java:4424)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.access$11400(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler$16.visitMethodInvocation(UnitCompiler.java:4066)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2649)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.getType(UnitCompiler.java:4086)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.findMostSpecificIInvocable(UnitCompiler.java:6028)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:5923)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.findIMethod(UnitCompiler.java:5862)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compileGet2(UnitCompiler.java:3124)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.access$6300(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler$10.visitMethodInvocation(UnitCompiler.java:2579)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Java$MethodInvocation.accept(Java.java:2650)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compileGet(UnitCompiler.java:2599)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compileGetValue(UnitCompiler.java:3535)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:1439)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.access$1700(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler$4.visitReturnStatement(UnitCompiler.java:748)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Java$ReturnStatement.accept(Java.java:1665)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:758)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:777)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.access$700(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler$4.visitBlock(UnitCompiler.java:738)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Java$Block.accept(Java.java:1280)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:758)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:1783)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:723)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compileDeclaredMethods(UnitCompiler.java:705)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:431)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile2(UnitCompiler.java:329)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler$3.visitPackageMemberClassDeclaration(UnitCompiler.java:302)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Java$PackageMemberClassDeclaration.accept(Java.java:703)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compile(UnitCompiler.java:308)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.compileUnit(UnitCompiler.java:286)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.SimpleCompiler.compileToClassLoader(SimpleCompiler.java:420)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.ClassBodyEvaluator.compileToClass(ClassBodyEvaluator.java:400)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:607)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.ScriptEvaluator.cook(ScriptEvaluator.java:443)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Cookable.cook(Cookable.java:72)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Cookable.cook(Cookable.java:64)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.Cookable.cook(Cookable.java:114)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.pentaho.di.trans.steps.janino.Janino.calcFields(Janino.java:171)
2019/02/14 09:43:38 - Get last digit of month.0 -   ... 3 more

【问题讨论】:

    标签: pentaho kettle pentaho-data-integration


    【解决方案1】:

    你把问题复杂化了。

    在回答之前,请记住一些事情,有几个步骤和步骤组合,可以实现数量惊人的转换以形成可用的模式,最后的手段是用户定义的 Java 表达式

    使用 Select Values 步骤将整数转换为字符串,然后使用 Formula 步骤使用代码 RIGHT([year]; 1).

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-06
      • 1970-01-01
      • 2016-01-26
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      • 2013-06-13
      相关资源
      最近更新 更多