Saturday 6 August 2016

Eliminate the Diagonal Values



Input:


We have to take away the diagonal values from the above matrix.





tFileInputDelimited:
          
          In the tFileInputDelimited, we have to give the field separator as " " (single space). 


          Basically the given input data consists of elements which are string data type where each value is separated by single space (“ “). Input source file path was chosen in the Filename/Stream and the required schema is declared.

tMap_1:
          A tab space found in the input data is converted into single space using string handling functions “CHANGE” in tmap. Further in expression builder, the system routine function Numeric.sequence("s1",1,1) to generate a sequence number for each row.




                 The above tMap expression changes the tab space into single space between columns.

tJava_Row:
            tJavaRow component is deployed after the tMap where it has a nature of passing the incoming data row by row. Here the data got split using the single space separator and that data is stored in an array named ‘a’ (String [ ] = a;).
           After the successful split of incoming data, individual values in the array can be compared or processed. Without splitting the data, it won’t be possible to perform any operations such as comparison among the values. The for loop is created to iterate or continuously run the job. It allows the program to run continuously till the condition which is given in the for loop meets the array length. Here in our program the array length is 4, so first the integer i=0 passes the first value in the array followed by the i=1, i=2, i=3 values. If else condition is used to check the values with the sequence numbers. When the sequence meets with the first array index, it checks whether both are equal or not. if they are equal, then no value should be passed. If the array index equals with the sequence number, then the loop goes to the else condition where the previous value stored in the context variable will be concatenated with the array value using comma delimiter or separator. This operation continues till the condition meets the length. After the condition meets the array length, the for loop terminates and switches to the next row.
Finally, the values stored in the context variable ‘c’ will be stored in the output value column. Here, the empty value in the first element of the array was observed in the output and that was removed by using substring method  [a.substring(1)].

The following code was typed in the tJavaRow component:


          



        The context variable is assigned as c and initially no value is declared for this context variable. 


tFilterColumns:
        tFilterColumns component is deployed to remove the unwanted columns in the output schema.


Obtained Result:




           We can see the displayed result with the absence of diagonal values in it and here we have to notice that this job runs dynamically no matter how much amount of values we give in.




No comments:

Post a Comment