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;
}
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);
}
}
}
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);
}
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)) };
}
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() };
}
Aggregations