Search in sources :

Example 36 with BufferedDataContainer

use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.

the class PortObjectRepository method copy.

/**
 * Copies the argument object by means of the associated serializer.
 * @param object The port object to be copied.
 * @param exec Host for BDTs being created
 * @param progress For progress/cancelation
 * @return The deep copy.
 * @throws IOException In case of exceptions while accessing the streams
 * @throws CanceledExecutionException If canceled.
 */
public static final PortObject copy(final PortObject object, final ExecutionContext exec, final ExecutionMonitor progress) throws IOException, CanceledExecutionException {
    if (object instanceof BufferedDataTable) {
        // need to copy the table cell by cell
        // this is to workaround the standard knime philosophy according
        // to which tables are referenced. A row-based copy will not work
        // as it still will reference blobs
        BufferedDataTable in = (BufferedDataTable) object;
        BufferedDataContainer con = exec.createDataContainer(in.getSpec(), true, 0);
        final long rowCount = in.size();
        long row = 0;
        boolean hasLoggedCloneProblem = false;
        for (DataRow r : in) {
            DataCell[] cells = new DataCell[r.getNumCells()];
            for (int i = 0; i < cells.length; i++) {
                // deserialize blob
                DataCell c = r.getCell(i);
                if (c instanceof BlobDataCell) {
                    try {
                        c = cloneBlobCell(c);
                    } catch (Exception e) {
                        if (!hasLoggedCloneProblem) {
                            LOGGER.warn("Can't clone blob object: " + e.getMessage(), e);
                            hasLoggedCloneProblem = true;
                            LOGGER.debug("Suppressing futher warnings.");
                        }
                    }
                }
                cells[i] = c;
            }
            con.addRowToTable(new DefaultRow(r.getKey(), cells));
            progress.setProgress(row / (double) rowCount, "Copied row " + row + "/" + rowCount);
            progress.checkCanceled();
            row++;
        }
        con.close();
        return con.getTable();
    }
    return Node.copyPortObject(object, exec);
}
Also used : BlobDataCell(org.knime.core.data.container.BlobDataCell) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) BlobDataCell(org.knime.core.data.container.BlobDataCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) CanceledExecutionException(org.knime.core.node.CanceledExecutionException) IOException(java.io.IOException)

Example 37 with BufferedDataContainer

use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.

the class BlobsInSetCellWorkflowTest method createBDT.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable createBDT(final ExecutionContext exec) {
    DataType t = ListCell.getCollectionType(DataType.getType(DataCell.class));
    BufferedDataContainer c = exec.createDataContainer(new DataTableSpec(new DataColumnSpecCreator("Sequence", t).createSpec()));
    for (int i = 0; i < ROW_COUNT; i++) {
        String s = "someName_" + i;
        // every other a ordinary string cell
        Collection<DataCell> cells = new ArrayList<DataCell>();
        for (int j = 0; j < LIST_SIZE * 2; j++) {
            String val = "Row_" + i + "; Cell index " + j;
            if (j % 2 == 0) {
                cells.add(new LargeBlobCell(val, LargeBlobCell.SIZE_OF_CELL));
            } else {
                cells.add(new StringCell(val));
            }
        }
        ListCell cell = CollectionCellFactory.createListCell(cells);
        c.addRowToTable(new DefaultRow(s, cell));
    }
    c.close();
    return c.getTable();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) ListCell(org.knime.core.data.collection.ListCell) ArrayList(java.util.ArrayList) LargeBlobCell(org.knime.testing.data.blob.LargeBlobCell) StringCell(org.knime.core.data.def.StringCell) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 38 with BufferedDataContainer

use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.

the class TreeEnsembleModelExtractorNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    TreeEnsembleModelPortObject treeEnsembleModel = (TreeEnsembleModelPortObject) inObjects[0];
    DataTableSpec outSpec = createOutSpec();
    BufferedDataContainer container = exec.createDataContainer(outSpec, false, 0);
    int nrModels = treeEnsembleModel.getEnsembleModel().getNrModels();
    for (int i = 0; i < nrModels; i++) {
        PMMLPortObject pmmlObject = treeEnsembleModel.createDecisionTreePMMLPortObject(i);
        DataCell cell = PMMLCellFactory.create(pmmlObject.getPMMLValue().toString());
        RowKey key = RowKey.createRowKey(i);
        container.addRowToTable(new DefaultRow(key, cell));
        exec.checkCanceled();
        exec.setProgress(i / (double) nrModels, "Exported model " + (i + 1) + "/" + nrModels);
    }
    container.close();
    return new BufferedDataTable[] { container.getTable() };
}
Also used : TreeEnsembleModelPortObject(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModelPortObject) DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 39 with BufferedDataContainer

