Search in sources :

Example 11 with DataTableSpec

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 };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) RowKey(org.knime.core.data.RowKey) BufferedDataTable(org.knime.core.node.BufferedDataTable) TSMissVHandler(org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler) DataRow(org.knime.core.data.DataRow)

Example 12 with DataTableSpec

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() };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) TSMissVHandler(org.knime.timeseries.node.timemissvaluehandler.tshandler.TSMissVHandler)

Example 13 with DataTableSpec

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);
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer)

Example 14 with DataTableSpec

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);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) JavaScriptingSettings(org.knime.ext.sun.nodes.script.settings.JavaScriptingSettings) UniqueNameGenerator(org.knime.core.util.UniqueNameGenerator) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ColumnCalculator(org.knime.ext.sun.nodes.script.calculator.ColumnCalculator) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow) NoSuchElementException(java.util.NoSuchElementException) FlowVariable(org.knime.core.node.workflow.FlowVariable)

Example 15 with DataTableSpec

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);
    }
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) ParseException(java.text.ParseException)

Aggregations

DataTableSpec (org.knime.core.data.DataTableSpec)938 DataColumnSpec (org.knime.core.data.DataColumnSpec)340 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)306 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)228 BufferedDataTable (org.knime.core.node.BufferedDataTable)226 DataCell (org.knime.core.data.DataCell)186 DataRow (org.knime.core.data.DataRow)170 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)136 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)129 DataType (org.knime.core.data.DataType)109 ArrayList (java.util.ArrayList)106 PortObjectSpec (org.knime.core.node.port.PortObjectSpec)98 DoubleValue (org.knime.core.data.DoubleValue)94 DefaultRow (org.knime.core.data.def.DefaultRow)92 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)90 ExecutionContext (org.knime.core.node.ExecutionContext)68 PortObject (org.knime.core.node.port.PortObject)66 PMMLPortObjectSpec (org.knime.core.node.port.pmml.PMMLPortObjectSpec)62 CanceledExecutionException (org.knime.core.node.CanceledExecutionException)61 RowKey (org.knime.core.data.RowKey)59