use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class TimeMissValueNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
ExecutionContext createExec = exec.createSubExecutionContext(0.4);
DataTableSpec spec = inData[0].getDataTableSpec();
double maxRow = inData[0].getRowCount();
double currRow = 0;
Map<String, TSMissVHandler> nameToMVHandler = checkInputAndCreateHandlerMap(spec);
Map<String, Integer> nameToInt = findColumns(spec, nameToMVHandler);
if (nameToMVHandler.isEmpty()) {
return inData;
}
for (DataRow row : inData[0]) {
RowKey key = row.getKey();
for (String s : nameToInt.keySet()) {
nameToMVHandler.get(s).incomingValue(key, row.getCell(nameToInt.get(s)));
}
createExec.checkCanceled();
createExec.setProgress(++currRow / maxRow, "Preprocessing... Row " + row.getKey().getString());
}
for (String s : nameToMVHandler.keySet()) {
nameToMVHandler.get(s).close();
}
ExecutionContext builtExec = exec.createSubExecutionContext(0.6);
ColumnRearranger colR = createColumnRearranger(nameToMVHandler, nameToInt, inData[0].getDataTableSpec());
BufferedDataTable outTable = exec.createColumnRearrangeTable(inData[0], colR, builtExec);
return new BufferedDataTable[] { outTable };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class TimeMissValueNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec spec = inSpecs[0];
Map<String, TSMissVHandler> nameToMVHandler = checkInputAndCreateHandlerMap(spec);
Map<String, Integer> nameToInt = findColumns(spec, nameToMVHandler);
ColumnRearranger c = createColumnRearranger(nameToMVHandler, nameToInt, spec);
return new DataTableSpec[] { c.createSpec() };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class MovingAggregationTableFactory method createTable.
/**
* @param exec {@link ExecutionContext} to provide progress
* @param table the {@link BufferedDataTable} to process
* @return the result table
* @throws CanceledExecutionException if the user has canceled the operation
*/
public BufferedDataTable createTable(final ExecutionContext exec, final BufferedDataTable table) throws CanceledExecutionException {
final DataTableSpec resultSpec = createResultSpec();
final BufferedDataContainer dc = exec.createDataContainer(resultSpec);
final int rowCount = table.getRowCount();
if (rowCount == 0) {
dc.close();
return dc.getTable();
}
if (m_cumulativeComp) {
return getCumulativeTable(exec, table, dc);
}
switch(m_type) {
case BACKWARD:
return getBackwardTable(exec, table, dc);
case CENTER:
return getCenterTable(exec, table, dc);
case FORWARD:
return getForwardTable(exec, table, dc);
}
throw new RuntimeException("Unknown window type " + m_type);
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class StringManipulationVariableNodeModel method calculate.
/**
* @throws CompilationFailedException
* @throws InstantiationException
* @throws Exception
*/
private void calculate() throws InvalidSettingsException, CompilationFailedException, InstantiationException {
if (m_settings == null || m_settings.getExpression() == null) {
throw new InvalidSettingsException("No expression has been set.");
}
JavaScriptingSettings settings = m_settings.createJavaScriptingSettings();
settings.setInputAndCompile(new DataTableSpec());
// calculate the result
ColumnCalculator cc = new ColumnCalculator(settings, this);
DataCell calculate = null;
try {
calculate = cc.calculate(new DefaultRow(new RowKey(""), new DataCell[] {}));
} catch (NoSuchElementException e) {
throw new InvalidSettingsException(e.getMessage());
}
String newVariableName;
Map<String, FlowVariable> inputFlowVariables = getAvailableInputFlowVariables();
if (m_settings.isReplace()) {
newVariableName = m_settings.getColName();
CheckUtils.checkSettingNotNull(inputFlowVariables.get(newVariableName), "Can't replace input variable '%s' -- it does not exist in the input", newVariableName);
} else {
newVariableName = new UniqueNameGenerator(inputFlowVariables.keySet()).newName(m_settings.getColName());
}
// convert and push result as flow variable
CheckUtils.checkSetting(!calculate.isMissing(), "Calculation returned missing value");
Class<? extends DataCell> cellType = calculate.getClass();
if (cellType.equals(IntCell.class)) {
pushFlowVariableInt(newVariableName, ((IntCell) calculate).getIntValue());
} else if (cellType.equals(DoubleCell.class)) {
pushFlowVariableDouble(newVariableName, ((DoubleCell) calculate).getDoubleValue());
} else if (cellType.equals(StringCell.class)) {
pushFlowVariableString(newVariableName, ((StringCell) calculate).getStringValue());
} else {
throw new RuntimeException("Invalid variable class: " + cellType);
}
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class RuleEngineNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
try {
m_rowCount = -1;
final List<Rule> rules = parseRules(inSpecs[0], RuleNodeSettings.RuleEngine);
ColumnRearranger crea = createRearranger(inSpecs[0], rules, -1, true);
return new DataTableSpec[] { crea.createSpec() };
} catch (ParseException ex) {
throw new InvalidSettingsException(ex.getMessage(), ex);
}
}
Aggregations