Newbie question about syntax documentation

One Star

Newbie question about syntax documentation

I've looked around and found the documentation for components but what about the syntax
for the talend functions in the expression builder? I can't find anything that lists the functions and their
syntax to know what goes in each parameter. The help box describes it but doesn't actually show the syntax.
If I understand correctly it's basically java if you choose that as your project language right?
Four Stars

Re: Newbie question about syntax documentation

Hello,
You can obtain a syntax example with a double click on the function in the expression builder.
Regards,
One Star

Re: Newbie question about syntax documentation

TalendString.talendTrim("",' ',0)
Here's what I get when I double click this function. Problem is how do I know what goes in the "", ' ', and what does 0 mean?
Some samples are more descriptive than others but I'm trying to find out if there's a reference for these in case some are overloaded
methods that I can take advantage of. Something like javadoc.
One Star

Re: Newbie question about syntax documentation

I have a field: '0001114444 Intralata'
I'm trying to trim the first part before the space into an output column for the phone number
and trim the last part after the space into an output column for the rate. talendTrim seems to fit this
description but I can't figure out how to use it.
Community Manager

Re: Newbie question about syntax documentation

Hello friend
try
String.substring(0,row1.columnName.indexOf(" "))     //for phone number

String.substring(row1.columnName.indexOf(" ")+1)     //for rate

Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Newbie question about syntax documentation

Thanks shong. I'll give that a shot.
But I guess my question still stands. Are those just java methods being called? Also, since there are talend methods in the expression builder where's the documentation of their syntax and variables?
Six Stars

Re: Newbie question about syntax documentation

It is just plain java: so you can use all the doc references available to java.
One Star

Re: Newbie question about syntax documentation

even for the talend methods and classes?
One Star

Re: Newbie question about syntax documentation

Cannot make a static reference to the non-static method substring(int, int) from the type String
I get this error Shong when I put that in the expression builder.
Community Manager

Re: Newbie question about syntax documentation

Hello
Cannot make a static reference to the non-static method substring(int, int) from the type String

What's your expression? It is just a java method beging called here...eg:
row1.name.substring(0,3) //name is a string
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Newbie question about syntax documentation

I was actually using the word "String1" in place of "row1.name". I should pay attention more than just copy and pasting. Smiley Happy
The job is having issues but I need to look at it some more before I post about it to make sure I'm asking the right questions.
One Star

Re: Newbie question about syntax documentation

Does this make any sense?
1) Get file via FTP.
2) If that's ok read from file
3) use javarow to remove errant newline character
4) output that to new csv file
5) starting with new csv file
6) use tmap to split columns, calculate 2 new columns via a routine
7) push result to mysql table
One Star

Re: Newbie question about syntax documentation

Hey there,
I am unsure of what you want your design to do exactly but here is a little fix:
Once you get all your files from the ftp, you must first iterate through the files and then read them. Furthermore, I dont think you need to save to file and then read from file unless you need those files later on?
TFTPGet -onOK->TFileList -iterate->TFileInputDelimited-row(main)->TJavaRow-row(main)->tMap-OTSCallDetail(main)->tMySQLOutput-onOk-> tMySQLCommit
Hope it helps.
One Star

Re: Newbie question about syntax documentation

Basically I'm trying to go through the seven steps I listed. I'm new to the program so I don't know which components to use in certain sitations yet. There's only one ftp file in this job so I don't think I'd neet to iterate through anything. There's a newline character that has to be removed that tjavarow is taking care of. I wasn't sure what components could or could not be linked to each other so I just broke it out a little more literally.
One Star

Re: Newbie question about syntax documentation

I modified my job at Wiktor's suggestion and I'm still bombing in the map.

