use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class UngroupOperation2 method compute.
/**
* Performs the ungroup operation on the given row input and pushes the result to the row output.
*
* @param in the row input, will NOT be closed when finished
* @param out the row input, will NOT be closed when finished
* @param exec the execution context to check cancellation and (optional) progress logging
* @param rowCount row count to track the progress or <code>-1</code> without progress tracking
* @param trans the hilite translater, will be modified directly. Must be non-null if hiliting is enabled, can be
* <code>null</code> otherwise
* @throws CanceledExecutionException if the execution has been canceled
* @throws InterruptedException if the execution has been interrupted
* @throws IllegalArgumentException if hiliting is enabled and no hilite translater is given
*/
public void compute(final RowInput in, final RowOutput out, final ExecutionContext exec, final long rowCount, final HiLiteTranslator trans) throws CanceledExecutionException, InterruptedException {
if (m_enableHilite && trans == null) {
throw new IllegalArgumentException("HiLiteTranslator must not be null when hiliting is enabled!");
}
final Map<RowKey, Set<RowKey>> hiliteMapping = new HashMap<RowKey, Set<RowKey>>();
@SuppressWarnings("unchecked") Iterator<DataCell>[] iterators = new Iterator[m_colIndices.length];
final DataCell[] missingCells = new DataCell[m_colIndices.length];
Arrays.fill(missingCells, DataType.getMissingCell());
long rowCounter = 0;
DataRow row = null;
while ((row = in.poll()) != null) {
rowCounter++;
exec.checkCanceled();
if (rowCount > 0) {
exec.setProgress(rowCounter / (double) rowCount, "Processing row " + rowCounter + " of " + rowCount);
}
boolean allMissing = true;
for (int i = 0, length = m_colIndices.length; i < length; i++) {
final DataCell cell = row.getCell(m_colIndices[i]);
final CollectionDataValue listCell;
final Iterator<DataCell> iterator;
if (cell instanceof CollectionDataValue) {
listCell = (CollectionDataValue) cell;
iterator = listCell.iterator();
allMissing = false;
} else {
iterator = null;
}
iterators[i] = iterator;
}
if (allMissing) {
// with missing cells as well if the skip missing value option is disabled
if (!m_skipMissingValues) {
final DefaultRow newRow = createClone(row.getKey(), row, m_colIndices, m_removeCollectionCol, missingCells);
if (m_enableHilite) {
// create the hilite entry
final Set<RowKey> keys = new HashSet<RowKey>(1);
keys.add(row.getKey());
hiliteMapping.put(row.getKey(), keys);
}
out.push(newRow);
}
continue;
}
long counter = 1;
final Set<RowKey> keys;
if (m_enableHilite) {
keys = new HashSet<RowKey>();
} else {
keys = null;
}
boolean continueLoop = false;
boolean allEmpty = true;
do {
// reset the loop flag
allMissing = true;
continueLoop = false;
final DataCell[] newCells = new DataCell[iterators.length];
for (int i = 0, length = iterators.length; i < length; i++) {
Iterator<DataCell> iterator = iterators[i];
DataCell newCell;
if (iterator != null && iterator.hasNext()) {
allEmpty = false;
continueLoop = true;
newCell = iterator.next();
} else {
if (iterator == null) {
allEmpty = false;
}
newCell = DataType.getMissingCell();
}
if (!newCell.isMissing()) {
allMissing = false;
}
newCells[i] = newCell;
}
if (!allEmpty && !continueLoop) {
break;
}
if (!allEmpty && allMissing && m_skipMissingValues) {
continue;
}
final RowKey oldKey = row.getKey();
final RowKey newKey = new RowKey(oldKey.getString() + "_" + counter++);
final DefaultRow newRow = createClone(newKey, row, m_colIndices, m_removeCollectionCol, newCells);
out.push(newRow);
if (keys != null) {
keys.add(newKey);
}
} while (continueLoop);
if (keys != null && !keys.isEmpty()) {
hiliteMapping.put(row.getKey(), keys);
}
}
if (m_enableHilite) {
trans.setMapper(new DefaultHiLiteMapper(hiliteMapping));
}
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class ValueCounterNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
if (m_settings.hiliting()) {
NodeSettings s = new NodeSettings("Hiliting");
((DefaultHiLiteMapper) m_translator.getMapper()).save(s);
File f = new File(nodeInternDir, "Hiliting.conf.gz");
OutputStream out = new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(f)));
s.saveToXML(out);
out.close();
}
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class EndifNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] rawInData, final ExecutionContext exec) throws Exception {
if (m_enableHiliting) {
// create empty hilite translation map (so we correctly
// handle the internals even if we return with a IBPO:
Map<RowKey, Set<RowKey>> map = new HashMap<RowKey, Set<RowKey>>();
m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
}
if (rawInData[0] instanceof InactiveBranchPortObject) {
return new PortObject[] { rawInData[1] };
}
if (rawInData[1] instanceof InactiveBranchPortObject) {
return new PortObject[] { rawInData[0] };
}
// no inactive branch - check compatibility of specs - which in
// this case must be BFT Specs!
DataTableSpec spec0 = (DataTableSpec) (rawInData[0].getSpec());
DataTableSpec spec1 = (DataTableSpec) (rawInData[1].getSpec());
if (spec0.equalStructure(spec1)) {
// concatenate tables and return result
BufferedDataTable[] inData = new BufferedDataTable[2];
inData[0] = (BufferedDataTable) rawInData[0];
inData[1] = (BufferedDataTable) rawInData[1];
int totalRowCount = 0;
for (BufferedDataTable t : inData) {
totalRowCount += t.getRowCount();
}
AppendedRowsTable out = new AppendedRowsTable((m_isAppendSuffix ? m_suffix : null), inData);
// note, this iterator throws runtime exceptions when canceled.
AppendedRowsIterator it = out.iterator(exec, totalRowCount);
BufferedDataContainer c = exec.createDataContainer(out.getDataTableSpec());
try {
while (it.hasNext()) {
// may throw exception, also sets progress
c.addRowToTable(it.next());
}
} catch (AppendedRowsIterator.RuntimeCanceledExecutionException rcee) {
throw rcee.getCause();
} finally {
c.close();
}
if (it.getNrRowsSkipped() > 0) {
setWarningMessage("Filtered out " + it.getNrRowsSkipped() + " duplicate row id(s).");
}
if (m_enableHiliting) {
// create hilite translation map
Map<RowKey, Set<RowKey>> map = new HashMap<RowKey, Set<RowKey>>();
// map of all RowKeys and duplicate RowKeys in the resulting table
Map<RowKey, RowKey> dupMap = it.getDuplicateNameMap();
for (Map.Entry<RowKey, RowKey> e : dupMap.entrySet()) {
// if a duplicate key
if (!e.getKey().equals(e.getValue())) {
Set<RowKey> set = Collections.singleton(e.getValue());
// put duplicate key and original key into map
map.put(e.getKey(), set);
} else {
// skip duplicate keys
if (!dupMap.containsKey(new RowKey(e.getKey().getString() + m_suffix))) {
Set<RowKey> set = Collections.singleton(e.getValue());
map.put(e.getKey(), set);
}
}
}
m_hiliteTranslator.setMapper(new DefaultHiLiteMapper(map));
}
return new BufferedDataTable[] { c.getTable() };
}
throw new Exception("Both input ports have data but the tables " + "have incompatible specs");
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class EndifNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
if (m_enableHiliting) {
final NodeSettings config = new NodeSettings("hilite_mapping");
((DefaultHiLiteMapper) m_hiliteTranslator.getMapper()).save(config);
config.saveToXML(new GZIPOutputStream(new FileOutputStream(new File(nodeInternDir, "hilite_mapping.xml.gz"))));
}
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class AppendedRowsNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
if (m_enableHiliting) {
final NodeSettings config = new NodeSettings("hilite_mapping");
((DefaultHiLiteMapper) m_hiliteTranslator.getMapper()).save(config);
config.saveToXML(new GZIPOutputStream(new FileOutputStream(new File(nodeInternDir, "hilite_mapping.xml.gz"))));
}
}
Aggregations