One Star

how to give column names through context

hi,
I have one tfileinputdelimit--->tjavaflex
tfileinputdelimit has columns id,name,age,amt.
i have to add "amt" column data to a list in a generalized way. that means by entering column name through context, we should get a resultant list contains the values of column "amt"( which is specified through context variable).
now i am doing like this,
inside of tjavaflex
---------------------
list1.add(row1.amt);
but, instead of this column name "amt" should be given through context parameter, such that resultant list contains "amt" column data.
can any one suggest me how to achieve it?
9 REPLIES
Community Manager

Re: how to give column names through context

Hi
What's the data type of context parameter now? String? Let's assume it is a string type,
define a context variable called name, set its default value as ""
context.name=context.name+","+row1.arm
For use later, we can normalize the context.name.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: how to give column names through context

hi,
thanks for quick reply.
But my requirement is, user has to give column name through context parameter, he don't want to hard code column name like "row1.amt" in job.
by giving column name like "amt" in context parameter, amt column data has to be added to a list.
please suggest a way to do it?
One Star

Re: how to give column names through context

hi,
can any one please lookinto this, as it is urgent.
how to compare two diiferent columns from two different files in a generalized way without hard coding the column names in job like row1.amt.
on just giving the column names through context, the comparision has to be happen.
One Star

Re: how to give column names through context

hi,
can any one please look into the issue.
it is urgent.
One Star

Re: how to give column names through context

You probably have to play with the Java Reflections class for this...
http://tutorials.jenkov.com/java-reflection/fields.html
Community Manager

Re: how to give column names through context

Hi
Please have a look at this topic, I showed how to get the column name through Java reflections class.
http://www.talendforge.org/forum/viewtopic.php?id=6441
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: how to give column names through context

hi,
thanks for reply.
but my question is I am having one tfileinputdelimited---->tjavaflex
inside tjavaflex
java.util.list list1=new java.util.ArrayList();
list1.add(row1.amt)
this coding will add the "amt" column values to a list called list1.
But how we can make it in generalize way with out hard coding the line "row1.amt"?
Is it possible to give this "row1.amt" through context?
As per your suggestion above, we will get column names but how to pass the column names to "row1.amt"?
please provide a sample job which will does it.
thanks,
Community Manager

Re: how to give column names through context

Hi
Because you only want to add the column name into the list, there should be at least and only one row.
String columnName=null;
java.lang.reflect.Field field[]= row1.getClass().getDeclaredFields();
for(int i=2;i<field.length;i++){
columnName=field.getName().toLowerCase();
System.out.println(columnName);
list.add(columnName);
}

For more information, please see my screenshot.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
One Star

Re: how to give column names through context

hi,
thanks for sending jobs.
but, here my requirement is not to add column name to a list.
adding column values( column data) to the list.
In sample job, you are adding column name to a list.But I want to add column content to a list.
Is there any way to do it?