Search in sources :

Example 51 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class ConcatenateTableFactory method addTable.

/**
 * All rows of the given row input are added to a new data container. Creates a new data container if this data
 * table spec differs from the previous table. This method call checks for row keys duplicates and throws a
 * {@link DuplicateKeyException}.
 *
 * @param table the table to be added
 * @param exec the execution context to possibly create a new data container
 * @throws InterruptedException
 * @throws IOException
 * @throws DuplicateKeyException
 * @throws CanceledExecutionException
 */
void addTable(final RowInput table, final ExecutionContext exec) throws InterruptedException, DuplicateKeyException, IOException, CanceledExecutionException {
    // check if last container has been closed (i.e. createTable was called)
    if (m_tables.size() > 0) {
        if (m_tables.get(m_tables.size() - 1).isClosed()) {
            throw new IllegalStateException("No more tables can be added! ConcatenateTable has already been created.");
        }
    }
    // poll first row in order to check whether the incoming table is empty
    DataRow row = table.poll();
    if (row == null) {
        // table is empty
        if (m_ignoreEmptyTables && m_tables.size() > 0) {
            m_iterationCount++;
            return;
        } else if (m_tables.size() == 0) {
            // if this is the first table we receive and its empty, create an empty one and keep it
            m_emptyTable = exec.createDataContainer(createSpec(table.getDataTableSpec(), m_addIterationColumn, false));
            m_iterationCount++;
            return;
        }
    }
    // compare spec of the current table with the spec of the first table if changing specs are not tolerated
    if (!m_tolerateChangingSpecs && (m_tables.size() > 0 || m_emptyTable != null)) {
        if (!(m_ignoreEmptyTables && (row == null || m_emptyTable != null))) {
            // don't fail if table is empty and to be ignored
            // create spec for comparision -> set the most common column type for both table spec, if altered column types
            // are to be tolerated
            DataTableSpec tmpSpec1;
            if (m_tables.size() == 0 && m_emptyTable != null) {
                tmpSpec1 = createSpec(m_emptyTable.getTableSpec(), false, m_tolerateColumnTypes);
            } else {
                tmpSpec1 = createSpec(m_tables.get(0).getTableSpec(), false, m_tolerateColumnTypes);
            }
            DataTableSpec tmpSpec2 = createSpec(table.getDataTableSpec(), m_addIterationColumn, m_tolerateColumnTypes);
            // fail if specs has been changed
            compareSpecsAndFail(tmpSpec1, tmpSpec2);
        }
    }
    // if table is empty and they are not to be ignored, nothing else to do -> return now
    if (row == null) {
        m_iterationCount++;
        return;
    }
    // if there are too much tables -> create one new and copy the whole data
    if (m_tables.size() > MAX_NUM_TABLES) {
        copyTablesIntoOneTable(exec);
    }
    // create a new data container except the previously added has the same data table spec -> problem: if in each iteration a new row is added we
    // end up with quite many data containers
    BufferedDataContainer con;
    DataTableSpec newTableSpec = createSpec(table.getDataTableSpec(), m_addIterationColumn, false);
    if (m_tables.size() == 0) {
        con = exec.createDataContainer(newTableSpec);
        m_tables.add(con);
    } else if (m_tables.size() > 0 && !newTableSpec.equalStructure(m_tables.get(m_tables.size() - 1).getTableSpec())) {
        con = m_tables.get(m_tables.size() - 1);
        con.close();
        con = exec.createDataContainer(newTableSpec);
        m_tables.add(con);
    } else {
        con = m_tables.get(m_tables.size() - 1);
    }
    // add rows of the table to the newly created data container
    do {
        exec.checkCanceled();
        // change row key if desired
        if (m_rowKeyCreator != null) {
            // change row key
            row = new BlobSupportDataRow(m_rowKeyCreator.apply(row.getKey()), row);
        }
        m_duplicateChecker.addKey(row.getKey().toString());
        // add additional iteration column if desired
        if (m_addIterationColumn) {
            IntCell currIterCell = new IntCell(m_iterationCount);
            row = new org.knime.core.data.append.AppendedColumnRow(row, currIterCell);
        }
        con.addRowToTable(row);
    } while ((row = table.poll()) != null);
    m_iterationCount++;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BlobSupportDataRow(org.knime.core.data.container.BlobSupportDataRow) DataRow(org.knime.core.data.DataRow) IntCell(org.knime.core.data.def.IntCell)

Example 52 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class Statistics3Table method createRow.

/**
 * Creates a row for the transposed table.
 *
 * @param name The name of the column.
 * @param colIdx The index of column in the computed values.
 * @return The cells according to {@link #STATISTICS_SPECIFICATION}.
 */
private DataCell[] createRow(final String name, final int colIdx) {
    final DataCell[] ret = new DataCell[getStatisticsSpecification().getNumColumns()];
    int i = 0;
    ret[i++] = new StringCell(name);
    ret[i++] = m_minCells[colIdx];
    ret[i++] = m_maxCells[colIdx];
    ret[i++] = new DoubleCell(m_meanValues[colIdx]);
    ret[i++] = new DoubleCell(Math.sqrt(m_varianceValues[colIdx]));
    ret[i++] = new DoubleCell(m_varianceValues[colIdx]);
    ret[i++] = new DoubleCell(m_skewness[colIdx]);
    ret[i++] = new DoubleCell(m_kurtosis[colIdx]);
    ret[i++] = new DoubleCell(m_sum[colIdx]);
    ret[i++] = new IntCell(m_missingValueCnt[colIdx]);
    ret[i++] = new IntCell(m_nanValueCnt[colIdx]);
    ret[i++] = new IntCell(m_posInfinityValueCnt[colIdx]);
    ret[i++] = new IntCell(m_negInfinityValueCnt[colIdx]);
    ret[i++] = Double.isNaN(m_median[colIdx]) ? DataType.getMissingCell() : new DoubleCell(m_median[colIdx]);
    ret[i++] = new IntCell(m_rowCount);
    return ret;
}
Also used : StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DataCell(org.knime.core.data.DataCell) BlobWrapperDataCell(org.knime.core.data.container.BlobWrapperDataCell) IntCell(org.knime.core.data.def.IntCell)

Example 53 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class VariableToTable2NodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    DataTableSpec spec = createOutSpec();
    BufferedDataContainer cont = exec.createDataContainer(spec);
    List<Pair<String, FlowVariable.Type>> vars = getVariablesOfInterest();
    DataCell[] specs = new DataCell[vars.size()];
    List<String> lostVariables = new ArrayList<String>();
    for (int i = 0; i < vars.size(); i++) {
        Pair<String, FlowVariable.Type> c = vars.get(i);
        String name = c.getFirst();
        // fallback
        DataCell cell = DataType.getMissingCell();
        switch(c.getSecond()) {
            case DOUBLE:
                try {
                    double dValue = peekFlowVariableDouble(c.getFirst());
                    cell = new DoubleCell(dValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (Double)");
                }
                break;
            case INTEGER:
                try {
                    int iValue = peekFlowVariableInt(c.getFirst());
                    cell = new IntCell(iValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (Integer)");
                }
                break;
            case STRING:
                try {
                    String sValue = peekFlowVariableString(c.getFirst());
                    sValue = sValue == null ? "" : sValue;
                    cell = new StringCell(sValue);
                } catch (NoSuchElementException e) {
                    lostVariables.add(name + " (String)");
                }
                break;
        }
        specs[i] = cell;
    }
    cont.addRowToTable(new DefaultRow(m_rowID.getStringValue(), specs));
    cont.close();
    return new BufferedDataTable[] { cont.getTable() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DoubleCell(org.knime.core.data.def.DoubleCell) ArrayList(java.util.ArrayList) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) IntCell(org.knime.core.data.def.IntCell) PortType(org.knime.core.node.port.PortType) DataType(org.knime.core.data.DataType) StringCell(org.knime.core.data.def.StringCell) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) NoSuchElementException(java.util.NoSuchElementException) Pair(org.knime.core.util.Pair) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 54 with IntCell

use of org.knime.core.data.def.IntCell 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 55 with IntCell

use of org.knime.core.data.def.IntCell in project knime-core by knime.

the class ExpressionFactoryTest method testColumnRef.

/**
 * Test method for {@link ExpressionFactory#columnRef(DataTableSpec, java.lang.String)} .
 */
@Test
public void testColumnRef() {
    final DefaultRow row0 = new DefaultRow(new RowKey("0"), new IntCell(3));
    final DefaultRow row1 = new DefaultRow(new RowKey("1"), new IntCell(3), new DoubleCell(3.14159));
    final DefaultRow row2 = new DefaultRow(new RowKey("1"), new DoubleCell(3.14159), new StringCell("Hi"));
    final ExpressionValue firstVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num" }, new DataType[] { IntCell.TYPE }), "Num").evaluate(row0, null);
    assertEquals(row0.getCell(0), firstVal.getValue());
    assertEquals(row1.getCell(0), m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Num").evaluate(row0, null).getValue());
    final ExpressionValue secondVal = m_factory.columnRef(new DataTableSpec(new String[] { "Num", "Pi" }, new DataType[] { IntCell.TYPE, DoubleCell.TYPE }), "Pi").evaluate(row1, null);
    assertEquals(row1.getCell(1), secondVal.getValue());
    final ExpressionValue thirdVal = m_factory.columnRef(new DataTableSpec(new String[] { "Pi", "Greeting" }, new DataType[] { DoubleCell.TYPE, StringCell.TYPE }), "Greeting").evaluate(row2, null);
    assertEquals(row2.getCell(1), thirdVal.getValue());
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) DoubleCell(org.knime.core.data.def.DoubleCell) DefaultRow(org.knime.core.data.def.DefaultRow) IntCell(org.knime.core.data.def.IntCell) Test(org.junit.Test)

Aggregations

IntCell (org.knime.core.data.def.IntCell)109 DataCell (org.knime.core.data.DataCell)79 DoubleCell (org.knime.core.data.def.DoubleCell)67 StringCell (org.knime.core.data.def.StringCell)55 DefaultRow (org.knime.core.data.def.DefaultRow)46 DataRow (org.knime.core.data.DataRow)33 DataTableSpec (org.knime.core.data.DataTableSpec)21 RowKey (org.knime.core.data.RowKey)21 ArrayList (java.util.ArrayList)20 DataType (org.knime.core.data.DataType)20 LongCell (org.knime.core.data.def.LongCell)14 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)14 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)12 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 Test (org.junit.Test)11 DataColumnSpec (org.knime.core.data.DataColumnSpec)11 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)9 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)9 DataContainer (org.knime.core.data.container.DataContainer)8 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)8