Search in sources :

Example 16 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class RuleEngineNodeModel method createStreamableOperator.

/**
 * {@inheritDoc}
 */
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final DataTableSpec spec = (DataTableSpec) inSpecs[0];
    final List<Rule> parsedRules;
    try {
        parsedRules = parseRules(spec, RuleNodeSettings.RuleEngine);
    } 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;
            RowInput rowInput = (RowInput) inputs[0];
            while (rowInput.poll() != null) {
                count++;
            }
            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);
            }
            createRearranger(((RowInput) inputs[0]).getDataTableSpec(), parsedRules, rowCount, false).createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
        }
    };
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) ExecutionContext(org.knime.core.node.ExecutionContext) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) ParseException(java.text.ParseException) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) RowInput(org.knime.core.node.streamable.RowInput)

Example 17 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class StreamingUtil method checkRules.

private static boolean checkRules(final RuleFactory ruleFactory, final Iterable<String> rules, final Predicate<Rule> ruleIsGood) {
    final RuleFactory proper = ruleFactory.cloned();
    proper.disableColumnChecks();
    proper.disableFlowVariableChecks();
    final DataTableSpec empty = new DataTableSpec();
    return StreamSupport.stream(rules.spliterator(), true).anyMatch(ruleAsString -> {
        try {
            return !ruleIsGood.test(proper.parse(ruleAsString, empty, Collections.emptyMap()));
        } catch (ParseException e) {
            return true;
        }
    });
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) ParseException(java.text.ParseException)

Example 18 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class PMMLRuleEditorNodeModel method computeFinalOutputSpecs.

/**
 * {@inheritDoc}
 */
@Override
public PortObjectSpec[] computeFinalOutputSpecs(final StreamableOperatorInternals internals, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
    final PortObjectSpec[] computeFinalOutputSpecs = super.computeFinalOutputSpecs(internals, inSpecs);
    // TODO should this be done some place else (finish)?
    StreamInternalForPMMLPortObject poInternals = (StreamInternalForPMMLPortObject) internals;
    try {
        DataTableSpec tableSpec = (DataTableSpec) inSpecs[0];
        RearrangerAndPMMLModel m = createRearrangerAndPMMLModel(tableSpec);
        poInternals.setObject(m.getPMMLPortObject());
    } catch (ParseException e) {
        throw new InvalidSettingsException(e);
    }
    return computeFinalOutputSpecs;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) PortObjectSpec(org.knime.core.node.port.PortObjectSpec) ParseException(java.text.ParseException)

Example 19 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class PMMLRuleEditorNodeModel method computeSpecs.

/**
 * Computes the specs after applying the derived fields.
 *
 * @param specs The input table and the possible preprocessing port.
 * @return The computed (original+preproc) input table's specification.
 */
@Deprecated
static DataTableSpec computeSpecs(final PortObjectSpec[] specs) {
    final DataTableSpec tableSpec = (DataTableSpec) specs[0];
    if (specs[1] == null) {
        return tableSpec;
    }
    PMMLPortObjectSpec portObjectSpec = (PMMLPortObjectSpec) specs[1];
    List<DataColumnSpec> preprocessingCols = portObjectSpec.getPreprocessingCols();
    DataTableSpecCreator creator = new DataTableSpecCreator(tableSpec);
    for (DataColumnSpec spec : preprocessingCols) {
        creator.addColumns(spec);
    }
    return creator.createSpec();
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) PMMLPortObjectSpec(org.knime.core.node.port.pmml.PMMLPortObjectSpec) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataTableSpecCreator(org.knime.core.data.DataTableSpecCreator)

Example 20 with DataTableSpec

use of org.knime.core.data.DataTableSpec in project knime-core by knime.

the class PMMLRuleEditorNodeModel method createStreamableOperator.

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

        private ColumnRearranger m_rearrangerx;

        private PMMLPortObject m_portObject;

        {
            try {
                final PMMLDocument doc = PMMLDocument.Factory.newInstance();
                final PMML pmml = doc.addNewPMML();
                RuleSetModel ruleSetModel = pmml.addNewRuleSetModel();
                RuleSet ruleSet = ruleSetModel.addNewRuleSet();
                PMMLRuleParser parser = new PMMLRuleParser(tableSpec, getAvailableInputFlowVariables());
                m_rearrangerx = createRearranger(tableSpec, ruleSet, parser);
            } catch (ParseException e) {
                throw new InvalidSettingsException(e);
            }
        }

        @Override
        public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
            m_rearrangerx.createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void loadInternals(final StreamableOperatorInternals internals) {
            super.loadInternals(internals);
            m_portObject = ((StreamInternalForPMMLPortObject) internals).getObject();
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public StreamableOperatorInternals saveInternals() {
            return createInitialStreamableOperatorInternals().setObject(m_portObject);
        }
    };
}
Also used : RuleSetModel(org.dmg.pmml.RuleSetModelDocument.RuleSetModel) RuleSet(org.dmg.pmml.RuleSetDocument.RuleSet) DataTableSpec(org.knime.core.data.DataTableSpec) StreamableOperator(org.knime.core.node.streamable.StreamableOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) ColumnRearranger(org.knime.core.data.container.ColumnRearranger) ExecutionContext(org.knime.core.node.ExecutionContext) PMMLPortObject(org.knime.core.node.port.pmml.PMMLPortObject) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) PMML(org.dmg.pmml.PMMLDocument.PMML) PMMLDocument(org.dmg.pmml.PMMLDocument) 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