use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class RowKeyNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws CanceledExecutionException, Exception {
LOGGER.debug("Entering execute(inData, exec) of class RowKeyNodeModel");
// check input data
if (inData == null || inData.length != 1 || inData[DATA_IN_PORT] == null) {
throw new IllegalArgumentException("No input data available.");
}
final BufferedDataTable data = inData[DATA_IN_PORT];
BufferedDataTable outData = null;
if (m_replaceKey.getBooleanValue()) {
LOGGER.debug("The user wants to replace the row ID with the" + " column " + m_newColumnName.getStringValue() + " optional appended column name" + m_appendRowKey.getBooleanValue());
if (m_newRowKeyColumn.getStringValue() != null) {
// the user wants a new column as rowkey column
final int colIdx = data.getDataTableSpec().findColumnIndex(m_newRowKeyColumn.getStringValue());
if (colIdx < 0) {
throw new InvalidSettingsException("No column with name: " + m_newColumnName.getStringValue() + " exists. Please select a valid column name.");
}
}
DataColumnSpec newColSpec = null;
if (m_appendRowKey.getBooleanValue()) {
final String newColName = m_newColumnName.getStringValue();
newColSpec = createAppendRowKeyColSpec(newColName);
}
final RowKeyUtil util = new RowKeyUtil();
outData = util.changeRowKey(data, exec, m_newRowKeyColumn.getStringValue(), m_appendRowKey.getBooleanValue(), newColSpec, m_ensureUniqueness.getBooleanValue(), m_handleMissingVals.getBooleanValue(), m_removeRowKeyCol.getBooleanValue(), m_enableHilite.getBooleanValue());
if (m_enableHilite.getBooleanValue()) {
m_hilite.setMapper(new DefaultHiLiteMapper(util.getHiliteMapping()));
}
final int missingValueCounter = util.getMissingValueCounter();
final int duplicatesCounter = util.getDuplicatesCounter();
final StringBuilder warningMsg = new StringBuilder();
if (duplicatesCounter > 0) {
warningMsg.append(duplicatesCounter + " duplicate(s) now unique. ");
}
if (missingValueCounter > 0) {
warningMsg.append(missingValueCounter + " missing value(s) replaced with " + RowKeyUtil.MISSING_VALUE_REPLACEMENT + ".");
}
if (warningMsg.length() > 0) {
setWarningMessage(warningMsg.toString());
}
LOGGER.debug("Row ID replaced successfully");
} else if (m_appendRowKey.getBooleanValue()) {
LOGGER.debug("The user only wants to append a new column with " + "name " + m_newColumnName);
// the user wants only a column with the given name which
// contains the rowkey as value
final DataTableSpec tableSpec = data.getDataTableSpec();
final String newColumnName = m_newColumnName.getStringValue();
final ColumnRearranger c = RowKeyUtil.createColumnRearranger(tableSpec, newColumnName, StringCell.TYPE);
outData = exec.createColumnRearrangeTable(data, c, exec);
exec.setMessage("New column created");
LOGGER.debug("Column appended successfully");
} else {
// the user doesn't want to do anything at all so we simply return
// the given data
outData = data;
LOGGER.debug("The user hasn't selected a new row ID column" + " and hasn't entered a new column name.");
}
LOGGER.debug("Exiting execute(inData, exec) of class RowKeyNodeModel.");
return new BufferedDataTable[] { outData };
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class GroupByNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException {
if (m_enableHilite.getBooleanValue()) {
final NodeSettings config = new NodeSettings("hilite_mapping");
final DefaultHiLiteMapper mapper = (DefaultHiLiteMapper) m_hilite.getMapper();
if (mapper != null) {
mapper.save(config);
}
config.saveToXML(new FileOutputStream(new File(nodeInternDir, INTERNALS_FILE_NAME)));
}
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class Joiner2NodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
Joiner joiner = new Joiner(inData[0].getDataTableSpec(), inData[1].getDataTableSpec(), m_settings);
BufferedDataTable[] joinedTable = new BufferedDataTable[] { joiner.computeJoinTable(inData[0], inData[1], exec) };
if (!joiner.getRuntimeWarnings().isEmpty()) {
for (String warning : joiner.getRuntimeWarnings()) {
setWarningMessage(warning);
}
}
m_leftRowKeyMap = joiner.getLeftRowKeyMap();
m_rightRowKeyMap = joiner.getRightRowKeyMap();
m_leftMapper = new DefaultHiLiteMapper(m_leftRowKeyMap);
m_rightMapper = new DefaultHiLiteMapper(m_rightRowKeyMap);
m_leftTranslator.setMapper(m_leftMapper);
m_rightTranslator.setMapper(m_rightMapper);
return joinedTable;
}
use of org.knime.core.node.property.hilite.DefaultHiLiteMapper in project knime-core by knime.
the class PivotNodeModel method saveInternals.
/**
* {@inheritDoc}
*/
@Override
protected void saveInternals(final File nodeInternDir, final ExecutionMonitor exec) throws IOException, CanceledExecutionException {
if (m_hiliting.getBooleanValue()) {
final NodeSettings config = new NodeSettings("hilite_mapping");
((DefaultHiLiteMapper) m_translator.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 UnpivotNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec inSpec = inData[0].getSpec();
List<String> orderColumns = m_orderColumns.getIncludeList();
List<String> valueColumns = m_valueColumns.getIncludeList();
int[] orderColumnIdx = new int[orderColumns.size()];
for (int i = 0; i < orderColumnIdx.length; i++) {
orderColumnIdx[i] = inSpec.findColumnIndex(orderColumns.get(i));
}
final double newRowCnt = inData[0].getRowCount() * valueColumns.size();
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);
for (DataRow row : inData[0]) {
LinkedHashSet<RowKey> set = new LinkedHashSet<RowKey>();
FilterColumnRow crow = new FilterColumnRow(row, orderColumnIdx);
for (int i = 0; i < valueColumns.size(); i++) {
String colName = valueColumns.get(i);
DataCell acell = row.getCell(inSpec.findColumnIndex(colName));
if (acell.isMissing() && m_missingValues.getBooleanValue()) {
// 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