use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class BasisFunctionLearnerNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File internDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
assert (m_modelInfo != null);
// save model info
exec.checkCanceled();
exec.setProgress(0.1, "Saving model information");
File file = new File(internDir, MODEL_INFO_FILE_NAME);
m_modelInfo.saveToXML(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(file))));
// save hilite mapping
exec.checkCanceled();
exec.setProgress(0.5, "Saving hilite mapping");
NodeSettings mapSettings = new NodeSettings(HILITE_MAPPING_FILE_NAME);
DefaultHiLiteMapper mapper = (DefaultHiLiteMapper) m_translator.getMapper();
mapper.save(mapSettings);
File mappingFile = new File(internDir, HILITE_MAPPING_FILE_NAME);
mapSettings.saveToXML(new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(mappingFile))));
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class GroupByNodeModel method createGroupByTable.
/**
* Create group-by table.
* @param exec execution context
* @param table input table to group
* @param groupByCols column selected for group-by operation
* @param inMemory keep data in memory
* @param sortInMemory does sorting in memory
* @param retainOrder reconstructs original data order
* @param aggregators column aggregation to use
* @return table with group and aggregation columns
* @throws CanceledExecutionException if the group-by table generation was
* canceled externally
* @deprecated sortInMemory is no longer required
* @see #createGroupByTable(ExecutionContext, BufferedDataTable, List,
* boolean, boolean, List)
*/
@Deprecated
protected final GroupByTable createGroupByTable(final ExecutionContext exec, final BufferedDataTable table, final List<String> groupByCols, final boolean inMemory, final boolean sortInMemory, final boolean retainOrder, final List<ColumnAggregator> aggregators) throws CanceledExecutionException {
final int maxUniqueVals = m_maxUniqueValues.getIntValue();
final boolean enableHilite = m_enableHilite.getBooleanValue();
final ColumnNamePolicy colNamePolicy = ColumnNamePolicy.getPolicy4Label(m_columnNamePolicy.getStringValue());
final GlobalSettings globalSettings = createGlobalSettings(exec, table, groupByCols, maxUniqueVals);
// reset all aggregators in order to use enforce operator creation
for (final ColumnAggregator colAggr : aggregators) {
colAggr.reset();
}
final GroupByTable resultTable;
if (inMemory || groupByCols.isEmpty()) {
resultTable = new MemoryGroupByTable(exec, table, groupByCols, aggregators.toArray(new ColumnAggregator[0]), globalSettings, enableHilite, colNamePolicy, retainOrder);
} else {
resultTable = new BigGroupByTable(exec, table, groupByCols, aggregators.toArray(new ColumnAggregator[0]), globalSettings, enableHilite, colNamePolicy, retainOrder);
}
if (m_enableHilite.getBooleanValue()) {
setHiliteMapping(new DefaultHiLiteMapper(resultTable.getHiliteMapping()));
}
// check for skipped columns
final String warningMsg = resultTable.getSkippedGroupsMessage(3, 3);
if (warningMsg != null) {
setWarningMessage(warningMsg);
LOGGER.info(resultTable.getSkippedGroupsMessage(Integer.MAX_VALUE, Integer.MAX_VALUE));
}
return resultTable;
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class Joiner2NodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
NodeSettings internalSettings = new NodeSettings("joiner");
NodeSettingsWO leftMapSet = internalSettings.addNodeSettings("leftHiliteMapping");
((DefaultHiLiteMapper) m_leftTranslator.getMapper()).save(leftMapSet);
NodeSettingsWO rightMapSet = internalSettings.addNodeSettings("rightHiliteMapping");
((DefaultHiLiteMapper) m_rightTranslator.getMapper()).save(rightMapSet);
File f = new File(nodeInternDir, "joinerInternalSettings");
FileOutputStream out = new FileOutputStream(f);
internalSettings.saveToXML(out);
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class UngroupOperation 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
* @throws Exception the thrown exception
* @since 3.2
*/
public void compute(final RowInput in, final RowOutput out, final ExecutionContext exec, final long rowCount) throws Exception {
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) {
m_trans.setMapper(new DefaultHiLiteMapper(hiliteMapping));
}
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class Unpivot2NodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec inSpec = inData[0].getSpec();
String[] retainedColumns = m_retainedColumns.applyTo(inSpec).getIncludes();
String[] valueColumns = m_valueColumns.applyTo(inSpec).getIncludes();
int[] valueColumnIndices = new int[valueColumns.length];
for (int i = 0; i < valueColumnIndices.length; i++) {
valueColumnIndices[i] = inSpec.findColumnIndex(valueColumns[i]);
}
int[] orderColumnIdx = new int[retainedColumns.length];
for (int i = 0; i < orderColumnIdx.length; i++) {
orderColumnIdx[i] = inSpec.findColumnIndex(retainedColumns[i]);
}
final double newRowCnt = inData[0].size() * valueColumns.length;
final boolean enableHilite = m_enableHilite.getBooleanValue();
LinkedHashMap<RowKey, Set<RowKey>> map = new LinkedHashMap<RowKey, Set<RowKey>>();
DataTableSpec outSpec = createOutSpec(inSpec);
BufferedDataContainer buf = exec.createDataContainer(outSpec);
final boolean skipMissings = m_missingValues.getBooleanValue();
for (DataRow row : inData[0]) {
LinkedHashSet<RowKey> set = new LinkedHashSet<RowKey>();
FilterColumnRow crow = new FilterColumnRow(row, orderColumnIdx);
for (int i = 0; i < valueColumns.length; i++) {
String colName = valueColumns[i];
DataCell acell = row.getCell(valueColumnIndices[i]);
if (acell.isMissing() && skipMissings) {
// skip rows containing missing cells (in Value column(s))
continue;
}
RowKey rowKey = RowKey.createRowKey(buf.size());
if (enableHilite) {
set.add(rowKey);
}
DefaultRow drow = new DefaultRow(rowKey, new StringCell(row.getKey().getString()), new StringCell(colName), acell);
buf.addRowToTable(new AppendedColumnRow(rowKey, drow, crow));
exec.checkCanceled();
exec.setProgress(buf.size() / newRowCnt);
}
if (enableHilite) {
map.put(crow.getKey(), set);
}
}
buf.close();
if (enableHilite) {
m_trans.setMapper(new DefaultHiLiteMapper(map));
} else {
m_trans.setMapper(null);
}
return new BufferedDataTable[] { buf.getTable() };
}
Aggregations