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