Java Transformer Stage adding one extra column in java

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
informdaya@gmail.com
Participant
Posts: 37
Joined: Tue Nov 30, 2010 10:51 am

Java Transformer Stage adding one extra column in java

Post by informdaya@gmail.com »

i have a java code like this.
Can anyone please let me know how can i add new column in java and then pass it on to output link?

below sample code will convert lower case to uppercase.

Code: Select all

import com.ascentialsoftware.jds.Stage; 
import com.ascentialsoftware.jds.Row; 
import com.ascentialsoftware.jds.Column;



public class ConCheck 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; 
} 
} 
}
actully i want to add one extra column in java..access in output link

only that portion of snippent will be enough.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

The key here is that you don't "add" a column ....your class "reacts to" or "fills" the columns that you already have.

The DataStage Developer, at design time, adds an output link...it may have one, two, or two hundred columns..... The code below where it says:

Code: Select all

for (int columnNumber = 0; columnNumber < columnCount; columnNumber++) 
...is going to "loop" thru as many columns as you have on that output link. You can't "add" a column, as this is at run time, but it will certainly handle as many as the developer chooses to use. It detects this at runtime but can't change it.

Describe to us what it is that you are trying to do.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
informdaya@gmail.com
Participant
Posts: 37
Joined: Tue Nov 30, 2010 10:51 am

Post by informdaya@gmail.com »

Hi,
That is not the requirement...
we have to take advantage of java...calculate some result and store in a particular column.

other column will remain as it is.

help me to write that portion of java code and mapped to a extra output column.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Is there not someone you work with that is Java proficient and can help?
-craig

"You can never have too many knives" -- Logan Nine Fingers
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

No problem...just code the DataStage Job with your "extra" column that is supposed to receive the value.

You could give it a dedicated name, or always know that it is in the first position...whatever you want.

The key point I was making up above is that the output link is "fixed" at the time of compilation. There's no "adding" columns. You can populate anything you want that is on the link, but the developer of the DataStage Job will have had to put it there ....assuming that you want this "column" to be something that the DataStage Developer is going to use downstream.

Of course, your java class could also do its own I/O and do whatever it wants to with that new value.

If this isn't clear then perhaps we still aren't understanding what your goal is.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
informdaya@gmail.com
Participant
Posts: 37
Joined: Tue Nov 30, 2010 10:51 am

Post by informdaya@gmail.com »

Hi Chulett,
Normal java programmers not able to help me..

Hi Eostic,
Please provide me that code snippet.
I understand it will after that for loop.
eostic
Premium Member
Premium Member
Posts: 3838
Joined: Mon Oct 17, 2005 9:34 am

Post by eostic »

Hi.

I can't teach you how to code in java...we'll leave that to some other forum somewhere, but conceptually, once you are "inside" that loop, you could look for the column that is supposed to get your value. Consider this snippet:

Code: Select all

if (rowNumber == 1) 
            {
          
            Column   MetaDataForMyColumn = inputRow.getColumn(columnNumber);
            String   colName  = MetaDataForMyColumn.getName();
            int      colSQLType=MetaDataForMyColumn.getSQLType();
            String   colSQLTypeName=Column.getSQLTypeName(colSQLType);
                                  
            
            trace(colName);
            trace(colSQLTypeName);
                      
              	
            }
//*--------------------------------------------------------------------------------------------------------------
// "reject" any rows that have asterisks [these will go down a link that the DS developer marks as "reject" link
//*--------------------------------------------------------------------------------------------------------------          

            outColNumber=columnNumber;
            
            if (value.indexOf("*") >=0) {
                reject = true;
//                  warn("Value found with Asterisk.  Reject the row");       
                  outputRow.setValueAsString(outColNumber, value);
            } else {
                  outputRow.setValueAsString(outColNumber, value.toUpperCase());
            }
        }
Note at the top how I am pulling out the column name and its datatype. I'm not doing anything with those values, but I certainly could have. Later on in the code, I check to see if the value of the current column (current meaning the index value of the loop that I am on) contains an asterisk. In your case you might want to look for this "special" column name and then you would write this "special value" that you have (setting the value on the output row) at that particular time, as opposed to writing something else.

Ernie
Ernie Ostic

blogit!
<a href="https://dsrealtime.wordpress.com/2015/0 ... ere/">Open IGC is Here!</a>
Post Reply