Search in sources :

Example 6 with IntValue

use of org.knime.core.data.IntValue in project knime-core by knime.

the class TableSorterTest method runMemoryTest.

private void runMemoryTest(final int numRows, final int maxNumRowsPerContainer, final int maxOpenContainers) throws CanceledExecutionException {
    // Create data with fields that consume a lot memory
    DataTable inputTable = new TestData(numRows, 1);
    BufferedDataTable bdt = m_exec.createBufferedDataTable(inputTable, m_exec);
    BufferedDataTableSorter sorter = new BufferedDataTableSorter(bdt, Arrays.asList("Index"), new boolean[] { true });
    sorter.setMaxOpenContainers(maxOpenContainers);
    BufferedDataTable defaultResult = sorter.sort(m_exec);
    sorter.setMaxRows(maxNumRowsPerContainer);
    // 10MB free memory
    long currentlyUsed = MemoryAlertSystem.getUsedMemory();
    double fraction = Math.min(1, (currentlyUsed + (10 << 20)) / (double) MemoryAlertSystem.getMaximumMemory());
    MemoryAlertSystem.getInstance().setFractionUsageThreshold(fraction);
    try {
        sorter.setMemService(MemoryAlertSystem.getInstance());
        // run again with change settings
        BufferedDataTable result = sorter.sort(m_exec);
        // Check if column is sorted in ascending order
        int prevValue = Integer.MIN_VALUE;
        for (DataRow row : result) {
            int thisValue = ((IntValue) row.getCell(0)).getIntValue();
            Assert.assertTrue(thisValue >= prevValue);
        }
        // Check if it has the same results as defaultResult
        Assert.assertTrue(defaultResult.getRowCount() == result.getRowCount());
        RowIterator defaultIter = defaultResult.iterator();
        RowIterator iter = result.iterator();
        while (defaultIter.hasNext()) {
            DataRow defaultRow = defaultIter.next();
            DataRow row = iter.next();
            Assert.assertTrue(defaultRow.getKey().getString().equals(row.getKey().getString()));
            Iterator<DataCell> defaultCellIter = defaultRow.iterator();
            Iterator<DataCell> cellIter = row.iterator();
            while (defaultCellIter.hasNext()) {
                Assert.assertTrue(defaultCellIter.next().equals(cellIter.next()));
            }
        }
    } finally {
        MemoryAlertSystem.getInstance().setFractionUsageThreshold(MemoryAlertSystem.DEFAULT_USAGE_THRESHOLD);
    }
}
Also used : DataTable(org.knime.core.data.DataTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) RowIterator(org.knime.core.data.RowIterator) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DataRow(org.knime.core.data.DataRow) IntValue(org.knime.core.data.IntValue)

Example 7 with IntValue

use of org.knime.core.data.IntValue in project knime-core by knime.

the class CreateByteVectorNodeModel method createRearranger.

private ColumnRearranger createRearranger(final DataTableSpec inSpec) {
    final ColumnRearranger ret = new ColumnRearranger(inSpec);
    final String[] includes = m_inputColumns.applyTo(inSpec).getIncludes();
    if (m_removeInput.getBooleanValue()) {
        ret.remove(includes);
    }
    final DataColumnSpecCreator newCol = new DataColumnSpecCreator(DataTableSpec.getUniqueColumnName(inSpec, m_outputColumn.getStringValue()), DenseByteVectorCell.TYPE);
    newCol.setElementNames(includes);
    final int[] sourceColumnIndices = SourceColumnsAsProperties.indices(m_inputColumns.applyTo(inSpec), inSpec);
    for (int i = sourceColumnIndices.length; i-- > 0; ) {
        if (sourceColumnIndices[i] < 0) {
            throw new IllegalStateException("Unknown column: " + includes[i]);
        }
    }
    ret.append(new SingleCellFactory(newCol.createSpec()) {

        @Override
        public DataCell getCell(final DataRow row) {
            final DenseByteVectorCellFactory fac = new DenseByteVectorCellFactory(sourceColumnIndices.length);
            for (int i = sourceColumnIndices.length; i-- > 0; ) {
                DataCell cell = row.getCell(sourceColumnIndices[i]);
                if (cell.isMissing()) {
                    if (m_failOnMissing.getBooleanValue()) {
                        throw new IllegalArgumentException("Missing value in the row: " + row.getKey() + "\nin the column: " + includes[i]);
                    } else {
                        // return DataType.getMissingCell();
                        fac.setValue(i, 0);
                    }
                } else if (cell instanceof IntValue) {
                    int intValue = ((IntValue) cell).getIntValue();
                    if (intValue < 0 || intValue > 255) {
                        if (m_failOnOutOfInterval.getBooleanValue()) {
                            throw new IllegalArgumentException("Invalid value: " + intValue + "\nin row: " + row.getKey() + "\nin the column: " + includes[i]);
                        } else {
                            fac.setValue(i, 0);
                        }
                    } else {
                        fac.setValue(i, intValue);
                    }
                } else {
                    throw new IllegalStateException("Not an int value: " + cell + " (" + cell.getType() + ")");
                }
            }
            return fac.createDataCell();
        }
    });
    return ret;
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) DataRow(org.knime.core.data.DataRow) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DenseByteVectorCellFactory(org.knime.core.data.vector.bytevector.DenseByteVectorCellFactory) DataCell(org.knime.core.data.DataCell) SingleCellFactory(org.knime.core.data.container.SingleCellFactory) IntValue(org.knime.core.data.IntValue)

