Search in sources :

Example 91 with DefaultRow

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);
}
Also used : FileReaderException(org.knime.base.node.io.filereader.FileReaderException) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow)

Example 92 with DefaultRow

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataCellFactory(org.knime.base.node.io.filereader.DataCellFactory) ColProperty(org.knime.base.node.io.filereader.ColProperty) DataRow(org.knime.core.data.DataRow) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) HashSet(java.util.HashSet)

Example 93 with DefaultRow

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])));
    }
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) LinkedList(java.util.LinkedList) IntCell(org.knime.core.data.def.IntCell)

Example 94 with DefaultRow

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);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 95 with DefaultRow

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();
}
Also used : DataColumnSpec(org.knime.core.data.DataColumnSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DefaultRow(org.knime.core.data.def.DefaultRow)

Aggregations

DefaultRow (org.knime.core.data.def.DefaultRow)207 DataCell (org.knime.core.data.DataCell)165 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)94 DataTableSpec (org.knime.core.data.DataTableSpec)92 DataRow (org.knime.core.data.DataRow)88 RowKey (org.knime.core.data.RowKey)80 DoubleCell (org.knime.core.data.def.DoubleCell)66 StringCell (org.knime.core.data.def.StringCell)65 BufferedDataTable (org.knime.core.node.BufferedDataTable)56 IntCell (org.knime.core.data.def.IntCell)46 ArrayList (java.util.ArrayList)26 DataType (org.knime.core.data.DataType)26 DataColumnSpec (org.knime.core.data.DataColumnSpec)22 DataContainer (org.knime.core.data.container.DataContainer)21 HashSet (java.util.HashSet)18 LinkedHashMap (java.util.LinkedHashMap)17 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 LinkedHashSet (java.util.LinkedHashSet)14 DoubleValue (org.knime.core.data.DoubleValue)14 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)14