Search in sources :

Example 41 with StreamableOperator

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

the class DateTimeBasedRowFilterNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final RowInput in = (RowInput) inputs[0];
            final RowOutput out = (RowOutput) outputs[0];
            // read input
            final int colIdx = in.getDataTableSpec().findColumnIndex(m_colSelect.getStringValue());
            final ZonedDateTime executionStartTime = m_startAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
            final ZonedDateTime executionEndTime = m_endAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
            // filter rows
            final DataType colDataType = in.getDataTableSpec().getColumnSpec(colIdx).getType();
            DataRow row;
            while ((row = in.poll()) != null) {
                exec.checkCanceled();
                final DataCell cell = row.getCell(colIdx);
                if (!cell.isMissing()) {
                    if (cell instanceof LocalDateValue && filterRowLocalDate(((LocalDateValue) cell).getLocalDate(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    } else if (cell instanceof LocalTimeValue && filterRowLocalTime(((LocalTimeValue) cell).getLocalTime(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    } else if (cell instanceof LocalDateTimeValue && filterRowLocalDateTime(((LocalDateTimeValue) cell).getLocalDateTime(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    } else if (cell instanceof ZonedDateTimeValue && filterRowZonedDateTime(((ZonedDateTimeValue) cell).getZonedDateTime(), executionStartTime, executionEndTime)) {
                        out.push(row);
                    }
                }
            }
            in.close();
            out.close();
        }
    };
}
Also used : LocalTimeValue(org.knime.core.data.time.localtime.LocalTimeValue) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) LocalDateValue(org.knime.core.data.time.localdate.LocalDateValue) RowInput(org.knime.core.node.streamable.RowInput) DataRow(org.knime.core.data.DataRow) LocalDateTimeValue(org.knime.core.data.time.localdatetime.LocalDateTimeValue) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) ZonedDateTime(java.time.ZonedDateTime) DataType(org.knime.core.data.DataType) DataCell(org.knime.core.data.DataCell) ZonedDateTimeValue(org.knime.core.data.time.zoneddatetime.ZonedDateTimeValue)

Example 42 with StreamableOperator

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

the class RuleEngineFilterNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec spec = (DataTableSpec) inSpecs[0];
    try {
        parseRules(spec, RuleNodeSettings.RuleFilter);
    } catch (final ParseException e) {
        throw new InvalidSettingsException(e);
    }
    return new StreamableOperator() {

        private SimpleStreamableOperatorInternals m_internals;

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_internals = (SimpleStreamableOperatorInternals) internals;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            // count number of rows
            long count = 0;
            if (inputs[0] instanceof RowInput) {
                final RowInput rowInput = (RowInput) inputs[0];
                while (rowInput.poll() != null) {
                    count++;
                }
            } else if (inputs[0] instanceof PortObjectInput) {
                final PortObjectInput portObjectInput = (PortObjectInput) inputs[0];
                count += ((BufferedDataTable) portObjectInput.getPortObject()).size();
            }
            m_internals.getConfig().addLong(CFG_ROW_COUNT, count);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return m_internals;
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            long rowCount = -1L;
            if (m_internals.getConfig().containsKey(CFG_ROW_COUNT)) {
                rowCount = m_internals.getConfig().getLong(CFG_ROW_COUNT);
            }
            RowOutput[] rowOutputs = (outputs instanceof RowOutput[]) ? (RowOutput[]) outputs : outputs.length > 1 ? new RowOutput[] { (RowOutput) outputs[0], (RowOutput) outputs[1] } : new RowOutput[] { (RowOutput) outputs[0] };
            execute((RowInput) inputs[0], rowOutputs, rowCount, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) DataTableRowInput(org.knime.core.node.streamable.DataTableRowInput) RowInput(org.knime.core.node.streamable.RowInput) PortObjectInput(org.knime.core.node.streamable.PortObjectInput) BufferedDataTableRowOutput(org.knime.core.node.streamable.BufferedDataTableRowOutput) RowOutput(org.knime.core.node.streamable.RowOutput) ExecutionContext(org.knime.core.node.ExecutionContext) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) BufferedDataTable(org.knime.core.node.BufferedDataTable) ParseException(java.text.ParseException)

Example 43 with StreamableOperator

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

the class PMMLRuleSetPredictorNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec preSpec = (DataTableSpec) inSpecs[DATA_INDEX];
    return new StreamableOperator() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final PortObjectInput modelPort = (PortObjectInput) inputs[MODEL_INDEX];
            final ColumnRearranger rearranger = createRearranger((PMMLPortObject) modelPort.getPortObject(), preSpec, m_doReplaceColumn.getBooleanValue(), m_doReplaceColumn.getBooleanValue() ? m_replaceColumn.getStringValue() : DataTableSpec.getUniqueColumnName(preSpec, m_outputColumn.getStringValue()), m_addConfidence.getBooleanValue(), m_confidenceColumn.getStringValue(), /*no validation column*/
            -1, /* no statistics computed, so concurrent processing is allowed*/
            true);
            final DataTableSpec tableSpec = rearranger.createSpec();
            if (m_doReplaceColumn.getBooleanValue()) {
                DataColumnSpec[] columns = new DataColumnSpec[preSpec.getNumColumns()];
                for (int i = columns.length; i-- > 0; ) {
                    columns[i] = preSpec.getColumnSpec(i);
                }
                int columnIndex = preSpec.findColumnIndex(m_replaceColumn.getStringValue());
                if (m_addConfidence.getBooleanValue()) {
                    // Move confidence to the end
                    rearranger.move(columnIndex, tableSpec.getNumColumns());
                    // Move the result to its place
                    rearranger.move(tableSpec.getNumColumns() - 2, columnIndex);
                }
            }
            final StreamableFunction function = rearranger.createStreamableFunction(DATA_INDEX, 0);
            function.runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ExecutionContext(org.knime.core.node.ExecutionContext) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) DataColumnSpec(org.knime.core.data.DataColumnSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableFunction(org.knime.core.node.streamable.StreamableFunction) PortObjectInput(org.knime.core.node.streamable.PortObjectInput)

Example 44 with StreamableOperator

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

the class AbstractConditionalStreamingNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        private SimpleStreamableOperatorInternals m_internals;

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            m_internals = (SimpleStreamableOperatorInternals) internals;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
            // count number of rows
            long count = 0;
            RowInput rowInput = (RowInput) inputs[0];
            while (rowInput.poll() != null) {
                count++;
            }
            m_internals.getConfig().addLong(CFG_ROW_COUNT, count);
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            long rowCount = -1;
            if (m_internals.getConfig().containsKey(CFG_ROW_COUNT)) {
                rowCount = m_internals.getConfig().getLong(CFG_ROW_COUNT);
            }
            StreamableFunction func = createColumnRearranger((DataTableSpec) inSpecs[0], rowCount).createStreamableFunction();
            func.runFinal(inputs, outputs, exec);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return m_internals;
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) ExecutionContext(org.knime.core.node.ExecutionContext) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) RowInput(org.knime.core.node.streamable.RowInput) StreamableFunction(org.knime.core.node.streamable.StreamableFunction)