use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.

the class MedianTableTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    Random random = new Random(37);
    DataColumnSpec[] colSpecs = new DataColumnSpec[] { new DataColumnSpecCreator("AscendingDouble", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("DescendingDouble", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("ThreeValuesSingleMedian", DoubleCell.TYPE).createSpec(), new DataColumnSpecCreator("ThreeValuesDifferentMedian", DoubleCell.TYPE).createSpec() // new DataColumnSpecCreator("FourValuesSingleMedian", DoubleCell.TYPE).createSpec(),
    // new DataColumnSpecCreator("FourValuesDifferentMedian", DoubleCell.TYPE).createSpec()
    };
    DataTableSpec spec = new DataTableSpec(colSpecs);
    final BufferedDataContainer container = EXEC_CONTEXT.createDataContainer(spec);
    try {
        int count = 100;
        for (int i = 0; i < count; ++i) {
            int col = 0;
            DataCell[] rowVals = new DataCell[colSpecs.length];
            rowVals[col++] = new DoubleCell(i);
            rowVals[col++] = new DoubleCell(count - i - 1);
            rowVals[col++] = i == 4 ? DataType.getMissingCell() : new DoubleCell(i < count / 2 ? 0 : i * 2 >= count + 2 ? 4 : 1);
            rowVals[col++] = new DoubleCell(i < count / 2 ? 0 : i * 2 >= count + 2 ? 4 : 1);
            container.addRowToTable(new DefaultRow(Integer.toString(i), rowVals));
        }
    } finally {
        container.close();
    }
    smallTable = container.getTable();
    NodeLogger.getLogger(getClass()).debug("Contents of test table:");
    for (DataRow row : smallTable) {
        StringBuilder buf = new StringBuilder();
        for (DataCell dataCell : row) {
            buf.append(dataCell + "\t");
        }
        NodeLogger.getLogger(getClass()).debug(buf.toString());
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) DataRow(org.knime.core.data.DataRow) DataColumnSpec(org.knime.core.data.DataColumnSpec) Random(java.util.Random) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) Before(org.junit.Before)

Example 40 with BufferedDataContainer

use of org.knime.core.node.BufferedDataContainer in project knime-core by knime.

the class CovarianceMatrixCalculatorTest method generateData.

/**
 * @param random
 * @param size
 * @param data
 */
private BufferedDataContainer generateData(final Random random, final double[][] data, final DataTableSpec spec) {
    BufferedDataContainer createDataContainer = m_exec.createDataContainer(spec);
    for (int j = 0; j < data.length; j++) {
        double[] row = new double[spec.getNumColumns()];
        for (int i = 0; i < spec.getNumColumns(); i++) {
            {
                row[i] = random.nextDouble();
            }
        }
        data[j] = row;
        createDataContainer.addRowToTable(new DefaultRow(RowKey.createRowKey(j), row));
    }
    return createDataContainer;
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

BufferedDataContainer (org.knime.core.node.BufferedDataContainer)157 BufferedDataTable (org.knime.core.node.BufferedDataTable)96 DefaultRow (org.knime.core.data.def.DefaultRow)93 DataCell (org.knime.core.data.DataCell)88 DataTableSpec (org.knime.core.data.DataTableSpec)88 DataRow (org.knime.core.data.DataRow)80 RowKey (org.knime.core.data.RowKey)38 DoubleCell (org.knime.core.data.def.DoubleCell)37 StringCell (org.knime.core.data.def.StringCell)26 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)24 ArrayList (java.util.ArrayList)23 DataColumnSpec (org.knime.core.data.DataColumnSpec)21 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)21 ExecutionMonitor (org.knime.core.node.ExecutionMonitor)17 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 IOException (java.io.IOException)15 ExecutionContext (org.knime.core.node.ExecutionContext)15 LinkedHashMap (java.util.LinkedHashMap)14 HashSet (java.util.HashSet)13 IntCell (org.knime.core.data.def.IntCell)13