adding a new column in javatrasnformer

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
austin_316
Participant
Posts: 80
Joined: Fri Aug 21, 2009 7:49 am
Location: India

adding a new column in javatrasnformer

Post by austin_316 »

hi,
i have done a dummy job in which iam reading data from a dataset and pass it to a java transformer. In the java transformer iam calling a java class file which will change the varchar fields from lowercase to uppercase and then send the data to output link.the output link of the java transformer is again connected to a dataset. The code is working fine for the sample job.
but my requirement is to do some calculation on the input data and create a new column which i have to pass to the output link.
present the code that i have is

Code: Select all

import com.ascentialsoftware.jds.Row;
import com.ascentialsoftware.jds.Stage; 
public class HashCheck extends Stage { 
public int process() { 
Row inputRow = readRow(); 
if (inputRow == null) 
{ 
return OUTPUT_STATUS_END_OF_DATA; 

}
boolean reject = false; 
int columnCount = inputRow.getColumnCount();


Row outputRow = createOutputRow();
for (int columnNumber = 0; columnNumber < columnCount; columnNumber++)
{ 
String value = inputRow.getValueAsString(columnNumber); 
if (!(value == null))
		{
outputRow.setValueAsString(columnNumber, value.toUpperCase()); 
}
else{
	outputRow.setValueAsString(columnNumber, value);
}
if (reject) 
{
rejectRow(outputRow);
} 
else 
{ 
writeRow(outputRow); 
} 
return OUTPUT_STATUS_READY;
}
}
} 
Can anyone please let me know how can i add new column in java and then pass it on to output link?

thanks
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Why not add it before then and then simply fill it there?
-craig

"You can never have too many knives" -- Logan Nine Fingers
austin_316
Participant
Posts: 80
Joined: Fri Aug 21, 2009 7:49 am
Location: India

Post by austin_316 »

chulett wrote:Why not add it before then and then simply fill it there? ...
hi craig,
we are using the java file to develop a hash value(32bit encoded value) on some columns that are passed to jva transformer. After creating the hash value in the java file i am planning to pass it to the output link

For example:
My dataset has the columns from 1-10
Col1,Col2,Col3,Col4,Col4,Col5,Col6,Col6,Col7,Col8,Col9,Col10
And i want to create two hash values HASHVALUE_1 and HASHVALUE_2.
i have parameterset in which i specify what columns have to be used for hash value. Like HASHVALUE_1=Col2,Col3 and HASHVALUE_2=Col5,Col6
And these columns in the paramterset can be dynamic. So whenever iam calling the java class from the java transformer i have to pass these parameters also and after generating the hash values for the columns i send to java, i have to pass on to the output link.
i have found the way to add the columns to the output link and also sending the values to it from the java file. but iam not able to access values for particular columns because when i see the code its access index of the columns and not the names.

Code: Select all

String value = inputRow.getValueAsString(columnNumber); 
Anyway to do this will be helpful.

thanks.
austin_316
Participant
Posts: 80
Joined: Fri Aug 21, 2009 7:49 am
Location: India

Post by austin_316 »

also please tell me how to pass the parameters to java class from the java transformer stage and read the same in the java class.
austin_316
Participant
Posts: 80
Joined: Fri Aug 21, 2009 7:49 am
Location: India

Post by austin_316 »

Sorry for not being clear.
i want to pass the parameters that are present in the parameterset and also paramteres in job properties
austin_316
Participant
Posts: 80
Joined: Fri Aug 21, 2009 7:49 am
Location: India

Post by austin_316 »

we got the way to do it :)
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Post it. Please.
-craig

"You can never have too many knives" -- Logan Nine Fingers
austin_316
Participant
Posts: 80
Joined: Fri Aug 21, 2009 7:49 am
Location: India

adding a new column in javatrasnformer

Post by austin_316 »

chulett wrote:Post it. Please.
Sure
In the UserProperties tab of Java Transformer stage we have given a parameter with the name ARGS and passed arguments in it.

UserProperties
ARGS=#$Parameter1#:#$Parameter2#:#ParameterSetname.Parameter3#
we have done that way because we wanted our developers to use a single arguments and pass the parameters in the same order mentioned.

After the passing the parameters we are accessing them in java code as mentioned below.

Code: Select all

	public void initialize()    {
        byte[]      userProperties = getUserProperties().getBytes();
        InputStream propertyStream = new ByteArrayInputStream(userProperties);
        Properties  properties     = new Properties();
 

        try {
            properties.load(propertyStream);
        } catch (IOException eIO) {
            //  Should never happen.
        }
  
 
        strNKCols = properties.getProperty("ARGS");
        String [] strParametersPassed = strNKCols.split(":");
        for(int iNumberofParameters=0;iNumberofParameters<strParametersPassed.length;iNumberofParameters++){
        	System.out.println(strParametersPassed[iNumberofParameters]);
        }
       

        
     }
the code mentioned above is just the part where we access arguments passed. After that we have implemented code for our specific requirement and it worked as expected :)
Post Reply