Search in sources :

Example 21 with DefaultHiLiteMapper

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper)

Example 22 with DefaultHiLiteMapper

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)));
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) FileOutputStream(java.io.FileOutputStream) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) File(java.io.File)

Example 23 with DefaultHiLiteMapper

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;
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper)

Example 24 with DefaultHiLiteMapper

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"))));
    }
}
Also used : NodeSettings(org.knime.core.node.NodeSettings) GZIPOutputStream(java.util.zip.GZIPOutputStream) FileOutputStream(java.io.FileOutputStream) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) File(java.io.File)

Example 25 with DefaultHiLiteMapper

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() };
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DataTableSpec(org.knime.core.data.DataTableSpec) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) DataRow(org.knime.core.data.DataRow) LinkedHashMap(java.util.LinkedHashMap) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DefaultHiLiteMapper(org.knime.core.node.property.hilite.DefaultHiLiteMapper) FilterColumnRow(org.knime.base.data.filter.column.FilterColumnRow) AppendedColumnRow(org.knime.base.data.append.column.AppendedColumnRow)

Aggregations

DefaultHiLiteMapper (org.knime.core.node.property.hilite.DefaultHiLiteMapper)35 File (java.io.File)16 FileOutputStream (java.io.FileOutputStream)16 NodeSettings (org.knime.core.node.NodeSettings)16 Set (java.util.Set)12 RowKey (org.knime.core.data.RowKey)12 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 GZIPOutputStream (java.util.zip.GZIPOutputStream)9 DataRow (org.knime.core.data.DataRow)8 DataTableSpec (org.knime.core.data.DataTableSpec)8 DataCell (org.knime.core.data.DataCell)7 DefaultRow (org.knime.core.data.def.DefaultRow)7 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)7 HashMap (java.util.HashMap)6 LinkedHashSet (java.util.LinkedHashSet)6 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)6 LinkedHashMap (java.util.LinkedHashMap)5 IOException (java.io.IOException)4 HashSet (java.util.HashSet)4 DataColumnSpec (org.knime.core.data.DataColumnSpec)4