java if table split by column type

Hi Everyone,

I’m trying to combine some data into one file. The issue is the plate barcode for some of these are long and others are string. When the file reader reads the longs in it reads them as double, and of course reads the strings as strings. This causes issues at the end of the loop.

What I’m trying to do is split away the plate barcode and if it is of type double convert it to long and then to type string. If I don’t do this then I get 7.77xxxxxE11 if I convert directly to string from double. If it comes in as type string I don’t want to do anything.

I have tried the traditional switches with no luck. My hunch is this could be done with a java if table node. I’m guessing there is some java which could say if column x is the go to port 0 if not then port 1.

Has anyone done this before?

Thanks in advance :slight_smile:,
Jason

Have you tried setting the File Reader to import the barcode column as string?

How about setting the Loop End node to allow variable column types?

Can you provides sample data that contains examples of barcodes that “work” and ones that don’t?

4 Likes

Hello @j_ochoada,

and how about using Column Splitter with Type Selection option?

Br,
Ivan

1 Like

Thanks @elsamuel @ipazin. I’m using csv reader in this case and I had tried to set up first a column splitter to split away the column in question then a second to split by type to modify but in that case I found the rowID’s were still there so I couldn’t use a empty table switch to control the path. Burned a couple of hours doing that :slight_smile: I did figure out a way to do what I want but I know that there is probably a snippet of java code which can do it all in the java if table. I’ve attached a pic of what I have which does work. It’s just inefficent.

2 Likes

Hi @j_ochoada,

you could use the Round Double node. All you need is one column with numbers (integer, long, double works well).

You could use the Column Splitter node from @ipazin and an Empty Table Switch ... End If.
The workflow looks like

I hope it helps.

Best regards
Andrew

3 Likes

Hello @j_ochoada,

and why not just using Double To Int node with check to have Long values? If the column is there and a double, it will convert it. Otherwise it is ignored. Follow it with Number To String which should have same behavior.

If you really want to use Java IF (Table) node you can use following code:

if ($${variableName}$$.equals(“Number (double)”)) {
return 0;
}
else {
return 1;
}

where variableName needs to have column type of target column but that doesn’t differ much from your current solution…

Br,
Ivan

3 Likes

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.