Search in sources :

Example 1 with StructDataTraits

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

the class ValueFactoryUtilsTest method testGetTraitsOnCollectionValueFactory.

@Test
void testGetTraitsOnCollectionValueFactory() {
    var valueFactory = new ListValueFactory();
    valueFactory.initialize(new IntValueFactory(), IntCell.TYPE);
    // 
    assertThat(ValueFactoryUtils.getTraits(valueFactory)).isInstanceOf(// 
    ListDataTraits.class).matches(// 
    this::hasLogicalTypeTrait).matches(this::isListTypeTrait).extracting(// 
    ListDataTraits.class::cast).extracting(// 
    ListDataTraits::getInner).matches(// 
    this::hasLogicalTypeTrait).extracting(// 
    ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
    // collection of data cell value factories
    var listOfDataCells = createListValueFactory(createDataCellValueFactory(), XMLCell.TYPE);
    // 
    assertThat(ValueFactoryUtils.getTraits(listOfDataCells)).isInstanceOf(// 
    ListDataTraits.class).matches(// 
    this::hasLogicalTypeTrait).matches(// 
    this::isListTypeTrait).extracting(// 
    ListDataTraits.class::cast).extracting(// 
    ListDataTraits::getInner).extracting(// 
    ValueFactoryUtilsTest::extractLogicalTypeJson).matches(j -> j.get("value_factory_class").asText().equals(DictEncodedDataCellValueFactory.class.getName())).extracting(// 
    j -> j.get("data_type")).extracting(// 
    j -> j.get("cell_class").asText()).isEqualTo(XMLCell.class.getName());
    // nested collection
    var nestedCollection = createListValueFactory(createListValueFactory(IntValueFactory.INSTANCE, IntCell.TYPE), DataType.getType(ListCell.class, IntCell.TYPE));
    // 
    assertThat(ValueFactoryUtils.getTraits(nestedCollection)).isInstanceOf(// 
    ListDataTraits.class).matches(// 
    this::hasLogicalTypeTrait).matches(// 
    this::isListTypeTrait).extracting(// 
    ListDataTraits.class::cast).extracting(// 
    ListDataTraits::getInner).matches(// 
    this::hasLogicalTypeTrait).matches(// 
    this::isListTypeTrait).extracting(// 
    ListDataTraits.class::cast).extracting(// 
    ListDataTraits::getInner).matches(// 
    this::hasLogicalTypeTrait).extracting(// 
    ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
    // SparseListValueFactory (uses StructDataTraits)
    var sparseList = new SparseListValueFactory();
    sparseList.initialize(IntValueFactory.INSTANCE, IntCell.TYPE);
    // 
    assertThat(ValueFactoryUtils.getTraits(sparseList)).isInstanceOf(// 
    StructDataTraits.class).extracting(// 
    StructDataTraits.class::cast).matches(// 
    this::hasLogicalTypeTrait).matches(// 
    t -> extractValueFactoryClassName(t).equals(SparseListValueFactory.class.getName())).extracting(// 
    t -> t.getDataTraits(0)).matches(// 
    this::hasLogicalTypeTrait).extracting(// 
    ValueFactoryUtilsTest::extractValueFactoryClassName).isEqualTo(IntValueFactory.class.getName());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ListCell(org.knime.core.data.collection.ListCell) LogicalTypeTrait(org.knime.core.table.schema.traits.LogicalTypeTrait) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) PNGImageCellFactory(org.knime.core.data.image.png.PNGImageCellFactory) IntReadAccess(org.knime.core.table.access.IntAccess.IntReadAccess) IntValueFactory(org.knime.core.data.v2.value.IntValueFactory) DataSpec(org.knime.core.table.schema.DataSpec) ListDataTraits(org.knime.core.table.schema.traits.ListDataTraits) StringValueFactory(org.knime.core.data.v2.value.StringValueFactory) DefaultDataTraits(org.knime.core.table.schema.traits.DefaultDataTraits) JsonNode(com.fasterxml.jackson.databind.JsonNode) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DataCell(org.knime.core.data.DataCell) IntValue(org.knime.core.data.IntValue) IntCell(org.knime.core.data.def.IntCell) NotInWorkflowDataRepository(org.knime.core.data.filestore.internal.NotInWorkflowDataRepository) DataCellValueFactory(org.knime.core.data.v2.value.cell.DataCellValueFactory) DoubleValueFactory(org.knime.core.data.v2.value.DoubleValueFactory) StructDataTraits(org.knime.core.table.schema.traits.StructDataTraits) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) DataTraits(org.knime.core.table.schema.traits.DataTraits) VoidRowKeyFactory(org.knime.core.data.v2.value.VoidRowKeyFactory) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) DoubleCell(org.knime.core.data.def.DoubleCell) NotInWorkflowWriteFileStoreHandler(org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler) XMLCell(org.knime.core.data.xml.XMLCell) DictEncodingTrait(org.knime.core.table.schema.traits.DataTrait.DictEncodingTrait) ListValueFactory(org.knime.core.data.v2.value.ListValueFactory) Test(org.junit.jupiter.api.Test) SparseListValueFactory(org.knime.core.data.v2.value.SparseListValueFactory) IntWriteAccess(org.knime.core.table.access.IntAccess.IntWriteAccess) IntListValueFactory(org.knime.core.data.v2.value.IntListValueFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) DefaultRowKeyValueFactory(org.knime.core.data.v2.value.DefaultRowKeyValueFactory) VoidValueFactory(org.knime.core.data.v2.value.VoidValueFactory) DataType(org.knime.core.data.DataType) DictEncodedDataCellValueFactory(org.knime.core.data.v2.value.cell.DictEncodedDataCellValueFactory) XMLCell(org.knime.core.data.xml.XMLCell) SparseListValueFactory(org.knime.core.data.v2.value.SparseListValueFactory) StructDataTraits(org.knime.core.table.schema.traits.StructDataTraits) DictEncodedDataCellValueFactory(org.knime.core.data.v2.value.cell.DictEncodedDataCellValueFactory) IntValueFactory(org.knime.core.data.v2.value.IntValueFactory) 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) Test(org.junit.jupiter.api.Test)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 Test (org.junit.jupiter.api.Test)1 DataCell (org.knime.core.data.DataCell)1 DataType (org.knime.core.data.DataType)1 IntValue (org.knime.core.data.IntValue)1 ListCell (org.knime.core.data.collection.ListCell)1 DoubleCell (org.knime.core.data.def.DoubleCell)1 IntCell (org.knime.core.data.def.IntCell)1 NotInWorkflowDataRepository (org.knime.core.data.filestore.internal.NotInWorkflowDataRepository)1 NotInWorkflowWriteFileStoreHandler (org.knime.core.data.filestore.internal.NotInWorkflowWriteFileStoreHandler)1 PNGImageCellFactory (org.knime.core.data.image.png.PNGImageCellFactory)1 DefaultRowKeyValueFactory (org.knime.core.data.v2.value.DefaultRowKeyValueFactory)1 DoubleValueFactory (org.knime.core.data.v2.value.DoubleValueFactory)1 IntListValueFactory (org.knime.core.data.v2.value.IntListValueFactory)1