How do I concatenate string in Pentaho spoon?
Asked Answered
L

2

7

I am a newbie to Pentaho (installed today). I was able to do basic transformation in 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

http://api.app.com/app/api/v1/feature/fbhjgjhgj87687jghgj88jgjj

What do I need to do in Spoon to get this done?

Also, data return will be in json format. how do I parse that?

Leverett answered 19/9, 2012 at 9:21 Comment(0)
O
9

You should first get your input with a CSV File Input using | as delimiter. Then you can get the 3rd field as a string.

Next you probably need to remove all spaces from this string with a String operations step. Look at the Remove special character column, and select space.

Then you need to concatenate it with your http address http://api.app.com/app/api/v1/feature/. For this you'll use a Calculator step. 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). At the Field A column you'll write your http address. 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).

Now on the same Calculator step create another field, let's say MyAddress, with operation A+B. Choose for Field A the field tmpAddr you just created, and for Field B the 3rd field from your input.

Now on your stream you should have the full address as a field MyAddress. Connect a REST client step. Mark Accept URL from field and choose field MyAddress as URL Field Name. Set Application Type to JSON. Set Result Fieldname as MyResult.

If you need further JSON parsing you can add a Json input step. Set Source is defined in a field and select field MyResult as Get Source from field.

Orle answered 19/9, 2012 at 12:19 Comment(1)
Great. Excellent step by step explanation and it worked like a charm :)Leverett
D
2

An alternate approach is to use the "Replace in String" step to append the string.

  1. Set 'use RegEx' to Y
  2. Set 'Search' to (.*)
  3. Set 'Replace with' to http://api.app.com/app/api/v1/feature/$1
  4. Set 'Whole Word' to Y

The parentheses in the regex set up a capture group that you can then insert into your replacement string with the $X syntax

Dismuke answered 8/3, 2013 at 20:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.