Return multiple rows of outputs for each row of input in a java snippet

Is it possible to return multiple rows of output for a single row of input in a java snippet?

 

I am using a java snippet to parse a file.

The input contains a file name per row, each file contains multiple sets of data, each set contains many rows in column deliminated form. The number of sets in the file is unknown at the start. The following is an example.

7744|12/29|14:59:52|B|2475||JT|200|A|2478||JT|200||

7744|12/29|14:59:51|B|2475||JT|210|A|2478||JT|200||

7744|12/29|14:59:50|B|2475||JT|190|A|2478||JT|200||

5645|12/29|14:59:52|B|2475||JT|500|A|2478||JT|200||

5645|12/29|14:59:51|B|2475||JT|600|A|2478||JT|200||

5645|12/29|14:59:50|B|2475||JT|610|A|2478||JT|200||

3433|12/29|14:59:52|B|2475||JT|1200|A|2478||JT|200||

I would like to return the data for 7744, 5645, 3433 in the example above as separate rows of output, each row containing lists of the separate entries, so the output table would look like

7443, [12/29, 12/29, 12/29], [14:59:52, 14:59:51, 14:59:50], [B,B,B], [JT,JT,JT], [200,210,190], ...

5645, [12/29, 12/29, 12/29], [14:59:52, 14:59:51, 14:59:50], [B,B,B], [JT,JT,JT], [500,600,610], ...

3433, [12/29, 12/29, 12/29], [14:59:52], [B], [JT], [1200], ...

[] are lists

 

is it possible to output multiple rows for each single row of input in a java snippet?

 

Alternatively, is it possible to return lists of lists? in which case I may be able to return

[7433, 5645, 3433], [[12/29, 12/29, 12/29], [12/29], [12/29], [12/29]], [[14:59:52, 14:59:51, 14:59:50], [14:59:52, 14:59:51, 14:59:50], [14:59:52]], .... 

and then use an ungroup node to re-create the multiple rows of output.

 

Best

 

David

 

 

Hi David, 

I would suggest using a GroupBy node instead of using a JavaSnippet node, which will make things easier. 

You can save your data in TXT format, read it with a File Reader, using vertical bar (|) as a delimiter. Since in some cases you have a double vertical bar as a delimiter, you'll have some columns with missing values as the output of the File Reader node, which can be removed with a Missing Value Column Filter node. 

After you get your data for aggregation, use a GroupBy node with the first column as a group column and Type Based Aggregation (for String and Number (Integer) data types) and aggregation method List to achieve the data aggregation you need. 

Please find attached a sample workflow. 

 

Best,

Anna