Java snippet node updated in KNIME 3.3

I've just seen the new functionality in the Java Snippet where KNIME Types and Java types can be defined. 

Am  I able to implement my own types here? It would be really useful to be able to use our custom chemical format (and engine) like we now seem to be able to act on RDKit molecules. 

Cheers

Sam

 

 

Hi Sam,

Credit goes to someone else (both for doing it and sponsoring it) but I should still be able to answer your question.

If you have a custom data type then you would annotate

  • the DataValue to get access to the POJO (org.knime.core.data.convert.DataValueAccessMethod annotation)
    See the RDKit example here.
  • the CellFactory (if you have any, otherwise you need to introduce one) to define your cell via POJO (org.knime.core.data.convert.DataCellFactoryMethod annotation)
    See the RDKit example here.

There is also the possibility to define custom mappers from POJO <-> any KNIME Type. (A type, which you don't own! So for instance if you wanted to define mappers that map a native KNIME fingerprint type to java.util.Bitset). This would be done via some extension point (JavaToDataCellConverter and DataCellToJavaConverter).

Bernd

PS: The mapper from Fingerprint <-> BitSet is currently missing, yes. It's an open ticket on our end.

Thanks Bernd, I will give it a go :)

I have now attempted a couple of approaches. 

I annoted my value and factories with the annotations as found in the RDKit code and replaced name = "ROMol" with name = "IStructure". 

Nothing appeared to happen :( 

So I went with plan B of writing the converters and using the extension points. Both the Cell -> Java and Java -> Cell appear in the Java snippet. Unfortunatelty when I execute the node I get the following error: 

 

ERROR Java Snippet         0:4        Execute failed: java.lang.RuntimeException: Could not find a converter factory for: IStructure -> {package}.IStructure

 

My converter factory:

 

public class IStructureValueToJavaConverterFactory
		extends SimpleDataCellToJavaConverterFactory<IStructureValue, IStructure>
{
	
	 // Constructor
    public IStructureValueToJavaConverterFactory() 
    {
        super(IStructureValue.class, // class of source type
        		IStructure.class,          // class of destination type
              (cell) -> cell.getIStructure(), // conversion function
              "IStructure"
        );
    }
    
}

I removed the class annotations to see if the the approaches conflict but it still has the same problem. 

Any pointers greatly appreciated :)

 

Edit:

Seems it's something to do with my implementation of the cells. I tried this on the BitSet cellt type implementation I have and it work fine simply with the annotations. I've got it working on a number of other cell types.

 

Edit2:

Forgot to define the factory class in the extension point. It now appears in the Java snippet when just using the annotations. Still not worked out how to get it to work though. 

 

Cheers

Sam

 

EDIT:

Found my problem. I unfortunately have the need to provide two different versions of some internal jars. For some of the cell types the Java class was being exported by two different plugins. 

I've locked down which classes are being exported by one of my versions and this appears to have fixed the issue. 

If someone else runs into a similar issue check which class loader your POJO is coming from. 

On a related note, would be be possible to configure the java snippet to run single / multi threaded?

Cheers

Sam