Example 45 with StreamableOperator

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

the class NumericOutliersApplyNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    return new StreamableOperator() {

        SummaryInternals m_summaryInternals;

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            final NumericOutlierPortObject outlierPort = (NumericOutlierPortObject) ((PortObjectInput) inputs[0]).getPortObject();
            NumericOutliersReviser outlierReviser = outlierPort.getOutRevBuilder().build();
            outlierReviser.treatOutliers(exec, (RowInput) inputs[1], (RowOutput) outputs[0], outlierPort.getOutlierModel(((RowInput) inputs[1]).getDataTableSpec()));
            m_summaryInternals = outlierReviser.getSummaryInternals();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return m_summaryInternals;
        }
    };
}
Also used : ExecutionContext(org.knime.core.node.ExecutionContext) NumericOutlierPortObject(org.knime.base.algorithms.outlier.NumericOutlierPortObject) SummaryInternals(org.knime.base.algorithms.outlier.NumericOutliersReviser.SummaryInternals) NumericOutliersReviser(org.knime.base.algorithms.outlier.NumericOutliersReviser) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) RowInput(org.knime.core.node.streamable.RowInput)

Aggregations

StreamableOperator (org.knime.core.node.streamable.StreamableOperator)57 ExecutionContext (org.knime.core.node.ExecutionContext)56 DataTableSpec (org.knime.core.data.DataTableSpec)32 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)32 RowInput (org.knime.core.node.streamable.RowInput)25 RowOutput (org.knime.core.node.streamable.RowOutput)23 StreamableFunction (org.knime.core.node.streamable.StreamableFunction)23 DataRow (org.knime.core.data.DataRow)13 BufferedDataTable (org.knime.core.node.BufferedDataTable)12 PMMLPortObject (org.knime.core.node.port.pmml.PMMLPortObject)11 DataTableRowInput (org.knime.core.node.streamable.DataTableRowInput)11 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)10 BufferedDataTableRowOutput (org.knime.core.node.streamable.BufferedDataTableRowOutput)10 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)10 PortObjectInput (org.knime.core.node.streamable.PortObjectInput)8 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)8 PortInput (org.knime.core.node.streamable.PortInput)7 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)6 IOException (java.io.IOException)5 DataCell (org.knime.core.data.DataCell)5