[英]How do I concatenate string in Pentaho spoon?
I am a newbie to Pentaho (installed today). 我是Pentaho的新手(今天安装)。 I was able to do basic transformation in Spoon. 我能够在Spoon中进行基本的转换。 Now I need to do some stuff, which I can't figure out how. 现在我需要做一些事情,我无法弄明白。
my input looks like 我的输入看起来像
2012-09-17|garima|fbhjgjhgj87687jghgj88jgjj|garima#1347868164626|::ffff:120.56.132.137
3rd field is an ID, for which I need to get some information from a REST API 第3个字段是一个ID,我需要从REST API获取一些信息
http://api.app.com/app/api/v1/feature/fbhjgjhgj87687jghgj88jgjj
What do I need to do in Spoon to get this done? 为了完成这项工作,我需要在Spoon中做些什么?
Also, data return will be in json format. 此外,数据返回将采用json格式。 how do I parse that? 我该如何解析?
You should first get your input with a CSV File Input
using |
您应首先使用|
CSV File Input
as delimiter. 作为分隔符。 Then you can get the 3rd field as a string. 然后你可以将第3个字段作为字符串。
Next you probably need to remove all spaces from this string with a String operations
step. 接下来,您可能需要使用String operations
步骤从此字符串中删除所有空格。 Look at the Remove special character
column, and select space
. 查看Remove special character
列,然后选择space
。
Then you need to concatenate it with your http address http://api.app.com/app/api/v1/feature/
. 然后,您需要将其与您的http地址http://api.app.com/app/api/v1/feature/
连接起来。 For this you'll use a Calculator
step. 为此,您将使用Calculator
步骤。 At this step first create a new temporary field tmpAddr
, with operation Define a constant value for ...
(or something like this, sorry my spoon is in portuguese). 在这一步,首先创建一个新的临时字段tmpAddr
,操作Define a constant value for ...
(或类似的东西,对不起,我的勺子是葡萄牙语)。 At the Field A
column you'll write your http address. 在Field A
列中,您将编写您的http地址。 It's a good practice, after you make this work, to set your address as a system variable so if it changes you don't need to replace it everywhere on your transformations (look at menu Edit -> System Variables
). 在完成这项工作后,将您的地址设置为系统变量是一个很好的做法,因此如果它发生变化,您无需在变换的任何地方替换它(请查看菜单Edit -> System Variables
)。
Now on the same Calculator
step create another field, let's say MyAddress
, with operation A+B
. 现在在同一个Calculator
步骤中创建另一个字段,假设MyAddress
,操作A+B
Choose for Field A
the field tmpAddr
you just created, and for Field B
the 3rd field from your input. 选择Field A
您刚刚创建的字段tmpAddr
,为Field B
选择输入的第3个字段。
Now on your stream you should have the full address as a field MyAddress
. 现在在您的流上,您应该将完整的地址作为字段MyAddress
。 Connect a REST client
step. 连接REST client
步骤。 Mark Accept URL from field
and choose field MyAddress
as URL Field Name
. Accept URL from field
标记Accept URL from field
并选择字段MyAddress
作为URL Field Name
。 Set Application Type
to JSON
. 将Application Type
设置为JSON
。 Set Result Fieldname
as MyResult
. 将Result Fieldname
设置为MyResult
。
If you need further JSON parsing you can add a Json input
step. 如果需要进一步的JSON解析,可以添加Json input
步骤。 Set Source is defined in a field
and select field MyResult
as Get Source from field
. Set Source is defined in a field
并选择字段MyResult
作为Get Source from field
。
An alternate approach is to use the "Replace in String" step to append the string. 另一种方法是使用“替换字符串”步骤来附加字符串。
(.*)
将“搜索”设置为(.*)
http://api.app.com/app/api/v1/feature/$1
将“替换为”设置为http://api.app.com/app/api/v1/feature/$1
The parentheses in the regex set up a capture group that you can then insert into your replacement string with the $X syntax 正则表达式中的括号设置了一个捕获组,然后您可以使用$ X语法将其插入到替换字符串中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.