Search in sources :

Example 36 with DefaultRow

use of org.knime.core.data.def.DefaultRow 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 DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class AbstractColumnTableSorter method sort.

/**
 * @param dataTable the table to sort
 * @param exec the execution context
 * @param resultListener the result listener
 * @throws CanceledExecutionException if the user cancels the execution
 */
void sort(final DataTable dataTable, final ExecutionMonitor exec, final SortingConsumer resultListener) throws CanceledExecutionException {
    if (m_sortDescriptions.length <= 0) {
        for (DataRow r : dataTable) {
            resultListener.consume(new DefaultRow(r.getKey(), new DataCell[0]));
        }
    } else {
        clearBuffer();
        sortOnDisk(dataTable, exec, resultListener);
    }
}
Also used : DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) DataRow(org.knime.core.data.DataRow)

Example 38 with DefaultRow

use of org.knime.core.data.def.DefaultRow 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 39 with DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class RegressionTreeModel method createLearnAttributeRow.

public DataRow createLearnAttributeRow(final DataRow learnRow, final DataTableSpec learnSpec) {
    final TreeType type = getType();
    switch(type) {
        case Ordinary:
            return learnRow;
        case BitVector:
            DataCell c = learnRow.getCell(0);
            if (c.isMissing()) {
                return null;
            }
            BitVectorValue bv = (BitVectorValue) c;
            final long length = bv.length();
            int nrAttributes = getMetaData().getNrAttributes();
            if (length != nrAttributes) {
                // TODO indicate error message
                return null;
            }
            DataCell trueCell = new StringCell("1");
            DataCell falseCell = new StringCell("0");
            DataCell[] cells = new DataCell[nrAttributes];
            for (int i = 0; i < nrAttributes; i++) {
                cells[i] = bv.get(i) ? trueCell : falseCell;
            }
            return new DefaultRow(learnRow.getKey(), cells);
        case ByteVector:
            DataCell cell = learnRow.getCell(0);
            if (cell.isMissing()) {
                return null;
            }
            ByteVectorValue byteVector = (ByteVectorValue) cell;
            final long bvLength = byteVector.length();
            int nrAttr = getMetaData().getNrAttributes();
            if (bvLength != nrAttr) {
                return null;
            }
            DataCell[] bvCells = new DataCell[nrAttr];
            for (int i = 0; i < nrAttr; i++) {
                bvCells[i] = new IntCell(byteVector.get(i));
            }
            return new DefaultRow(learnRow.getKey(), bvCells);
        default:
            throw new IllegalStateException("Type unknown (not implemented): " + type);
    }
}
Also used : TreeType(org.knime.base.node.mine.treeensemble.model.TreeEnsembleModel.TreeType) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Example 40 with DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class TreeEnsembleModel method createLearnAttributeRow.

public DataRow createLearnAttributeRow(final DataRow learnRow, final DataTableSpec learnSpec) {
    final TreeType type = getType();
    switch(type) {
        case Ordinary:
            return learnRow;
        case BitVector:
            DataCell c = learnRow.getCell(0);
            if (c.isMissing()) {
                return null;
            }
            BitVectorValue bv = (BitVectorValue) c;
            final long length = bv.length();
            int nrAttributes = getMetaData().getNrAttributes();
            if (length != nrAttributes) {
                // TODO indicate error message
                return null;
            }
            DataCell trueCell = new StringCell("1");
            DataCell falseCell = new StringCell("0");
            DataCell[] cells = new DataCell[nrAttributes];
            for (int i = 0; i < nrAttributes; i++) {
                cells[i] = bv.get(i) ? trueCell : falseCell;
            }
            return new DefaultRow(learnRow.getKey(), cells);
        case ByteVector:
            DataCell cell = learnRow.getCell(0);
            if (cell.isMissing()) {
                return null;
            }
            ByteVectorValue byteVector = (ByteVectorValue) cell;
            final long bvLength = byteVector.length();
            int nrAttr = getMetaData().getNrAttributes();
            if (bvLength != nrAttr) {
                return null;
            }
            DataCell[] bvCells = new DataCell[nrAttr];
            for (int i = 0; i < nrAttr; i++) {
                bvCells[i] = new IntCell(byteVector.get(i));
            }
            return new DefaultRow(learnRow.getKey(), bvCells);
        default:
            throw new IllegalStateException("Type unknown (not implemented): " + type);
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) ByteVectorValue(org.knime.core.data.vector.bytevector.ByteVectorValue) BitVectorValue(org.knime.core.data.vector.bitvector.BitVectorValue) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell)

Aggregations

DefaultRow (org.knime.core.data.def.DefaultRow)207 DataCell (org.knime.core.data.DataCell)165 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)94 DataTableSpec (org.knime.core.data.DataTableSpec)92 DataRow (org.knime.core.data.DataRow)88 RowKey (org.knime.core.data.RowKey)80 DoubleCell (org.knime.core.data.def.DoubleCell)66 StringCell (org.knime.core.data.def.StringCell)65 BufferedDataTable (org.knime.core.node.BufferedDataTable)56 IntCell (org.knime.core.data.def.IntCell)46 ArrayList (java.util.ArrayList)26 DataType (org.knime.core.data.DataType)26 DataColumnSpec (org.knime.core.data.DataColumnSpec)22 DataContainer (org.knime.core.data.container.DataContainer)21 HashSet (java.util.HashSet)18 LinkedHashMap (java.util.LinkedHashMap)17 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 LinkedHashSet (java.util.LinkedHashSet)14 DoubleValue (org.knime.core.data.DoubleValue)14 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)14