Search in sources :

Example 1 with DataCellTypeConverter

use of org.knime.core.data.DataCellTypeConverter in project knime-core by knime.

the class RearrangeColumnsTable method applyDataTypeConverters.

/**
 * Used when {@link ColumnRearranger#ensureColumnIsConverted(DataCellTypeConverter, int)} is called. It
 * preproccesses the row and replaces the column to be converted by the the result of the given converter.
 *
 * @param row The original input row.
 * @param producerMap The object having the converter list (or not)
 * @param newCells
 * @return The input row if no converter applied or a modified copy of the input row.
 */
private static DataRow applyDataTypeConverters(final DataRow row, final NewColumnsProducerMapping producerMap, final DataCell[] newCells) {
    List<Pair<SpecAndFactoryObject, Integer>> converterToIndexMap = producerMap.getConverterToIndexMap();
    if (!converterToIndexMap.isEmpty()) {
        DataCell[] inputRowCells = new DataCell[row.getNumCells()];
        for (int i = 0; i < inputRowCells.length; i++) {
            inputRowCells[i] = row instanceof BlobSupportDataRow ? ((BlobSupportDataRow) row).getRawCell(i) : row.getCell(i);
        }
        for (Pair<SpecAndFactoryObject, Integer> entry : converterToIndexMap) {
            SpecAndFactoryObject specAndObject = entry.getFirst();
            DataCellTypeConverter converter = specAndObject.getConverter();
            int converterIndex = specAndObject.getConverterIndex();
            Integer index = entry.getSecond();
            DataCell convertedCell = converter.callConvert(row.getCell(converterIndex));
            newCells[index] = convertedCell;
            inputRowCells[converterIndex] = convertedCell;
        }
        return new BlobSupportDataRow(row.getKey(), inputRowCells);
    }
    return row;
}
Also used : DataCellTypeConverter(org.knime.core.data.DataCellTypeConverter) SpecAndFactoryObject(org.knime.core.data.container.ColumnRearranger.SpecAndFactoryObject) DataCell(org.knime.core.data.DataCell) Pair(org.knime.core.util.Pair)

Aggregations

DataCell (org.knime.core.data.DataCell)1 DataCellTypeConverter (org.knime.core.data.DataCellTypeConverter)1 SpecAndFactoryObject (org.knime.core.data.container.ColumnRearranger.SpecAndFactoryObject)1 Pair (org.knime.core.util.Pair)1