在 Pentaho Data Integration 8 CE 中获取年份的最后一位数字

Get last digit of year in Pentaho Data Integration 8 CE

我有一个名为 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.access400(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.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.access400(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.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.access00(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.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.access00(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.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.access0(UnitCompiler.java:108)
2019/02/14 09:43:38 - Get last digit of month.0 -   at org.codehaus.janino.UnitCompiler.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.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

你把问题复杂化了。

在回答之前,记住一些事情,有几个步骤,以及步骤的组合,实现了令人难以置信的转换数量以制作可用的模式,最后的手段是用户定义的Java 表达式.

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

的新列