Search in sources :

Example 1 with DataTableRowInput

use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.

the class RuleEngine2PortsNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable data = (BufferedDataTable) inData[DATA_PORT];
    m_rowCount = data.size();
    try {
        Pair<ColumnRearranger, PortObject> rearrangerPair = createColumnRearranger((DataTableSpec) inData[DATA_PORT].getSpec(), new DataTableRowInput((DataTable) inData[RULE_PORT]));
        BufferedDataTable predictedTable = exec.createColumnRearrangeTable(data, rearrangerPair.getFirst(), exec);
        PortObject second = rearrangerPair.getSecond();
        if (m_settings.isPMMLRuleSet()) {
            if (m_settings.isProvideStatistics()) {
                PMMLPortObject po = (PMMLPortObject) rearrangerPair.getSecond();
                PMMLPortObject pmmlPortObject = new PMMLPortObject(m_copy.getSpec(), po);
                // Remove extra model.
                pmmlPortObject.addModelTranslater(new PMMLTranslator() {

                    @Override
                    public void initializeFrom(final PMMLDocument pmmlDoc) {
                    }

                    @Override
                    public SchemaType exportTo(final PMMLDocument pmmlDoc, final PMMLPortObjectSpec spec) {
                        return null;
                    }
                });
                second = pmmlPortObject;
            } else {
                second = m_copy;
            }
        }
        return new PortObject[] { predictedTable, second };
    } finally {
        m_rowCount = -1;
    }
}
Also used : BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTable(org.knime.core.data.DataTable) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) PMMLDocument(org.dmg.pmml.PMMLDocument) PMMLTranslator(org.knime.core.node.port.pmml.PMMLTranslator) PortObject(org.knime.core.node.port.PortObject) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InactiveBranchPortObject(org.knime.core.node.port.inactive.InactiveBranchPortObject) SchemaType(org.apache.xmlbeans.SchemaType)

Example 2 with DataTableRowInput

use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.

the class RuleEngineFilter2PortsNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    BufferedDataTable ruleTable = inData[RuleEngine2PortsNodeModel.RULE_PORT];
    BufferedDataTable dataTable = inData[RuleEngine2PortsNodeModel.DATA_PORT];
    // m_rulesList.clear();
    // m_rulesList.addAll(RuleEngineVariable2PortsNodeModel.rules(ruleTable, m_settings, RuleNodeSettings.RuleFilter));
    // final List<Rule> rules = parseRules(dataTable.getDataTableSpec(), RuleNodeSettings.RuleFilter);
    final BufferedDataContainer first = exec.createDataContainer(dataTable.getDataTableSpec(), true);
    final int nrOutPorts = getNrOutPorts();
    final RowAppender second = nrOutPorts > 1 ? exec.createDataContainer(dataTable.getDataTableSpec(), true) : new RowAppender() {

        @Override
        public void addRowToTable(final DataRow row) {
        // do nothing
        }
    };
    // final RowAppender[] containers = new RowAppender[]{first, second};
    // final int matchIndex = m_includeOnMatch ? 0 : 1;
    // final int otherIndex = 1 - matchIndex;
    // 
    final BufferedDataTable[] ret = new BufferedDataTable[nrOutPorts];
    // try {
    // final MutableLong rowIdx = new MutableLong();
    // final long rows = inData[DATA_PORT].size();
    // final VariableProvider provider = new VariableProvider() {
    // @Override
    // public Object readVariable(final String name, final Class<?> type) {
    // return RuleEngineFilter2PortsNodeModel.this.readVariable(name, type);
    // }
    // 
    // @Override
    // @Deprecated
    // public int getRowCount() {
    // throw new UnsupportedOperationException();
    // }
    // 
    // @Override
    // public long getRowCountLong() {
    // return rows;
    // }
    // 
    // @Override
    // @Deprecated
    // public int getRowIndex() {
    // throw new UnsupportedOperationException();
    // }
    // 
    // @Override
    // public long getRowIndexLong() {
    // return rowIdx.longValue();
    // }
    // };
    // for (DataRow row : inData[DATA_PORT]) {
    // rowIdx.increment();
    // exec.setProgress(rowIdx.longValue() / (double)rows, "Adding row " + rowIdx.longValue() + " of " + rows);
    // exec.checkCanceled();
    // boolean wasMatch = false;
    // for (final Rule r : rules) {
    // if (r.getCondition().matches(row, provider).getOutcome() == MatchState.matchedAndStop) {
    // //                        r.getSideEffect().perform(row, provider);
    // DataValue value = r.getOutcome().getComputedResult(row, provider);
    // if (value instanceof BooleanValue) {
    // final BooleanValue bv = (BooleanValue)value;
    // containers[bv.getBooleanValue() ? matchIndex : otherIndex].addRowToTable(row);
    // } else {
    // containers[matchIndex].addRowToTable(row);
    // }
    // wasMatch = true;
    // break;
    // }
    // }
    // if (!wasMatch) {
    // containers[otherIndex].addRowToTable(row);
    // }
    // }
    // } finally {
    // first.close();
    // ret[0] = first.getTable();
    // if (second instanceof BufferedDataContainer) {
    // BufferedDataContainer container = (BufferedDataContainer)second;
    // container.close();
    // ret[1] = container.getTable();
    // }
    // }
    final PortOutput[] outputs = new PortOutput[] { new BufferedDataTableRowOutput(first), new RowAppenderRowOutput(second) };
    final StreamableOperator streamableOperator = createStreamableOperator(new PartitionInfo(0, 1), new DataTableSpec[] { inData[0].getSpec(), inData[1].getSpec() });
    final PortInput[] inputs = new PortInput[] { new DataTableRowInput(dataTable), new DataTableRowInput(ruleTable) };
    final SimpleStreamableOperatorInternals internals = new SimpleStreamableOperatorInternals();
    internals.getConfig().addLong(CFG_ROW_COUNT, dataTable.size());
    streamableOperator.loadInternals(internals);
    streamableOperator.runFinal(inputs, outputs, exec);
    ret[0] = first.getTable();
    if (ret.length > 1) {
        ret[1] = ((BufferedDataContainer) second).getTable();
    }
    return ret;
}
Also used : SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) PortOutput(org.knime.core.node.streamable.PortOutput) DataRow(org.knime.core.data.DataRow) RowAppender(org.knime.core.data.container.RowAppender) BufferedDataTable(org.knime.core.node.BufferedDataTable) RowAppenderRowOutput(org.knime.base.node.rules.engine.RowAppenderRowOutput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) PartitionInfo(org.knime.core.node.streamable.PartitionInfo) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) PortInput(org.knime.core.node.streamable.PortInput)

