You are not logged in.

Unanswered posts

Important! This site has been replaced. All content here is read-only. Please visit our brand-new community at We look forward to hearing from you there!

#1 2008-02-07 14:12:08

2 posts

bse said:

Convert field value

Hi All,
Thank in advance for helping us resolve the following issue.
In our POC project, we must take the value of a product weight from source table and store it in destination table after some conversion. The schema of the source and destination table structure is given below with sample records. The weight unit in the source table given by the “WEIGHT_UNIT_OF_MEASURE” field can have the following values: “Kilogram”, “Centigram” or “Milligram”.
In the destination table the corresponding is “WEIGHT_IN_KILOGRAM” and weight is always expressed in “Kilogram”.

Source Table:
A; 5; Kilogram
B; 45; Milligram
C; 30; Centigram

Destination Table
A; 5
B; 0.045,
C; 0.30

The issue can be expressed in pseudo code as follow:
if (SourceTable.WEIGHT_UNIT_OF_MEASURE == “Centigram”)
    DestinationTable. WEIGHT_IN_KILOGRAM = SourceTable.WEIGHT/100;
else if (SourceTable.WEIGHT_UNIT_OF_MEASURE == “Milligram”)
    DestinationTable. WEIGHT_IN_KILOGRAM = SourceTable.WEIGHT/1000;
else DestinationTable. WEIGHT_IN_KILOGRAM = SourceTable.WEIGHT;

Is there any way to do such a conversion using the tMap? We are running TOS 2.3.0.M2_r7640 and Java.


#2 2008-02-07 22:35:28

Talend Team

mhirt said:

Re: Convert field value

The most readable solution do to this is probably to write your own routine.

Go to code -> routines -> create routine.
You can call it MyRoutine for example

Here is an example of method to do your conversion :
public static Float convertToKilogram(String unit, Float weight) {
        if (unit.equals("Centigram")) {
            return weight/100;
        } else if (unit.equals("Milligram")) {
            return weight/1000;
        } else {
            return weight;

You can call it it the tMap with MyRoutine.convertToKilogram(row1.WEIGHT_UNIT_OF_MEASURE,row1.WEIGHT)



#3 2008-02-14 14:18:20

2 posts

bse said:

Re: Convert field value

Hi mhirt,

Thank you very much for your prompt reaction. This is EXACTELY what we were looking for!

Thank a lot.



Board footer

Talend Contributor Agreement - Talend Website Privacy Policy