use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class TestSubnode_StreamingPortObject method checkTableView.
private void checkTableView() throws Exception {
NativeNodeContainer tableViewNNC = (NativeNodeContainer) findNodeContainer(m_tableViewInSubNode_8_8);
checkState(tableViewNNC, EXECUTED);
BufferedDataTable table = (BufferedDataTable) tableViewNNC.getNode().getInternalHeldPortObjects()[0];
assertNotNull(table);
try (CloseableRowIterator it = table.iterator()) {
assertTrue(it.hasNext());
assertNotNull(it.next());
}
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class ReferenceColumnResorterNodeModel method readOrderFromTable.
/**
* @param orderTable
* @return
*/
private String[] readOrderFromTable(final BufferedDataTable orderTable) {
int orderCol = orderTable.getSpec().findColumnIndex(m_orderCol.getStringValue());
// get order from input[1]
CloseableRowIterator rows = orderTable.iterator();
List<String> orderList = new ArrayList<String>();
while (rows.hasNext()) {
orderList.add(rows.next().getCell(orderCol).toString());
}
switch(m_strategy.getStringValue()) {
case "Last":
orderList.add(UNKNOWN_COL_DUMMY.getName());
break;
case "First":
orderList.add(0, UNKNOWN_COL_DUMMY.getName());
break;
case "Drop":
break;
default:
throw new IllegalStateException("Node should have failed during configuration");
}
String[] order = orderList.toArray(new String[orderList.size()]);
return order;
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class TargetShufflingNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final int colIndex = inData[0].getDataTableSpec().findColumnIndex(m_settings.columnName());
final String colName = inData[0].getDataTableSpec().getColumnSpec(colIndex).getName();
// create a new column rearranger from the input table
ColumnRearranger colRe = new ColumnRearranger(inData[0].getDataTableSpec());
for (DataColumnSpec c : inData[0].getDataTableSpec()) {
if (!c.getName().equals(colName)) {
// remove all columns except the selected one
colRe.remove(c.getName());
}
}
// append a new column with a random number for each cell
String uniqueColumnName = DataTableSpec.getUniqueColumnName(inData[0].getDataTableSpec(), "random_col");
colRe.append(new SingleCellFactory(new DataColumnSpecCreator(uniqueColumnName, LongCell.TYPE).createSpec()) {
@Override
public DataCell getCell(final DataRow row) {
return new LongCell(m_random.nextLong());
}
});
BufferedDataTable toSort = exec.createColumnRearrangeTable(exec.createBufferedDataTable(inData[0], exec), colRe, exec.createSilentSubProgress(.2));
// sort the random numbers ---> shuffles the sorted column
List<String> include = new ArrayList<String>();
include.add(toSort.getDataTableSpec().getColumnSpec(1).getName());
SortedTable sort = new SortedTable(toSort, include, new boolean[] { true }, exec.createSubExecutionContext(.6));
final BufferedDataTable sorted = sort.getBufferedDataTable();
// replace the selected column with the shuffled one
final DataColumnSpec colSpec = inData[0].getDataTableSpec().getColumnSpec(colIndex);
ColumnRearranger crea = new ColumnRearranger(inData[0].getDataTableSpec());
crea.replace(new SingleCellFactory(colSpec) {
private final CloseableRowIterator m_iterator = sorted.iterator();
@Override
public DataCell getCell(final DataRow row) {
return m_iterator.next().getCell(0);
}
}, colName);
return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[0], crea, exec.createSubProgress(0.2)) };
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class FixedPieNodeModel method createModel.
/**
* {@inheritDoc}
* @throws CanceledExecutionException
* @throws TooManySectionsException
*/
@Override
protected void createModel(final ExecutionContext exec, final DataColumnSpec pieColSpec, final DataColumnSpec aggrColSpec, final BufferedDataTable dataTable, final int noOfRows, final boolean containsColorHandler) throws CanceledExecutionException, TooManySectionsException {
m_model = new FixedPieDataModel(pieColSpec, aggrColSpec, containsColorHandler);
final DataTableSpec spec = dataTable.getSpec();
final int pieColIdx = spec.findColumnIndex(pieColSpec.getName());
final int aggrColIdx;
if (aggrColSpec == null) {
aggrColIdx = -1;
} else {
aggrColIdx = spec.findColumnIndex(aggrColSpec.getName());
}
final double progressPerRow = 1.0 / noOfRows;
double progress = 0.0;
final CloseableRowIterator rowIterator = dataTable.iterator();
try {
for (int rowCounter = 0; rowCounter < noOfRows && rowIterator.hasNext(); rowCounter++) {
final DataRow row = rowIterator.next();
final Color rowColor = spec.getRowColor(row).getColor(false, false);
final DataCell pieCell = row.getCell(pieColIdx);
final DataCell aggrCell;
if (aggrColIdx >= 0) {
aggrCell = row.getCell(aggrColIdx);
} else {
aggrCell = null;
}
m_model.addDataRow(row, rowColor, pieCell, aggrCell);
progress += progressPerRow;
exec.setProgress(progress, "Adding data rows to pie chart...");
exec.checkCanceled();
}
} finally {
if (rowIterator != null) {
rowIterator.close();
}
}
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class FixedColumnHistogramNodeModel method createHistogramModel.
/**
* {@inheritDoc}
*/
@Override
protected void createHistogramModel(final ExecutionContext exec, final int noOfRows, final BufferedDataTable table) throws CanceledExecutionException {
LOGGER.debug("Entering createHistogramModel(exec, table) " + "of class FixedColumnHistogramNodeModel.");
final Collection<ColorColumn> aggrColumns = getAggrColumns();
final int noOfBins = BinningUtil.calculateIntegerMaxNoOfBins(m_noOfBins.getIntValue(), getXColSpec());
m_model = new FixedHistogramDataModel(getXColSpec(), AggregationMethod.getDefaultMethod(), aggrColumns, noOfBins);
if (noOfRows < 1) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("No rows available");
}
return;
}
exec.setMessage("Adding data rows to histogram...");
final double progressPerRow = 1.0 / noOfRows;
double progress = 0.0;
int aggrColSize = 0;
if (aggrColumns != null) {
aggrColSize = aggrColumns.size();
}
final DataTableSpec tableSpec = getTableSpec();
final int xColIdx = getXColIdx();
// save the aggregation column indices
final int[] aggrColIdxs = new int[aggrColSize];
if (aggrColumns != null) {
int idx = 0;
for (final ColorColumn aggrCol : aggrColumns) {
aggrColIdxs[idx++] = tableSpec.findColumnIndex(aggrCol.getColumnName());
}
}
final CloseableRowIterator rowIterator = table.iterator();
try {
for (int rowCounter = 0; rowCounter < noOfRows && rowIterator.hasNext(); rowCounter++) {
final DataRow row = rowIterator.next();
final Color color = tableSpec.getRowColor(row).getColor(false, false);
if (aggrColSize < 1) {
m_model.addDataRow(row.getKey(), color, row.getCell(xColIdx), DataType.getMissingCell());
} else {
final DataCell[] aggrCells = new DataCell[aggrColSize];
for (int i = 0, length = aggrColIdxs.length; i < length; i++) {
aggrCells[i] = row.getCell(aggrColIdxs[i]);
}
m_model.addDataRow(row.getKey(), color, row.getCell(xColIdx), aggrCells);
}
progress += progressPerRow;
exec.setProgress(progress, "Adding data rows to histogram...");
exec.checkCanceled();
}
} finally {
if (rowIterator != null) {
rowIterator.close();
}
}
exec.setMessage("Sorting rows...");
exec.setProgress(1.0, "Histogram finished.");
LOGGER.debug("Exiting createHistogramModel(exec, table) " + "of class FixedColumnHistogramNodeModel.");
}
Aggregations