Search in sources :

Example 1 with BlobDataCell

use of org.knime.core.data.container.BlobDataCell 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 2 with BlobDataCell

use of org.knime.core.data.container.BlobDataCell in project knime-core by knime.

the class BlobSupportDataCellList method init.

private void init(final Collection<? extends DataCell> coll) {
    ArrayList<DataCell> cellList = new ArrayList<DataCell>(coll.size());
    DataType commonType = null;
    for (DataCell c : coll) {
        if (c == null) {
            throw new NullPointerException("List element must not be null");
        }
        DataType cellType;
        if (c instanceof BlobWrapperDataCell) {
            m_containsBlobWrapperCells = true;
            cellList.add(c);
            cellType = DataType.getType(((BlobWrapperDataCell) c).getBlobClass());
        } else if (c instanceof BlobDataCell) {
            m_containsBlobWrapperCells = true;
            cellList.add(new BlobWrapperDataCell((BlobDataCell) c));
            cellType = c.getType();
        } else {
            cellList.add(c);
            cellType = c.getType();
        }
        if (!c.isMissing()) {
            if (commonType == null) {
                commonType = cellType;
            } else {
                commonType = DataType.getCommonSuperType(commonType, cellType);
            }
        }
    }
    if (commonType == null) {
        m_elementType = DataType.getMissingCell().getType();
    } else {
        m_elementType = commonType;
    }
    m_cellList = cellList;
}
Also used : BlobDataCell(org.knime.core.data.container.BlobDataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) ArrayList(java.util.ArrayList) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) BlobDataCell(org.knime.core.data.container.BlobDataCell) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType)

Example 3 with BlobDataCell

use of org.knime.core.data.container.BlobDataCell in project knime-core by knime.

the class BlobSupportDataCellSet method init.

/**
 * @param cells
 */
private void init(final Collection<? extends DataCell> cells) {
    LinkedHashSet<Wrapper> cellSet = new LinkedHashSet<Wrapper>();
    DataType commonType = null;
    for (DataCell c : cells) {
        if (c == null) {
            throw new NullPointerException("Collection element must not be null");
        }
        DataType cellType;
        Wrapper element;
        if (c instanceof BlobWrapperDataCell) {
            m_containsBlobWrapperCells = true;
            element = new Wrapper(c);
            cellType = DataType.getType(((BlobWrapperDataCell) c).getBlobClass());
        } else if (c instanceof BlobDataCell) {
            m_containsBlobWrapperCells = true;
            element = new Wrapper(new BlobWrapperDataCell((BlobDataCell) c));
            cellType = c.getType();
        } else {
            element = new Wrapper(c);
            cellType = c.getType();
        }
        cellSet.add(element);
        if (!c.isMissing()) {
            if (commonType == null) {
                commonType = cellType;
            } else {
                commonType = DataType.getCommonSuperType(commonType, cellType);
            }
        }
    }
    if (commonType == null) {
        m_elementType = DataType.getMissingCell().getType();
    } else {
        m_elementType = commonType;
    }
    m_set = Collections.unmodifiableSet(cellSet);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BlobDataCell(org.knime.core.data.container.BlobDataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) DataType(org.knime.core.data.DataType) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) BlobDataCell(org.knime.core.data.container.BlobDataCell) DataCell(org.knime.core.data.DataCell)

Aggregations

DataCell (org.knime.core.data.DataCell)3 BlobDataCell (org.knime.core.data.container.BlobDataCell)3 DataType (org.knime.core.data.DataType)2 BlobWrapperDataCell (org.knime.core.data.container.BlobWrapperDataCell)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 LinkedHashSet (java.util.LinkedHashSet)1 DataRow (org.knime.core.data.DataRow)1 DefaultRow (org.knime.core.data.def.DefaultRow)1 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)1 BufferedDataTable (org.knime.core.node.BufferedDataTable)1 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)1