Search in sources :

Example 26 with SingleCellFactory

use of org.knime.core.data.container.SingleCellFactory in project knime-core by knime.

the class DBDeleteRowsNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final DataTableSpec inSpec, final int[] updateStatus) {
    final String updateColumn = DataTableSpec.getUniqueColumnName(inSpec, DELETE_ROWS_COLUMN);
    final DataColumnSpec cspec = new DataColumnSpecCreator(updateColumn, IntCell.TYPE).createSpec();
    final ColumnRearranger rearr = new ColumnRearranger(inSpec);
    rearr.append(new SingleCellFactory(cspec) {

        private int m_rowCount = 0;

        @Override
        public DataCell getCell(final DataRow row) {
            return new IntCell(updateStatus[m_rowCount++]);
        }
    });
    return rearr;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataCell(org.knime.core.data.DataCell) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 27 with SingleCellFactory

use of org.knime.core.data.container.SingleCellFactory in project knime-core by knime.

the class CollectionCreateNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final DataTableSpec in) throws InvalidSettingsException {
    List<String> includes = m_includeModel.getIncludeList();
    if (includes == null || includes.isEmpty()) {
        throw new InvalidSettingsException("Select columns to aggregate");
    }
    String[] names = includes.toArray(new String[includes.size()]);
    final int[] colIndices = new int[names.length];
    for (int i = 0; i < names.length; i++) {
        int index = in.findColumnIndex(names[i]);
        if (index < 0) {
            throw new InvalidSettingsException("No column \"" + names[i] + "\" in input table");
        }
        colIndices[i] = index;
    }
    DataType comType = CollectionCellFactory.getElementType(in, colIndices);
    String newColName = m_newColName.getStringValue();
    DataType type;
    if (m_createSet.getBooleanValue()) {
        type = SetCell.getCollectionType(comType);
    } else {
        type = ListCell.getCollectionType(comType);
    }
    DataColumnSpecCreator newColSpecC = new DataColumnSpecCreator(newColName, type);
    newColSpecC.setElementNames(names);
    DataColumnSpec newColSpec = newColSpecC.createSpec();
    CellFactory appendFactory = new SingleCellFactory(newColSpec) {

        /**
         * {@inheritDoc}
         */
        @Override
        public DataCell getCell(final DataRow row) {
            if (m_createSet.getBooleanValue()) {
                return CollectionCellFactory.createSetCell(row, colIndices);
            } else {
                return CollectionCellFactory.createListCell(row, colIndices);
            }
        }
    };
    ColumnRearranger rearranger = new ColumnRearranger(in);
    if (m_removeCols.getBooleanValue()) {
        rearranger.remove(colIndices);
    }
    rearranger.append(appendFactory);
    return rearranger;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) SettingsModelFilterString(org.knime.core.node.defaultnodesettings.SettingsModelFilterString) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataRow(org.knime.core.data.DataRow) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) CellFactory(org.knime.core.data.container.CellFactory) CollectionCellFactory(org.knime.core.data.collection.CollectionCellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory)

Example 28 with SingleCellFactory

use of org.knime.core.data.container.SingleCellFactory in project knime-core by knime.

the class DBUpdateNodeModel method createColumnRearranger.

