Search in sources :

Example 1 with DataTraits

use of org.knime.core.table.schema.traits.DataTraits in project knime-core by knime.

the class ValueFactoryUtilsTest method testLoadValueFactory.

@Test
void testLoadValueFactory() {
    var dataRepo = NotInWorkflowDataRepository.newInstance();
    // no logical type trait
    assertThrows(IllegalArgumentException.class, () -> ValueFactoryUtils.loadValueFactory(DefaultDataTraits.EMPTY, dataRepo));
    // void
    var voidTrait = ValueFactoryUtils.getTraits(VoidValueFactory.INSTANCE);
    assertThat(ValueFactoryUtils.loadValueFactory(voidTrait, dataRepo)).isEqualTo(VoidValueFactory.INSTANCE);
    // ordinary
    DataTraits traits = ValueFactoryUtils.getTraits(IntValueFactory.INSTANCE);
    // 
    assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isInstanceOf(IntValueFactory.class);
    // specific collection
    traits = ValueFactoryUtils.getTraits(IntListValueFactory.INSTANCE);
    // 
    assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isEqualTo(IntListValueFactory.INSTANCE);
    // nested collection
    var nestedListValueFactory = new ListValueFactory();
    nestedListValueFactory.initialize(IntListValueFactory.INSTANCE, DataType.getType(ListCell.class, DataType.getType(ListCell.class, IntCell.TYPE)));
    traits = ValueFactoryUtils.getTraits(nestedListValueFactory);
    // 
    assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isInstanceOf(// 
    ListValueFactory.class).extracting(// 
    ListValueFactory.class::cast).extracting(// 
    ListValueFactory::getElementValueFactory).isEqualTo(IntListValueFactory.INSTANCE);
    // data cell value factory
    var dictEncodedDataCellValueFactory = createDataCellValueFactory();
    traits = ValueFactoryUtils.getTraits(dictEncodedDataCellValueFactory);
    // 
    assertThat(ValueFactoryUtils.loadValueFactory(traits, dataRepo)).isInstanceOf(// 
    DictEncodedDataCellValueFactory.class).extracting(// 
    DictEncodedDataCellValueFactory.class::cast).extracting(// 
    DictEncodedDataCellValueFactory::getType).isEqualTo(XMLCell.TYPE);
    // try to load an unregistered value factory
    final var finalTraits = createSimpleTypeTraits(DummyDataValueFactory.class.getName());
    assertThrows(IllegalArgumentException.class, () -> ValueFactoryUtils.loadValueFactory(finalTraits, dataRepo));
}
Also used : DictEncodedDataCellValueFactory(org.knime.core.data.v2.value.cell.DictEncodedDataCellValueFactory) ListCell(org.knime.core.data.collection.ListCell) ListValueFactory(org.knime.core.data.v2.value.ListValueFactory) SparseListValueFactory(org.knime.core.data.v2.value.SparseListValueFactory) IntListValueFactory(org.knime.core.data.v2.value.IntListValueFactory) ListDataTraits(org.knime.core.table.schema.traits.ListDataTraits) DefaultDataTraits(org.knime.core.table.schema.traits.DefaultDataTraits) StructDataTraits(org.knime.core.table.schema.traits.StructDataTraits) DataTraits(org.knime.core.table.schema.traits.DataTraits) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 ListCell (org.knime.core.data.collection.ListCell)1 IntListValueFactory (org.knime.core.data.v2.value.IntListValueFactory)1 ListValueFactory (org.knime.core.data.v2.value.ListValueFactory)1 SparseListValueFactory (org.knime.core.data.v2.value.SparseListValueFactory)1 DictEncodedDataCellValueFactory (org.knime.core.data.v2.value.cell.DictEncodedDataCellValueFactory)1 DataTraits (org.knime.core.table.schema.traits.DataTraits)1 DefaultDataTraits (org.knime.core.table.schema.traits.DefaultDataTraits)1 ListDataTraits (org.knime.core.table.schema.traits.ListDataTraits)1 StructDataTraits (org.knime.core.table.schema.traits.StructDataTraits)1