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);
}
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();
}
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() };
}
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());
}
}
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;
}
Aggregations