Example 8 with IntValue

use of org.knime.core.data.IntValue in project knime-core by knime.

the class LinearInterpolationStatisticTB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(getColumnIndex());
    if (cell.isMissing()) {
        incMissing();
    } else {
        for (int i = 0; i < getNumMissing(); i++) {
            DataCell res;
            if (getPrevious().isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev));
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) getPrevious()).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
                    if (getPrevious() instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (getPrevious() instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            addMapping(res);
        }
        resetMissing(cell);
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 9 with IntValue

use of org.knime.core.data.IntValue in project knime-core by knime.

the class AverageInterpolationStatisticTB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(getColumnIndex());
    if (cell.isMissing()) {
        incMissing();
    } else {
        for (int i = 0; i < getNumMissing(); i++) {
            DataCell res;
            if (getPrevious().isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round((prev + next) / 2);
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) getPrevious()).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = (prev + next) / 2;
                    if (getPrevious() instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (getPrevious() instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            addMapping(res);
        }
        resetMissing(cell);
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 10 with IntValue

use of org.knime.core.data.IntValue in project knime-core by knime.

the class LinearInterpolationStatisticMB method consumeRow.

/**
 * {@inheritDoc}
 */
@Override
protected void consumeRow(final DataRow dataRow) {
    DataCell cell = dataRow.getCell(m_colIdx);
    if (cell.isMissing()) {
        m_numMissing++;
    } else {
        for (int i = 0; i < m_numMissing; i++) {
            DataCell res;
            if (m_previous.isMissing()) {
                res = cell;
            } else {
                if (m_isDateColumn) {
                    DateAndTimeValue val = (DateAndTimeValue) cell;
                    DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
                    boolean hasDate = val.hasDate() | prevVal.hasDate();
                    boolean hasTime = val.hasTime() | prevVal.hasTime();
                    boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
                    long prev = prevVal.getUTCTimeInMillis();
                    long next = val.getUTCTimeInMillis();
                    long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev));
                    res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
                } else {
                    DoubleValue val = (DoubleValue) cell;
                    double prev = ((DoubleValue) m_previous).getDoubleValue();
                    double next = val.getDoubleValue();
                    double lin = prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev);
                    if (m_previous instanceof IntValue) {
                        // get an int, create an int
                        res = new IntCell((int) Math.round(lin));
                    } else if (m_previous instanceof LongValue) {
                        // get an long, create an long
                        res = new LongCell(Math.round(lin));
                    } else {
                        res = new DoubleCell(lin);
                    }
                }
            }
            m_values.add(res);
        }
        m_numMissing = 0;
        m_previous = cell;
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Aggregations

IntValue (org.knime.core.data.IntValue)19 DoubleValue (org.knime.core.data.DoubleValue)14 DataCell (org.knime.core.data.DataCell)12 LongValue (org.knime.core.data.LongValue)10 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)10 DataRow (org.knime.core.data.DataRow)6 DateAndTimeCell (org.knime.core.data.date.DateAndTimeCell)6 DoubleCell (org.knime.core.data.def.DoubleCell)6 IntCell (org.knime.core.data.def.IntCell)6 LongCell (org.knime.core.data.def.LongCell)6 SQLException (java.sql.SQLException)4 BooleanValue (org.knime.core.data.BooleanValue)4 DataTableSpec (org.knime.core.data.DataTableSpec)4 BinaryObjectDataValue (org.knime.core.data.blob.BinaryObjectDataValue)4 BufferedDataTable (org.knime.core.node.BufferedDataTable)4 IOException (java.io.IOException)3 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 StringValue (org.knime.core.data.StringValue)3 InputStream (java.io.InputStream)2 PreparedStatement (java.sql.PreparedStatement)2