Search in sources :

Example 11 with LongCell

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

the class RankCellFactory method getCell.

/**
 * {@inheritDoc}
 */
@Override
public DataCell getCell(final DataRow row) {
    // create group identification
    DataCellTuple rowVals = new DataCellTuple(row, m_groupColIndices);
    // get RankAssigner for corresponding group
    RankAssigner rankAssigner = m_groupHashTable.get(rowVals);
    DataCell rankCell = null;
    // check if RankAssigner is registered for group
    if (rankAssigner == null) {
        // create new RankAssigner and register it for this new group
        rankAssigner = createRankAssigner(m_rankMode, m_rankColIndices);
        m_groupHashTable.put(rowVals, rankAssigner);
        // create RankCell
        if (m_rankAsLong) {
            rankCell = new LongCell(rankAssigner.getRank(row));
        } else {
            rankCell = new IntCell((int) rankAssigner.getRank(row));
        }
    } else {
        // create RankCell
        if (m_rankAsLong) {
            rankCell = new LongCell(rankAssigner.getRank(row));
        } else {
            rankCell = new IntCell((int) rankAssigner.getRank(row));
        }
    }
    return rankCell;
}
Also used : LongCell(org.knime.core.data.def.LongCell) DataCell(org.knime.core.data.DataCell) IntCell(org.knime.core.data.def.IntCell)

Example 12 with LongCell

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

the class BatchExecutor method setNodeOptions.

private static void setNodeOptions(final Collection<Option> options, final WorkflowManager wfm) throws InvalidSettingsException, IllegalOptionException {
    for (Option o : options) {
        int[] idPath = o.m_nodeIDs;
        NodeID subID = new NodeID(wfm.getID(), idPath[0]);
        NodeContainer cont = null;
        try {
            cont = wfm.getNodeContainer(subID);
            for (int i = 1; i < idPath.length; i++) {
                if (cont instanceof WorkflowManager) {
                    WorkflowManager subWM = (WorkflowManager) cont;
                    subID = new NodeID(subID, idPath[i]);
                    cont = subWM.getNodeContainer(subID);
                } else {
                    cont = null;
                }
            }
        } catch (IllegalArgumentException ex) {
            // throw by getNodeContainer if no node with the id exists
            cont = null;
        }
        if (cont == null) {
            LOGGER.warn("No node with id " + Arrays.toString(idPath) + " found.");
        } else {
            WorkflowManager parent = cont.getParent();
            NodeSettings settings = new NodeSettings("something");
            parent.saveNodeSettings(cont.getID(), settings);
            NodeSettings model = settings.getNodeSettings(Node.CFG_MODEL);
            String[] splitName = o.m_name.split("/");
            String name = splitName[splitName.length - 1];
            String[] pathElements = new String[splitName.length - 1];
            System.arraycopy(splitName, 0, pathElements, 0, pathElements.length);
            for (String s : pathElements) {
                model = model.getNodeSettings(s);
            }
            if ("int".equals(o.m_type)) {
                model.addInt(name, Integer.parseInt(o.m_value));
            } else if ("long".equals(o.m_type)) {
                model.addLong(name, Long.parseLong(o.m_value));
            } else if ("short".equals(o.m_type)) {
                model.addShort(name, Short.parseShort(o.m_value));
            } else if ("byte".equals(o.m_type)) {
                model.addByte(name, Byte.parseByte(o.m_value));
            } else if ("boolean".equals(o.m_type)) {
                model.addBoolean(name, Boolean.parseBoolean(o.m_value));
            } else if ("char".equals(o.m_type)) {
                model.addChar(name, o.m_value.charAt(0));
            } else if ("float".equals(o.m_type) || ("double".equals(o.m_type))) {
                model.addDouble(name, Double.parseDouble(o.m_value));
            } else if ("String".equals(o.m_type)) {
                model.addString(name, o.m_value);
            } else if ("StringCell".equals(o.m_type)) {
                model.addDataCell(name, new StringCell(o.m_value));
            } else if ("DoubleCell".equals(o.m_type)) {
                double d = Double.parseDouble(o.m_value);
                model.addDataCell(name, new DoubleCell(d));
            } else if ("IntCell".equals(o.m_type)) {
                int i = Integer.parseInt(o.m_value);
                model.addDataCell(name, new IntCell(i));
            } else if ("LongCell".equals(o.m_type)) {
                long i = Long.parseLong(o.m_value);
                model.addDataCell(name, new LongCell(i));
            } else {
                throw new IllegalOptionException("Unknown option type for " + o.m_name + ": " + o.m_type);
            }
            parent.loadNodeSettings(cont.getID(), settings);
        }
    }
}
Also used : DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) NodeSettings(org.knime.core.node.NodeSettings) LongCell(org.knime.core.data.def.LongCell) StringCell(org.knime.core.data.def.StringCell)

Example 13 with LongCell

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

the class SumOperator method getResultInternal.

/**
 * {@inheritDoc}
 */
@Override
protected DataCell getResultInternal() {
    if (!m_valid) {
        return DataType.getMissingCell();
    }
    if (IntCell.TYPE.equals(m_type)) {
        // check if the double value is to big for an integer
        if (m_sum > Integer.MAX_VALUE) {
            setSkipped(true);
            setSkipMessage("Sum > maximum int value. " + "Convert column to long.");
            return DataType.getMissingCell();
        }
        return new IntCell((int) m_sum);
    } else if (LongCell.TYPE.equals(m_type)) {
        // check if the double value is to big for a long
        if (m_sum > Long.MAX_VALUE) {
            setSkipped(true);
            setSkipMessage("Sum > maximum long value. " + "Convert column to double.");
            return DataType.getMissingCell();
        }
        return new LongCell((long) m_sum);
    }
    return new DoubleCell(m_sum);
}
Also used : LongCell(org.knime.core.data.def.LongCell) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell)

