Search in sources :

Example 1 with ValueSchema

use of org.knime.core.data.v2.schema.ValueSchema in project knime-core by knime.

the class ValueSchemaTest method testSchemaSaveLoadDataType.

private static void testSchemaSaveLoadDataType(final DataType type, final Class<?> factoryClass) throws InvalidSettingsException {
    final DataColumnSpec columnSpec = new DataColumnSpecCreator("0", type).createSpec();
    final DataTableSpec tableSpec = new DataTableSpec(columnSpec);
    final IDataRepository dataRepository = null;
    final IWriteFileStoreHandler fileStoreHandler = new DummyWriteFileStoreHandler();
    // Create the schema and check
    final ValueSchema schema = ValueSchemaUtils.create(tableSpec, RowKeyType.NOKEY, fileStoreHandler);
    assertEquals(2, schema.numFactories());
    var rowKeyFactory = schema.getValueFactory(0);
    assertEquals(VoidRowKeyFactory.class, rowKeyFactory.getClass());
    var dataFactory = schema.getValueFactory(1);
    assertEquals(factoryClass, dataFactory.getClass());
    // Save to some note settings
    final NodeSettings settings = new NodeSettings("valueSchema");
    ValueSchemaUtils.save(schema, settings);
    var columnarSchema = // 
    DefaultColumnarSchema.builder().addColumn(rowKeyFactory.getSpec(), // 
    ValueFactoryUtils.getTraits(rowKeyFactory)).addColumn(dataFactory.getSpec(), // 
    ValueFactoryUtils.getTraits(dataFactory)).build();
    var loadContext = mock(ValueSchemaLoadContext.class);
    when(loadContext.getTableSpec()).thenReturn(tableSpec);
    when(loadContext.getDataRepository()).thenReturn(dataRepository);
    when(loadContext.getSettings()).thenReturn(settings);
    // Load back and check
    final ValueSchema loadedSchema = ValueSchemaUtils.load(columnarSchema, loadContext);
    assertEquals(VoidRowKeyFactory.class, rowKeyFactory.getClass());
    assertEquals(2, loadedSchema.numFactories());
    assertEquals(factoryClass, loadedSchema.getValueFactory(1).getClass());
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) IDataRepository(org.knime.core.data.IDataRepository) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) NodeSettings(org.knime.core.node.NodeSettings) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ValueSchema(org.knime.core.data.v2.schema.ValueSchema)

Example 2 with ValueSchema

use of org.knime.core.data.v2.schema.ValueSchema in project knime-core by knime.

the class BufferedTableBackend method create.

@Override
public RowContainer create(final ExecutionContext context, final DataTableSpec spec, final DataContainerSettings settings, final IDataRepository repository, final IWriteFileStoreHandler handler) {
    final BufferedDataContainer container = context.createDataContainer(spec, settings.getInitializeDomain(), settings.getMaxCellsInMemory());
    final ValueSchema schema = ValueSchemaUtils.create(spec, RowKeyType.CUSTOM, handler);
    return new BufferedRowContainer(container, schema);
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ValueSchema(org.knime.core.data.v2.schema.ValueSchema)

Aggregations

ValueSchema (org.knime.core.data.v2.schema.ValueSchema)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 IDataRepository (org.knime.core.data.IDataRepository)1 IWriteFileStoreHandler (org.knime.core.data.filestore.internal.IWriteFileStoreHandler)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 NodeSettings (org.knime.core.node.NodeSettings)1