Example 3 with DataTableRowInput

use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.

the class RuleEngineFilterNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    RowInput input = new DataTableRowInput(inData[0]);
    final BufferedDataContainer first = exec.createDataContainer(inData[0].getDataTableSpec(), true);
    final int nrOutPorts = getNrOutPorts();
    final BufferedDataContainer second = exec.createDataContainer(inData[0].getDataTableSpec(), true);
    BufferedDataTableRowOutput[] outputs = new BufferedDataTableRowOutput[] { new BufferedDataTableRowOutput(first), new BufferedDataTableRowOutput(second) };
    execute(input, outputs, inData[0].size(), exec);
    return nrOutPorts == 2 ? new BufferedDataTable[] { outputs[0].getDataTable(), outputs[1].getDataTable() } : new BufferedDataTable[] { outputs[0].getDataTable() };
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Example 4 with DataTableRowInput

use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.

the class StringToDurationPeriodNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
    final BufferedDataTable in = inData[0];
    if (m_type.getStringValue().equals(OutputType.Automatic.name())) {
        DataTableRowInput rowInput = new DataTableRowInput(in);
        try {
            detectTypes(rowInput);
        } finally {
            rowInput.close();
        }
        // no more rows to look at, guess that column is Period, if it was not detected
        for (int i = 0; i < m_detectedTypes.length; i++) {
            if (m_detectedTypes[i] == null) {
                m_detectedTypes[i] = PeriodCellFactory.TYPE;
            }
        }
    }
    final ColumnRearranger r = createColumnRearranger(in.getDataTableSpec());
    final BufferedDataTable out = exec.createColumnRearrangeTable(in, r, exec);
    if (m_failCounter > 0) {
        setWarningMessage(m_failCounter + " rows could not be converted. Check the message in the missing cells for details.");
    }
    return new BufferedDataTable[] { out };
}
Also used : ColumnRearranger(org.knime.core.data.container.ColumnRearranger) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput)

Example 5 with DataTableRowInput

use of org.knime.core.node.streamable.DataTableRowInput in project knime-core by knime.

the class UngroupOperation method compute.

/**
 * @param exec the execution context
 * @return the table with the ungrouped collections
 * @throws Exception the thrown exception
 */
public BufferedDataTable compute(final ExecutionContext exec) throws Exception {
    final BufferedDataContainer dc = exec.createDataContainer(m_newSpec);
    if (m_table.size() == 0) {
        dc.close();
        return dc.getTable();
    }
    DataTableRowInput in = new DataTableRowInput(m_table);
    BufferedDataTableRowOutput out = new BufferedDataTableRowOutput(dc);
    compute(in, out, exec, m_table.size());
    in.close();
    out.close();
    return out.getDataTable();
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput)

Aggregations

DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)24 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)16 BufferedDataTable (org.knime.core.node.BufferedDataTable)15 DataTableSpec (org.knime.core.data.DataTableSpec)9 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)9 RowInput (org.knime.core.node.streamable.RowInput)7 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)6 RowOutput (org.knime.core.node.streamable.RowOutput)6 StreamableOperator (org.knime.core.node.streamable.StreamableOperator)4 DataRow (org.knime.core.data.DataRow)3 ExecutionContext (org.knime.core.node.ExecutionContext)3 PortObject (org.knime.core.node.port.PortObject)3 PortInput (org.knime.core.node.streamable.PortInput)3 DataCell (org.knime.core.data.DataCell)2 PartitionInfo (org.knime.core.node.streamable.PartitionInfo)2 PortObjectInput (org.knime.core.node.streamable.PortObjectInput)2 PortOutput (org.knime.core.node.streamable.PortOutput)2 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)2 File (java.io.File)1 IOException (java.io.IOException)1