Example 14 with LongCell

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

the class TargetShufflingNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final int colIndex = inData[0].getDataTableSpec().findColumnIndex(m_settings.columnName());
    final String colName = inData[0].getDataTableSpec().getColumnSpec(colIndex).getName();
    // create a new column rearranger from the input table
    ColumnRearranger colRe = new ColumnRearranger(inData[0].getDataTableSpec());
    for (DataColumnSpec c : inData[0].getDataTableSpec()) {
        if (!c.getName().equals(colName)) {
            // remove all columns except the selected one
            colRe.remove(c.getName());
        }
    }
    // append a new column with a random number for each cell
    String uniqueColumnName = DataTableSpec.getUniqueColumnName(inData[0].getDataTableSpec(), "random_col");
    colRe.append(new SingleCellFactory(new DataColumnSpecCreator(uniqueColumnName, LongCell.TYPE).createSpec()) {

        @Override
        public DataCell getCell(final DataRow row) {
            return new LongCell(m_random.nextLong());
        }
    });
    BufferedDataTable toSort = exec.createColumnRearrangeTable(exec.createBufferedDataTable(inData[0], exec), colRe, exec.createSilentSubProgress(.2));
    // sort the random numbers ---> shuffles the sorted column
    List<String> include = new ArrayList<String>();
    include.add(toSort.getDataTableSpec().getColumnSpec(1).getName());
    SortedTable sort = new SortedTable(toSort, include, new boolean[] { true }, exec.createSubExecutionContext(.6));
    final BufferedDataTable sorted = sort.getBufferedDataTable();
    // replace the selected column with the shuffled one
    final DataColumnSpec colSpec = inData[0].getDataTableSpec().getColumnSpec(colIndex);
    ColumnRearranger crea = new ColumnRearranger(inData[0].getDataTableSpec());
    crea.replace(new SingleCellFactory(colSpec) {

        private final CloseableRowIterator m_iterator = sorted.iterator();

        @Override
        public DataCell getCell(final DataRow row) {
            return m_iterator.next().getCell(0);
        }
    }, colName);
    return new BufferedDataTable[] { exec.createColumnRearrangeTable(inData[0], crea, exec.createSubProgress(0.2)) };
}
Also used : DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) ArrayList(java.util.ArrayList) CloseableRowIterator(org.knime.core.data.container.CloseableRowIterator) DataRow(org.knime.core.data.DataRow) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) LongCell(org.knime.core.data.def.LongCell) SortedTable(org.knime.base.data.sort.SortedTable) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) SingleCellFactory(org.knime.core.data.container.SingleCellFactory)

Example 15 with LongCell

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

the class TimerinfoNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataContainer result = exec.createDataContainer(createSpec());
    WorkflowManager wfm = NodeContext.getContext().getWorkflowManager();
    for (NodeContainer nc : wfm.getNodeContainers()) {
        NodeTimer nt = nc.getNodeTimer();
        DataRow row = new DefaultRow(new RowKey("Node " + nc.getID().getIndex()), new StringCell(nc.getName()), nt.getLastExecutionDuration() >= 0 ? new LongCell(nt.getLastExecutionDuration()) : DataType.getMissingCell(), new LongCell(nt.getExecutionDurationSinceReset()), new LongCell(nt.getExecutionDurationSinceStart()), new IntCell(nt.getNrExecsSinceReset()), new IntCell(nt.getNrExecsSinceStart()), new StringCell(nc.getID().toString()), new StringCell(nc instanceof NativeNodeContainer ? ((NativeNodeContainer) nc).getNodeModel().getClass().getName() : "n/a"));
        result.addRowToTable(row);
    }
    result.close();
    return new PortObject[] { result.getTable() };
}
Also used : LongCell(org.knime.core.data.def.LongCell) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) StringCell(org.knime.core.data.def.StringCell) NodeTimer(org.knime.core.node.workflow.NodeTimer) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) NodeContainer(org.knime.core.node.workflow.NodeContainer) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow) FlowVariablePortObject(org.knime.core.node.port.flowvariable.FlowVariablePortObject) PortObject(org.knime.core.node.port.PortObject) NativeNodeContainer(org.knime.core.node.workflow.NativeNodeContainer) IntCell(org.knime.core.data.def.IntCell)

Aggregations

LongCell (org.knime.core.data.def.LongCell)18 IntCell (org.knime.core.data.def.IntCell)14 DataCell (org.knime.core.data.DataCell)10 DoubleCell (org.knime.core.data.def.DoubleCell)10 LongValue (org.knime.core.data.LongValue)8 StringCell (org.knime.core.data.def.StringCell)7 DoubleValue (org.knime.core.data.DoubleValue)6 IntValue (org.knime.core.data.IntValue)6 DateAndTimeCell (org.knime.core.data.date.DateAndTimeCell)6 DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)6 RowKey (org.knime.core.data.RowKey)4 DefaultRow (org.knime.core.data.def.DefaultRow)4 DataRow (org.knime.core.data.DataRow)3 Test (org.junit.Test)2 DataColumnSpec (org.knime.core.data.DataColumnSpec)2 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)2 DataType (org.knime.core.data.DataType)2 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)2 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 ArrayList (java.util.ArrayList)1