Five Stars

Using local variable in tmap expression builder

Hi,

I tried to create local variable(s) inside the expression builder, to get an array of strings as return value:

Kijelölés_015.png

 

As I just started using Talend, the idea above is not working.

Error messages:

  • Syntax error on tokens, ReferenceType expected instead  (mouse over the String[] text)
  • Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration (mouse over the numbers_strarray)

My questions:

  • is it possible to create a local variable somehow to be able to  write complex "scripts" instead of input field - output field?
  • if yes, where can I found working example/documentation of it or what to write in the example above to get it work?

I feel I really miss something trivial.

Thanks,

István

  • Data Integration
1 ACCEPTED SOLUTION

Accepted Solutions
Ten Stars

Re: Using local variable in tmap expression builder

For the complex scripts (and even complex data types) look at Routines. You can write your own Java classes and use with the expression builder. I have several tutorials of differing complexity on my website, but this one may be of interest for a simple example using a Routine (https://www.rilhia.com/tutorials/creating-random-test-data-using-talend-data-integration).

 

To do what you are trying to do, you need to think in a different way. In the expression builder, you can only use one line of Java code at a time. This makes it trickier to work with, but there are always workarounds (a Routine is a good workaround).  What you are trying to build is a String array. This might be tricky (impossible I would suggest) in the way you are trying it. But you can use a Routine for this OR use an ArrayList to achieve this. Talend actually implements a List data type which is essentially the java.util.List class.

 

Another thing I will suggest is that if you are new to Talend, maybe ask us about your requirement. A lot of the time there is a different way of solving a problem in Talend that new users do not realise. It might be that you are making this a little more complicated than it needs to be.  

 

 

Rilhia Solutions
6 REPLIES
Ten Stars

Re: Using local variable in tmap expression builder

Paging @rhall_2_0, will @rhall_2_0 please pick up a white courtesy phone...

Five Stars

Re: Using local variable in tmap expression builder - definition solved

I think, I will have to learn java, I cannot avoid it.

 

For the string array declaration/definition I already figured out, what is the right way:

 

String numbers_strarray[] = {"service1", row3.service1};

Regarding, how to return this array is still a question.

 

 

Nine Stars TRF
Nine Stars

Re: Using local variable in tmap expression builder - definition solved

Hi,

 

I've personaly never seen it before (not saying it's impossible).

Can you give us some information about your use case? 

What do you expect? How are the input data? What is the expected result?


TRF
Five Stars

Re: Using local variable in tmap expression builder - definition solved

Thank you TRF,

My post is a part of this use case:

Postgresql -> webservice (another post by me)

 

In short, I just learn Talend to replace old jitterbit, but until now I am on the beginning of the learning curve. With headache Smiley Happy

Ten Stars

Re: Using local variable in tmap expression builder

For the complex scripts (and even complex data types) look at Routines. You can write your own Java classes and use with the expression builder. I have several tutorials of differing complexity on my website, but this one may be of interest for a simple example using a Routine (https://www.rilhia.com/tutorials/creating-random-test-data-using-talend-data-integration).

 

To do what you are trying to do, you need to think in a different way. In the expression builder, you can only use one line of Java code at a time. This makes it trickier to work with, but there are always workarounds (a Routine is a good workaround).  What you are trying to build is a String array. This might be tricky (impossible I would suggest) in the way you are trying it. But you can use a Routine for this OR use an ArrayList to achieve this. Talend actually implements a List data type which is essentially the java.util.List class.

 

Another thing I will suggest is that if you are new to Talend, maybe ask us about your requirement. A lot of the time there is a different way of solving a problem in Talend that new users do not realise. It might be that you are making this a little more complicated than it needs to be.  

 

 

Rilhia Solutions
Five Stars

SOLVED - Re: Using local variable in tmap expression builder

Thank you very much for your hint rhall_2_0, it seems I have jitterbit-like expectations from the expression builder.

Anyway, writing own routines seems acceptable, which is a differrent approach, but it has benefits and acceptable Smiley Happy

As I already wrote some routines (I found them somewhere on the net), so, technically it is not a problem.

 

Regarding to my use case, please read the other post, where you can find the task to solve and my problem. This string array is only a little part of the task.

In the Jitterbit community edition I have problems with the utf-8 characters, but the xml structure handled well and it was not a big deal to populate the structure with data (except utf-8 issues).

Main problem is how to populate two stupid tree with dynamic data.

 

Anyway, I close this topic, as it already answered, thank you!