use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class TwoSampleTTestNodeView method renderDescriptiveStatistics.
/**
* Create HTML for the descriptive statistics.
*/
private String renderDescriptiveStatistics() {
StringBuilder buffer = NodeViewUtil.createHtmlHeader();
buffer.append("<body>\n");
buffer.append("<h3>Group Statistics</h3>");
NodeViewUtil.renderDataTable(getNodeModel().getDescritiveStatistics(), TwoSampleTTestStatistics.TEST_COLUMN, Arrays.asList(new String[] { TwoSampleTTestStatistics.TEST_COLUMN, TwoSampleTTestStatistics.IGNORED_COUNT_GROUP_COL }), new HashMap<String, String>(), buffer);
BufferedDataTable descStats = getNodeModel().getDescritiveStatistics();
if (descStats.getRowCount() > 0) {
CloseableRowIterator iter = descStats.iteratorFailProve();
int ignoredIndex = descStats.getSpec().findColumnIndex(TwoSampleTTestStatistics.IGNORED_COUNT_GROUP_COL);
DataCell ignoredCell = iter.next().getCell(ignoredIndex);
if (!ignoredCell.isMissing()) {
int ignoredCount = ((IntValue) ignoredCell).getIntValue();
if (ignoredCount > 0) {
buffer.append("<p>");
buffer.append(ignoredCount);
buffer.append(ignoredCount > 1 ? " rows have been ignored. Their " : " row has been ignored. Its ");
buffer.append("value in the grouping column is neither \"");
buffer.append(getNodeModel().getSettings().getGroupOne());
buffer.append("\" nor \"");
buffer.append(getNodeModel().getSettings().getGroupTwo());
buffer.append("\".");
buffer.append("</p>");
}
}
iter.close();
}
buffer.append("</body>\n");
buffer.append("</html>\n");
return buffer.toString();
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class FileStoresInLoopCache method deletableUnusedFileStores.
void deletableUnusedFileStores(final FileStoresInLoopCache endNodeCacheWithKeysToPersist, final ILoopStartWriteFileStoreHandler handler) throws CanceledExecutionException {
MutableInteger nrFilesDeleted = new MutableInteger(0);
MutableInteger nrFailedDeletes = new MutableInteger(0);
CloseableRowIterator allKeysIterator = m_createdFileStoresTable.iterator();
CloseableRowIterator endNodeKeysIterator = endNodeCacheWithKeysToPersist.getCreatedFileStoresTable().iterator();
FileStoreKey nextLoopEndFSKey = next(endNodeKeysIterator, null);
FileStoreKey nextAllFSKey = next(allKeysIterator, null);
while (nextLoopEndFSKey != null) {
if (nextAllFSKey != null) {
final int compare = nextLoopEndFSKey.compareTo(nextAllFSKey);
if (compare == 0) {
nextLoopEndFSKey = next(endNodeKeysIterator, nextLoopEndFSKey);
nextAllFSKey = next(allKeysIterator, nextAllFSKey);
} else if (compare > 0) {
delete(nextAllFSKey, handler, nrFilesDeleted, nrFailedDeletes);
nextAllFSKey = next(allKeysIterator, nextAllFSKey);
} else {
nextLoopEndFSKey = next(endNodeKeysIterator, nextLoopEndFSKey);
}
} else {
break;
}
}
while (nextAllFSKey != null) {
delete(nextAllFSKey, handler, nrFilesDeleted, nrFailedDeletes);
nextAllFSKey = next(allKeysIterator, nextAllFSKey);
}
allKeysIterator.close();
endNodeKeysIterator.close();
if (nrFilesDeleted.intValue() > 0) {
StringBuilder b = new StringBuilder("Deleted ");
b.append(nrFilesDeleted.intValue()).append(" files ");
if (nrFailedDeletes.intValue() > 0) {
b.append("; ").append(nrFailedDeletes.intValue()).append(" of which failed");
} else {
b.append("successfully");
}
LOGGER.debug(b.toString());
}
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class TableContentModel method setDataTableIntern.
/**
* Sets new data for this table. The table argument may be
* <code>null</code> to indicate invalid data (nothing displayed).
*/
private void setDataTableIntern(final DataTable originalData, final DataTable data, final TableSortOrder sortOrder) {
assert SwingUtilities.isEventDispatchThread();
if (m_data == data) {
// do not start event storm
return;
}
boolean clearOldTable = m_tableSortOrder != null;
if (m_tableSorterWorker != null) {
m_tableSorterWorker.cancel(true);
m_tableSorterWorker = null;
}
m_tableSortOrder = sortOrder;
cancelRowCountingInBackground();
int oldColCount = getColumnCount();
int newColCount = data != null ? data.getDataTableSpec().getNumColumns() : 0;
int oldRowCount = getRowCount();
DataTable oldData = m_data;
m_originalUnsortedTable = originalData;
m_data = data;
m_cachedRows = null;
m_hilitSet = null;
if (m_iterator instanceof CloseableRowIterator) {
((CloseableRowIterator) m_iterator).close();
}
m_iterator = null;
m_rowCountOfInterestInIterator = 0;
m_rowCountOfInterest = 0;
m_maxRowCount = 0;
cancelRowCountingInBackground();
m_isMaxRowCountFinal = true;
m_isRowCountOfInterestFinal = true;
boolean structureChanged = oldColCount != newColCount;
if (oldColCount == newColCount) {
if (oldRowCount > 0) {
fireTableRowsDeleted(0, oldRowCount - 1);
}
if (newColCount > 0) {
structureChanged = !data.getDataTableSpec().equalStructure(oldData.getDataTableSpec());
}
}
if (data != null) {
// new data available, release old stuff
// assume that there are rows, may change in cacheNextRow() below
m_isMaxRowCountFinal = false;
m_isRowCountOfInterestFinal = false;
final long rowCountFromTable;
if (data instanceof BufferedDataTable) {
rowCountFromTable = ((BufferedDataTable) data).size();
} else if (data instanceof ContainerTable) {
rowCountFromTable = ((ContainerTable) data).size();
} else {
// unknown
rowCountFromTable = -1;
}
if (rowCountFromTable >= 0) {
m_isMaxRowCountFinal = true;
if (rowCountFromTable > Integer.MAX_VALUE) {
NodeLogger.getLogger(getClass()).warn("Table view will show only the first " + Integer.MAX_VALUE + " rows of " + rowCountFromTable + ".");
m_maxRowCount = Integer.MAX_VALUE;
} else {
m_maxRowCount = (int) rowCountFromTable;
}
if (!m_tableFilter.performsFiltering()) {
m_rowCountOfInterest = m_maxRowCount;
m_isRowCountOfInterestFinal = true;
}
}
int cacheSize = getCacheSize();
m_cachedRows = new DataRow[cacheSize];
m_hilitSet = new BitSet(cacheSize);
// will instantiate a new iterator.
clearCache();
// will also set m_isRowCountOfInterestFinal etc. accordingly
cacheNextRow();
}
if (structureChanged) {
// notify listeners
fireTableStructureChanged();
} else {
int newRowCount = getRowCount();
if (newRowCount > 0) {
fireTableRowsInserted(0, newRowCount);
}
}
m_propertySupport.firePropertyChange(PROPERTY_DATA, oldData, m_data);
if (clearOldTable && oldData instanceof ContainerTable) {
((ContainerTable) oldData).clear();
}
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class HistogramNodeModel method createHistogramModel.
/**
* {@inheritDoc}
*/
@Override
protected void createHistogramModel(final ExecutionContext exec, final int noOfRows, final BufferedDataTable data) throws CanceledExecutionException {
LOGGER.debug("Entering createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
if (noOfRows == 0) {
m_model = null;
return;
}
if (exec == null) {
throw new NullPointerException("exec must not be null");
}
if (data == null) {
throw new IllegalArgumentException("Table shouldn't be null");
}
ExecutionMonitor subExec = exec.createSubProgress(0.5);
exec.setMessage("Adding rows to histogram model...");
final DataArray dataArray = new DefaultDataArray(data, 1, noOfRows, subExec);
exec.setMessage("Adding row color to histogram...");
final SortedSet<Color> colorSet = new TreeSet<Color>(HSBColorComparator.getInstance());
subExec = exec.createSubProgress(0.5);
final double progressPerRow = 1.0 / noOfRows;
double progress = 0.0;
final CloseableRowIterator rowIterator = data.iterator();
try {
for (int i = 0; i < noOfRows && rowIterator.hasNext(); i++) {
final DataRow row = rowIterator.next();
final Color color = data.getDataTableSpec().getRowColor(row).getColor(false, false);
if (!colorSet.contains(color)) {
colorSet.add(color);
}
progress += progressPerRow;
subExec.setProgress(progress, "Adding data rows to histogram...");
subExec.checkCanceled();
}
} finally {
if (rowIterator != null) {
rowIterator.close();
}
}
exec.setProgress(1.0, "Histogram finished.");
m_model = new InteractiveHistogramDataModel(dataArray, new ArrayList<Color>(colorSet));
LOGGER.debug("Exiting createHistogramModel(exec, dataTable) " + "of class HistogramNodeModel.");
}
use of org.knime.core.data.container.CloseableRowIterator in project knime-core by knime.
the class DefaultDataArray method init.
private void init(final DataTable dTable, final int firstRow, final int numOfRows, final ExecutionMonitor execMon) throws CanceledExecutionException {
if (dTable == null) {
throw new IllegalArgumentException("Must provide non-null data table" + " for DataArray");
}
if (firstRow < 1) {
throw new IllegalArgumentException("Starting row must be greater" + " than zero");
}
if (numOfRows < 0) {
throw new IllegalArgumentException("Number of rows to read must be" + " greater than or equal zero");
}
DataTableSpec tSpec = dTable.getDataTableSpec();
DataTableDomainCreator domainCreator = new DataTableDomainCreator(tSpec, true);
int numOfColumns = tSpec.getNumColumns();
m_firstRow = firstRow;
m_rows = new ArrayList<DataRow>(numOfColumns);
// now fill our data structures
RowIterator rIter = dTable.iterator();
int rowNumber = 0;
while ((rIter.hasNext()) && (m_rows.size() < numOfRows)) {
// get the next row
DataRow row = rIter.next();
rowNumber++;
if (rowNumber < firstRow) {
// skip all rows until we see the specified first row
continue;
}
// store it.
m_rows.add(row);
domainCreator.updateDomain(row);
// see if user wants us to stop
if (execMon != null) {
// will throw an exception if we are supposed to cancel
execMon.checkCanceled();
execMon.setProgress((double) m_rows.size() / (double) numOfRows, "read row " + m_rows.size() + " of max. " + numOfRows);
}
}
if (rIter instanceof CloseableRowIterator) {
((CloseableRowIterator) rIter).close();
}
m_tSpec = domainCreator.createSpec();
}
Aggregations