private ColumnRearranger createColumnRearranger(final DataTableSpec inSpec, final int[] updateStatus) {
    final String updateColumn = DataTableSpec.getUniqueColumnName(inSpec, UPDATE_COLUMN);
    final DataColumnSpec cspec = new DataColumnSpecCreator(updateColumn, IntCell.TYPE).createSpec();
    final ColumnRearranger rearr = new ColumnRearranger(inSpec);
    rearr.append(new SingleCellFactory(cspec) {

        private int m_rowCount = 0;

        @Override
        public DataCell getCell(final DataRow row) {
            return new IntCell(updateStatus[m_rowCount++]);
        }
    });
    return rearr;
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataCell(org.knime.core.data.DataCell) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 29 with SingleCellFactory

use of org.knime.core.data.container.SingleCellFactory in project knime-core by knime.

the class CollectionCreate2NodeModel method createColumnRearranger.

@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec in) throws InvalidSettingsException {
    FilterResult filterResult = m_includeModel.applyTo(in);
    List<String> includes = Arrays.asList(filterResult.getIncludes());
    String[] names = includes.toArray(new String[includes.size()]);
    final int[] colIndices = new int[names.length];
    for (int i = 0; i < names.length; i++) {
        int index = in.findColumnIndex(names[i]);
        if (index < 0) {
            throw new InvalidSettingsException("No column \"" + names[i] + "\" in input table");
        }
        colIndices[i] = index;
    }
    DataType comType;
    if (includes.size() == 0) {
        comType = DataType.getType(DataCell.class);
    } else {
        comType = CollectionCellFactory.getElementType(in, colIndices);
    }
    String newColName = m_newColName.getStringValue();
    DataType type;
    if (m_createSet.getBooleanValue()) {
        type = SetCell.getCollectionType(comType);
    } else {
        type = ListCell.getCollectionType(comType);
    }
    DataColumnSpecCreator newColSpecC = new DataColumnSpecCreator(newColName, type);
    newColSpecC.setElementNames(names);
    DataColumnSpec newColSpec = newColSpecC.createSpec();
    CellFactory appendFactory = new SingleCellFactory(newColSpec) {

        /**
         * {@inheritDoc}
         */
        @Override
        public DataCell getCell(final DataRow row) {
            int[] validColIndices = colIndices;
            // iff ignore missing value is switched on
            if (m_ignoreMissing.getBooleanValue()) {
                List<Integer> vCI = new ArrayList<Integer>();
                for (int i : validColIndices) {
                    if (!row.getCell(i).isMissing()) {
                        vCI.add(i);
                    }
                }
                validColIndices = buildIntArray(vCI);
            }
            // based on given column indices
            if (m_createSet.getBooleanValue()) {
                return CollectionCellFactory.createSetCell(row, validColIndices);
            } else {
                return CollectionCellFactory.createListCell(row, validColIndices);
            }
        }
    };
    ColumnRearranger rearranger = new ColumnRearranger(in);
    if (m_removeCols.getBooleanValue()) {
        rearranger.remove(colIndices);
    }
    rearranger.append(appendFactory);
    return rearranger;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataRow(org.knime.core.data.DataRow) DataColumnSpec(org.knime.core.data.DataColumnSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) FilterResult(org.knime.core.node.util.filter.NameFilterConfiguration.FilterResult) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) CellFactory(org.knime.core.data.container.CellFactory) CollectionCellFactory(org.knime.core.data.collection.CollectionCellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory)

Example 30 with SingleCellFactory

use of org.knime.core.data.container.SingleCellFactory in project knime-core by knime.

the class SearchReplaceDictNodeModel method createColumnRearranger.

@Override
protected ColumnRearranger createColumnRearranger(final DataTableSpec spec) {
    ColumnRearranger result = new ColumnRearranger(spec);
    final int targetColIndex = spec.findColumnIndex(m_targetColumnName);
    DataColumnSpecCreator newColCreator;
    if (m_newColumnName == null) {
        DataColumnSpec old = spec.getColumnSpec(m_targetColumnName);
        newColCreator = new DataColumnSpecCreator(old);
        newColCreator.setType(StringCell.TYPE);
        newColCreator.setDomain(null);
    } else {
        newColCreator = new DataColumnSpecCreator(m_newColumnName, StringCell.TYPE);
    }
    CellFactory amendedCol = new SingleCellFactory(newColCreator.createSpec()) {

        @Override
        public DataCell getCell(final DataRow row) {
            DataCell c = row.getCell(targetColIndex);
            if (c.isMissing()) {
                return c;
            }
            String cellContent = c.toString();
            String replacement = m_replacementMap.get(cellContent);
            if (replacement != null) {
                return new StringCell(replacement);
            } else {
                // StringCell.TYPE!)
                return new StringCell(cellContent);
            }
        }
    };
    if (m_newColumnName != null) {
        result.append(amendedCol);
    } else {
        result.replace(amendedCol, targetColIndex);
    }
    return result;
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DataColumnSpec(org.knime.core.data.DataColumnSpec) StringCell(org.knime.core.data.def.StringCell) DataCell(org.knime.core.data.DataCell) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) CellFactory(org.knime.core.data.container.CellFactory) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) DataRow(org.knime.core.data.DataRow)

Aggregations

SingleCellFactory (org.knime.core.data.container.SingleCellFactory)48 DataRow (org.knime.core.data.DataRow)47 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)41 DataCell (org.knime.core.data.DataCell)40 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)35 DataColumnSpec (org.knime.core.data.DataColumnSpec)34 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)19 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)19 DataType (org.knime.core.data.DataType)12 CellFactory (org.knime.core.data.container.CellFactory)12 StringCell (org.knime.core.data.def.StringCell)10 Calendar (java.util.Calendar)8 DataTableSpec (org.knime.core.data.DataTableSpec)8 StringValue (org.knime.core.data.StringValue)8 DateAndTimeCell (org.knime.core.data.date.DateAndTimeCell)8 ArrayList (java.util.ArrayList)7 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)6 SettingsModelCalendar (org.knime.timeseries.util.SettingsModelCalendar)5 ParseException (java.text.ParseException)4 ZonedDateTime (java.time.ZonedDateTime)4