Creating your own data type in KNIME

To create a molecule data type, I have generated the classes MolValue and MolCell (which implements MolValue and also StringValue classes).

I can happily generate molecules and store them in the tables but when I come to retrieving molecules from data cells, I need to first check if the data type in the cell (MolCell) is compatible to MolValue.class but it isn't. It is compatible to StringValue.class however.

I'm not sure if I have overlooked something, the preferred value class is always returned as MolValue.

Any ideas would be greatly appreciated.

Thanks in advance.

Hi Hina,

What is the runtime class of the cell being returned from the table (cell.getClass().getSimpleName())?

Just to double check: You test the type associated with the cell, not only the type associated with the column? (The DataColumnSpec contained in the DataTableSpec has also a getType() method, which should be used to test if a column matches the expected input - in your case it should be DataType.getType(MolCell.class)).

Anyway, it should work either way but if it's a column spec with the wrong type we have one more place to look for the problem.

Bernd

Thanks for the quick reply Bernd.

I was actually checking the column spec but I have now also checked the cell itself and both come back as MolCell.

It seems that when I try to extract data from a table, MolCell type is no longer compatible with MolValue.class. When putting the molecules into the table, it is compatible then.

The preferred class is always returned as MolValue and the function getValueClasses() also returns MolValue first.

Could this have anything to do with the renderer?

hina4 wrote:

It seems that when I try to extract data from a table, MolCell type is no longer compatible with MolValue.class. When putting the molecules into the table, it is compatible then.

That's not possible. The method DataCell#getType() is not a "real" object method, it's rather a delegate to a static method in DataType. The implementation in the (super-) class DataCell is

public final DataType getType() {
        return DataType.getType(getClass());
}
It means the compatibility is not checked against the object at hand but against its class. So if MolCell.getType().isCompatible(MolValue.class) is true before saving it must also be true after loading. (The getType() method is final - no way of cheating here).

For the extracted cell the following assertion must be true:

assert (cell instanceof MolCell) == (cell.getType().isCompatibleTo(MolValue.class);
There must be a wrong reference or so in your code. If it is of any help you can also send me the code and I will have a look.

Regards,
Bernd

It must work no matter what your preferred value class is. (The preferred value class is (only) used to determine which of the Interfaces to ask first for a renderer or comparator.)

Is it possible that you have two different MolValue classes in your workspace and the node that's loading the data has a wrong import statement?

To create the geometric data type, I create the GeometryValue and GeometryCell class which implements GeometryValue, when I run the node it does not show me the output table, the only thing that comes out is "loading by content", besides a notification in the console that shows me this: "ERROR ModalContext DataTypeRegistry CODING PROBLEM Data cell implementation 'utils.GeometryCell' is not registered at extension point 'org.knime.core.DataType' via it's serializer, using buddy classloading as fallback. Please change your implementation and use the extension point ". Could someone help me with that?,
Regards,
Laura