LOG:
Starting job OTSImport at 13:32 02/09/2009.
connecting to socket on port 4055
connected
connecting to socket on port 4575
connected
For input string: "Dur."
Exception in component tMap_1
java.lang.NullPointerException
at otstest.otsimport_0_1.OTSImport.tFileInputDelimited_1Process(OTSImport.java:3452)
at otstest.otsimport_0_1.OTSImport.tFTPGet_1Process(OTSImport.java:436)
at otstest.otsimport_0_1.OTSImport.runJobInTOS(OTSImport.java:4528)
at otstest.otsimport_0_1.OTSImport.main(OTSImport.java:4430)
disconnected
disconnected
Job OTSImport ended at 13:32 02/09/2009.
BillCalc function (my java skills are rudimentary so don't laugh too hard when you read it):
package routines;
public class BillCalc {

public static int minutes(Integer duration) {
int rem = 0;
int min = 0;

if ((duration > 0) & (duration < 60))
{return 1;
}
else {
rem = duration % 60;
min = ((duration - rem)/60);
min += (rem >= 30)?1:0;
return min;
}
}

public static double revenue(Integer billminutes, String rate, String calltype){

double rev;
double debit_rate_interlata = 0.234;
double debit_rate_interstate = 0.387;
double debit_rate_intralata = 0.234;
double debit_rate_local = 0.234;
double nondebit_rate_interlata = 0.26;
double nondebit_rate_interstate = 0.43;
double nondebit_rate_intralata = 0.26;
double nondebit_rate_local = 0.26;
int debitchk, ratechk;

if (calltype.equalsIgnoreCase("Debit")) {debitchk = 1;}
else
debitchk = 0;

if (rate.equalsIgnoreCase("interlata")) {ratechk = 1;}
else if (rate.equalsIgnoreCase("interstate")) {ratechk = 2;}
else if (rate.equalsIgnoreCase("intralata")) {ratechk = 3;}
else ratechk = 4;



switch(debitchk){
case 1:
switch(ratechk){
case 1: rev = billminutes * debit_rate_interlata;
return rev;
case 2: rev = billminutes * debit_rate_interstate;
return rev;
case 3: rev = billminutes * debit_rate_intralata;
return rev;
case 4: rev = billminutes * debit_rate_local;
return rev;
}
case 0:
switch(ratechk){
case 1: rev = billminutes * nondebit_rate_interlata;
return rev;
case 2: rev = billminutes * nondebit_rate_interstate;
return rev;
case 3: rev = billminutes * nondebit_rate_intralata;
return rev;
case 4: rev = billminutes * nondebit_rate_local;
return rev;
}
}
return 0;
}
}
One Star

Re: Newbie question about syntax documentation

Map component
One Star

Re: Newbie question about syntax documentation

in a related story,
i get a null pointer exception any time i have a component mapped to the output of tmap.
There's something funny with my expressions or how I'm using tmap.
Community Manager

Re: Newbie question about syntax documentation

Hello guy
i get a null pointer exception any time i have a component mapped to the output of tmap.

You should check if there are some null value in some of columns, like row2.call, if so, you need handle the null value first, eg:
row2.call==null?value1Smiley Sadrow2.call.equalsIgnoreCase("complete")?value2:value3)
Aslo, I see you add a semicolon ';' at the end of some of expression, need remove it.
Best regards

shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: Newbie question about syntax documentation

row2.call==null?value1Smiley Sadrow2.call.equalsIgnoreCase("complete")?value2:value3)
when I use this statement it gives me an error about the word "null".
I tried using ISNULL() but it wants to create a method.
I tried using row2.call.equals(null) but it gives a compiler error saying 'null' can't be converted to boolean.
For fields that are empty in the csv file I suppose I need to insert a 0 to indicate false for the boolean value. Or I could
convert those fields to string and just string comparisons and put in true or false depending on the data.

Help?
One Star

Re: Newbie question about syntax documentation

"For input string: "Dur."
Exception in component tMap_1
java.lang.NullPointerException
at otstest.otsimport_0_1.OTSImport.tFileInputDelimited_1Process(OTSImport.java:3452)
at otstest.otsimport_0_1.OTSImport.tFTPGet_1Process(OTSImport.java:436)"
When you get this message, check the generated code of the job, line 3452, and you will know exactly which instruction to modify.
Then use the same syntax you've used for row2.call. Your syntax is right and should not give an error, however, you can try with (""+row2.call).equals("")?value1Smiley Sadrow2.call.equalsIgnoreCase("complete")?value2:value3)
One Star

Re: Newbie question about syntax documentation

Most recent error after removing semicolons per shong, but not checking null values yet. (i have all the columns set to nullable in tmap):
For input string: "Dur."
Exception in component tMap_1
java.lang.NullPointerException
at otstest.otsimport_0_1.OTSImport.tFileInputDelimited_1Process(OTSImport.java:3647)
at otstest.otsimport_0_1.OTSImport.tFTPGet_1Process(OTSImport.java:448)
at otstest.otsimport_0_1.OTSImport.runJobInTOS(OTSImport.java:4826)
at otstest.otsimport_0_1.OTSImport.main(OTSImport.java:4728)
3647: OTSCallDetail_tmp.Commission = OTSCallDetail.Revenue * .4;
448: tFileInputDelimited_1Process(globalMap);
4826: tFTPGet_1Process(globalMap);
4728: int exitCode = OTSImportClass.runJobInTOS(args);
Now looking at the code i see a potential problem in that Commission is a calculated value.
From the lines before 3647:
OTSCallDetail_tmp.Revenue = (row2.call2.equalsIgnoreCase("Complete")) ? routines.BillCalc.revenue
(OTSCallDetail.Minutes, OTSCallDetail.Rate, OTSCallDetail.call1): 0;
There's an underlined yellow error saying that OTSCallDetail can only be null at this location.
Am I missing something on calculating values? Can you not reference a value in the same output row?
I was thinking that it started with the first column of each row and did the processing so that by the time i get to the last
column i can reference the previous one for a calculation.
One Star

Re: Newbie question about syntax documentation

You cannot reference an output column in another output column. If you don't want to repeat the code, use tmap variables.
One Star

Re: Newbie question about syntax documentation

row2.call2.equalsIgnoreCase("Complete")

This kind of tests can become safe to null values this way :
"Complete".equalsIgnoreCase(row2.call2)

Because the String "Complete" will never null and the method equalsIngoreCase handle a null parameter.
One Star

Re: Newbie question about syntax documentation

ok. so if i need to calculate something I do it in a variable? the commission is based on revenue that's based on billable minutes that is calculated with a java routine.