use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class FixedWidthRowIterator method prepareForException.
/*
* !!!!!!!!!! Creates the exception object (storing the last read items in
* the row of the exception), sets the global "exception thrown" flag, and
* closes the input stream. !!!!!!!!!!
*/
private FileReaderException prepareForException(final String msg, final int lineNumber, final String rowHeader, final DataCell[] cellsRead) {
/*
* indicate we have thrown (actually will throw...) an exception, and
* close the stream as we will not read anymore from the stream after
* the exception.
*/
m_exceptionThrown = true;
DataCell[] errCells = new DataCell[cellsRead.length];
System.arraycopy(cellsRead, 0, errCells, 0, errCells.length);
for (int c = 0; c < errCells.length; c++) {
if (errCells[c] == null) {
errCells[c] = DataType.getMissingCell();
}
}
String errRowHeader = "ERROR_ROW (" + rowHeader.toString() + ")";
DataRow errRow = new DefaultRow(errRowHeader, errCells);
return new FileReaderException(msg, errRow, lineNumber);
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class TableCreator2NodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
DataTableSpec outSpec = createSpec();
BufferedDataContainer cont = exec.createDataContainer(outSpec, true);
int numColProps = m_settings.getColumnProperties().size();
ColProperty[] colProps = new ColProperty[numColProps];
for (int i = 0; i < numColProps; i++) {
colProps[i] = m_settings.getColumnProperties().get(i);
}
int cc = 0;
int[] notSkippedMap = new int[numColProps];
for (int i = 0; i < numColProps; i++) {
notSkippedMap[i] = cc;
if (!colProps[i].getSkipThisColumn()) {
cc++;
}
}
int numRows = max(m_settings.getRowIndices()) + 1;
String rowIdPrefix = m_settings.getRowIdPrefix();
String rowIdSuffix = m_settings.getRowIdSuffix();
int rowIdStartWidth = m_settings.getRowIdStartValue();
int c = 0;
// fix for bug #2969
Set<Integer> toRemove = new HashSet<Integer>();
DataCellFactory cellFactory = new DataCellFactory();
for (int i = 0; i < numRows; i++) {
DataCell[] cells = new DataCell[outSpec.getNumColumns()];
for (int k = 0; k < numColProps; k++) {
// fix for bug #2969
while (c < m_settings.getRowIndices().length && (m_settings.getRowIndices()[c] < 0 || m_settings.getColumnIndices()[c] < 0)) {
toRemove.add(c);
c++;
}
String value = "";
if (c < m_settings.getRowIndices().length && m_settings.getRowIndices()[c] == i && m_settings.getColumnIndices()[c] == k) {
value = m_settings.getValues()[c];
c++;
}
if (colProps[k].getSkipThisColumn()) {
continue;
}
String missValPattern = colProps[k].getMissingValuePattern();
cellFactory.setMissingValuePattern(missValPattern);
cellFactory.setFormatParameter(colProps[k].getFormatParameter().orElse(null));
DataCell result = cellFactory.createDataCellOfType(colProps[k].getColumnSpec().getType(), value);
if (null != result) {
cells[notSkippedMap[k]] = result;
} else {
throw new InvalidSettingsException(cellFactory.getErrorMessage());
}
}
StringBuilder rowId = new StringBuilder();
rowId.append(rowIdPrefix);
rowId.append(Integer.toString(i + rowIdStartWidth));
rowId.append(rowIdSuffix);
DataRow row = new DefaultRow(rowId.toString(), cells);
cont.addRowToTable(row);
}
cont.close();
BufferedDataTable out = cont.getTable();
return new BufferedDataTable[] { out };
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class NumericalAttributeModel method createDataRows.
/**
* {@inheritDoc}
*/
@Override
void createDataRows(final ExecutionMonitor exec, final BufferedDataContainer dc, final boolean ignoreMissing, final AtomicInteger rowId) throws CanceledExecutionException {
final List<String> sortedClassVal = AttributeModel.sortCollection(m_classValues.keySet());
if (sortedClassVal == null) {
return;
}
final StringCell attributeCell = new StringCell(getAttributeName());
for (final String classVal : sortedClassVal) {
final List<DataCell> cells = new LinkedList<>();
cells.add(attributeCell);
cells.add(DataType.getMissingCell());
cells.add(new StringCell(classVal));
final NumericalClassValue classValue = m_classValues.get(classVal);
cells.add(new IntCell(classValue.getNoOfNotMissingRows()));
if (!ignoreMissing) {
cells.add(new IntCell(classValue.getNoOfMissingValueRecs()));
}
cells.add(new DoubleCell(classValue.getMean()));
cells.add(new DoubleCell(classValue.getStdDeviation()));
dc.addRowToTable(new DefaultRow(RowKey.createRowKey(rowId.getAndIncrement()), cells.toArray(new DataCell[0])));
}
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class Statistics3Table method createRow.
private DataRow createRow(final String key, final double[] array) {
int idx = 0;
DataTableSpec outSpec = createOutSpecNumeric(m_spec);
DataCell[] data = new DataCell[outSpec.getNumColumns()];
for (int i = 0; idx < data.length; i++) {
if (outSpec.getColumnSpec(idx).getName().equals(m_spec.getColumnSpec(i).getName())) {
if (Double.isNaN(array[i])) {
data[idx] = DataType.getMissingCell();
} else {
data[idx] = new DoubleCell(array[i]);
}
idx++;
}
}
return new DefaultRow(key, data);
}
use of org.knime.core.data.def.DefaultRow in project knime-core by knime.
the class Statistics3Table method createStatisticsInColumnsTable.
/**
* Creates the statistics in transposed compared to the original.
*
* @param exec An {@link ExecutionContext}.
* @return Statistics {@link BufferedDataTable} with skewness and kurtosis in a transposed form.
* @since 2.9
*/
public BufferedDataTable createStatisticsInColumnsTable(final ExecutionContext exec) {
BufferedDataContainer container = exec.createDataContainer(getStatisticsSpecification());
int colIdx = 0;
for (DataColumnSpec spec : m_spec) {
if (spec.getType().isCompatible(DoubleValue.class)) {
container.addRowToTable(new DefaultRow(spec.getName(), createRow(spec.getName(), colIdx)));
}
colIdx++;
}
container.close();
return container.getTable();
}
Aggregations