Search in sources :

Example 1 with IDataRepository

use of org.knime.core.data.IDataRepository in project knime-core by knime.

the class DictEncodedDataCellInOutDelegateTest method testReadAdapterCell.

@Test
public void testReadAdapterCell() throws IOException, ParserConfigurationException, SAXException, XMLStreamException {
    // This calls readDataCell twice, once for the AdapterCell and once for the contained cell.
    final var xmlString = "<dummyXML>Test</dummyXML>";
    final var innerCell = XMLCellFactory.create(xmlString);
    @SuppressWarnings("unchecked") final var cell = new MyAdapterCell(innerCell, XMLValue.class);
    final IDataRepository dataRepository = null;
    final IWriteFileStoreHandler fileStoreHandler = new ValueSchemaTest.DummyWriteFileStoreHandler();
    final var baseBuffer = new ByteArrayOutputStream();
    final var outStream = new DataOutputStream(baseBuffer);
    try (final var out = new DictEncodedDataCellDataOutputDelegator(fileStoreHandler, outStream)) {
        out.writeDataCell(cell);
        final var classNames = DictEncodedDataCellDataInputDelegator.getSerializedCellNames(cell).split(";");
        assertEquals(2, classNames.length);
        assertEquals(cell.getClass().getName(), classNames[0]);
        assertEquals(innerCell.getClass().getName(), classNames[1]);
        final var inStream = new ReadableDataInputStream(new ByteArrayInputStream(baseBuffer.toByteArray()));
        try (final var in = new DictEncodedDataCellDataInputDelegator(dataRepository, inStream, DictEncodedDataCellDataInputDelegator.getSerializedCellNames(cell))) {
            in.readDataCell();
        }
    }
}
Also used : IDataRepository(org.knime.core.data.IDataRepository) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) MyAdapterCell(org.knime.core.data.AdapterCellTest.MyAdapterCell) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReadableDataInputStream(org.knime.core.table.io.ReadableDataInputStream) Test(org.junit.Test) ValueSchemaTest(org.knime.core.data.v2.ValueSchemaTest)

Example 2 with IDataRepository

use of org.knime.core.data.IDataRepository in project knime-core by knime.

the class DictEncodedDataCellInOutDelegateTest method testReadDataCellWithoutClassNameThrowsException.

@Test(expected = IllegalStateException.class)
public void testReadDataCellWithoutClassNameThrowsException() throws IOException, ParserConfigurationException, SAXException, XMLStreamException {
    final var xmlString = "<dummyXML>Test</dummyXML>";
    final var cell = XMLCellFactory.create(xmlString);
    final IDataRepository dataRepository = null;
    final IWriteFileStoreHandler fileStoreHandler = new ValueSchemaTest.DummyWriteFileStoreHandler();
    final var baseBuffer = new ByteArrayOutputStream();
    final var outStream = new DataOutputStream(baseBuffer);
    try (final var out = new DictEncodedDataCellDataOutputDelegator(fileStoreHandler, outStream)) {
        out.writeDataCell(cell);
        final var inStream = new ReadableDataInputStream(new ByteArrayInputStream(baseBuffer.toByteArray()));
        try (final var in = new DictEncodedDataCellDataInputDelegator(dataRepository, inStream, "")) {
            // throws because no cell class name was specified in constructor
            in.readDataCell();
        }
    }
}
Also used : IDataRepository(org.knime.core.data.IDataRepository) IWriteFileStoreHandler(org.knime.core.data.filestore.internal.IWriteFileStoreHandler) ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ReadableDataInputStream(org.knime.core.table.io.ReadableDataInputStream) Test(org.junit.Test) ValueSchemaTest(org.knime.core.data.v2.ValueSchemaTest)

Example 3 with IDataRepository

use of org.knime.core.data.IDataRepository 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 4 with IDataRepository

use of org.knime.core.data.IDataRepository in project knime-core by knime.

the class BufferedContainerTable method clear.

/**
 * Be mindful when to call this method. Any underlying resources will be released. Any subsequent iteration on the
 * table will fail!
 *
 * @see KnowsRowCountTable#clear()
 */
@Override
public void clear() {
    if (m_buffer != null) {
        m_buffer.clear();
        m_buffer.getDataRepository().removeTable(m_buffer.getBufferID());
    }
    if (m_readTask != null) {
        IDataRepository dataRepository = CheckUtils.checkArgumentNotNull(m_readTask.getDataRepository());
        dataRepository.removeTable(m_readTask.getBufferID());
    }
}
Also used : IDataRepository(org.knime.core.data.IDataRepository)

Example 5 with IDataRepository

use of org.knime.core.data.IDataRepository in project knime-core by knime.

the class WriteFileStoreHandler method getOwnerHandler.

/**
 * @param key
 * @return
 */
@SuppressWarnings("null")
IFileStoreHandler getOwnerHandler(final FileStoreKey key) {
    IFileStoreHandler ownerHandler;
    final UUID keyStoreUUID = key.getStoreUUID();
    if (keyStoreUUID.equals(m_storeUUID)) {
        ownerHandler = this;
    } else {
        IDataRepository repo = m_dataRepository;
        CheckUtils.checkState(repo != null, "No data repository set");
        ownerHandler = repo.getHandler(keyStoreUUID);
    }
    return ownerHandler;
}
Also used : IDataRepository(org.knime.core.data.IDataRepository) UUID(java.util.UUID)

Aggregations

IDataRepository (org.knime.core.data.IDataRepository)7 IWriteFileStoreHandler (org.knime.core.data.filestore.internal.IWriteFileStoreHandler)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DataOutputStream (java.io.DataOutputStream)3 ReadableDataInputStream (org.knime.core.table.io.ReadableDataInputStream)3 Test (org.junit.Test)2 ValueSchemaTest (org.knime.core.data.v2.ValueSchemaTest)2 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 MyAdapterCell (org.knime.core.data.AdapterCellTest.MyAdapterCell)1 DataColumnSpec (org.knime.core.data.DataColumnSpec)1 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)1 DataTableSpec (org.knime.core.data.DataTableSpec)1 FileStoreProxy (org.knime.core.data.filestore.internal.FileStoreProxy)1 ValueSchema (org.knime.core.data.v2.schema.ValueSchema)1 NodeSettings (org.knime.core.node.NodeSettings)1