Six Stars

tJavaRow set Null to output row

Hi,

I have a tJavaRow with some input and output rows

I have a random column name and  I want to set that output column as null

How can I do that ?

Thank all.

1 ACCEPTED SOLUTION

Accepted Solutions
Twelve Stars

Re: tJavaRow set Null to output row

What you could try will take a fair amount of work, will perform a little slower, but will not require quite as much coding as my previous suggestion. You could try connecting your data source to a tFlowToIterate. This will iterate over the dataset once row at a time. However, what it does is load each row into the globalMap HashMap. The "key" to the value can either be the default {row}.{column} String or something you specify for each column. After your tFlowToIterate, connect to a tJavaFlex. In the "Start Code" section you could write something to iterate over the globalMap using your String variable to find the columns that should be null and change them. Then in the "Main Code" section you can simply have code to map the corresponding globalMap value with the correct output column. Your dynamic functionality would be in the Start Code section and what you have in the Main Code (albeit a lot of lines of code) would be fixed.

Rilhia Solutions
10 REPLIES
Twelve Stars

Re: tJavaRow set Null to output row

It will be null unless you set it to something else

Rilhia Solutions
Six Stars

Re: tJavaRow set Null to output row

I have set all input_row to ouput_row,
Now I want set some column to null, I have list of column name but I don't know exactly what they are.
Do you have some idea?
Twelve Stars

Re: tJavaRow set Null to output row

If you want the column set to null for every row, just don't set a value. For example, if your input and out columns are set as below....

 

output_row.newColumn = input_row.newColumn;
output_row.newColumn1 = input_row.newColumn1;
output_row.newColumn2 = input_row.newColumn2;
output_row.newColumn3 = input_row.newColumn3;

....and you want to ensure that "newColumn2" is null, you can either....

 

output_row.newColumn = input_row.newColumn;
output_row.newColumn1 = input_row.newColumn1;
output_row.newColumn3 = input_row.newColumn3;

... or....

output_row.newColumn = input_row.newColumn;
output_row.newColumn1 = input_row.newColumn1;
output_row.newColumn2 = null;
output_row.newColumn3 = input_row.newColumn3;
Rilhia Solutions
Six Stars

Re: tJavaRow set Null to output row

Thank you, but I don't know the column name, I just have it as a String variable
Twelve Stars

Re: tJavaRow set Null to output row

So something more dynamic? You could try something like this...

 

if(myStringVar.equals("newColumn")){
output_row.newColumn = null;
output_row.newColumn1 = input_row.newColumn1;
output_row.newColumn2 = input_row.newColumn2;
output_row.newColumn3 = input_row.newColumn3;
}else if(myStringVar.equals("newColumn1")){
output_row.newColumn = input_row.newColumn;
output_row.newColumn1 = null;
output_row.newColumn2 = input_row.newColumn2;
output_row.newColumn3 = input_row.newColumn3;
} //..... etc

 

Rilhia Solutions
Six Stars

Re: tJavaRow set Null to output row

My input row has more than 1000 column, I can't use 'if else' for this.
If I don't use tJavaRow, is there any way to set some column of an input row to null ?
Twelve Stars

Re: tJavaRow set Null to output row

OK, lets go back a few steps. Why do you need to do this? What is the requirement? I'm sure your requirement can be met, but I will need to know all of the information before I can suggest something sensible 

Rilhia Solutions
Six Stars

Re: tJavaRow set Null to output row

I have some data rows with 1000 coulmns each row, some column have invalid data and I use tSchemaComplianceCheck to get all the name of invalid column,
Now I want to export all data row, and set null to invalid column. Keep all right column.
Twelve Stars

Re: tJavaRow set Null to output row

What you could try will take a fair amount of work, will perform a little slower, but will not require quite as much coding as my previous suggestion. You could try connecting your data source to a tFlowToIterate. This will iterate over the dataset once row at a time. However, what it does is load each row into the globalMap HashMap. The "key" to the value can either be the default {row}.{column} String or something you specify for each column. After your tFlowToIterate, connect to a tJavaFlex. In the "Start Code" section you could write something to iterate over the globalMap using your String variable to find the columns that should be null and change them. Then in the "Main Code" section you can simply have code to map the corresponding globalMap value with the correct output column. Your dynamic functionality would be in the Start Code section and what you have in the Main Code (albeit a lot of lines of code) would be fixed.

Rilhia Solutions
Six Stars

Re: tJavaRow set Null to output row

Thank you so much, it works