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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations