use of org.knime.core.node.streamable.PortObjectOutput in project knime-core by knime.
the class RuleEngine2PortsNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
private StreamInternalWithPortObject m_internals;
/**
* {@inheritDoc}
*/
@Override
public void loadInternals(final StreamableOperatorInternals internals) {
m_internals = (StreamInternalWithPortObject) internals;
}
/**
* {@inheritDoc}
*/
@Override
public void runIntermediate(final PortInput[] inputs, final ExecutionContext exec) throws Exception {
// count number of rows
long count = 0;
final RowInput rowInput = (RowInput) inputs[DATA_PORT];
while (rowInput.poll() != null) {
count++;
}
if (inputs[RULE_PORT] instanceof RowInput) {
final RowInput ruleInput = (RowInput) inputs[RULE_PORT];
final Pair<ColumnRearranger, PortObject> pair = createColumnRearranger(rowInput.getDataTableSpec(), ruleInput);
final ColumnRearranger rearranger = pair.getFirst();
final DataTableSpec spec = rearranger.createSpec();
m_internals.setTableSpec(spec);
if (pair.getSecond() instanceof PMMLPortObject) {
PMMLPortObject po = (PMMLPortObject) pair.getSecond();
m_internals.setObject(po);
} else {
m_internals.setObject(null);
}
}
m_internals.setRowCount(count);
}
/**
* {@inheritDoc}
*/
@Override
public StreamableOperatorInternals saveInternals() {
return m_internals;
}
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
if (m_internals.getTableSpec() != null) {
m_rowCount = m_internals.getRowCount();
}
final Pair<ColumnRearranger, PortObject> pair = createColumnRearranger((DataTableSpec) inSpecs[DATA_PORT], (RowInput) inputs[RULE_PORT]);
pair.getFirst().createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
if (pair.getSecond() != null) {
((PortObjectOutput) outputs[1]).setPortObject(pair.getSecond());
}
}
};
}
use of org.knime.core.node.streamable.PortObjectOutput in project knime-core by knime.
the class PMMLRuleEditorNodeModel method finishStreamableExecution.
/**
* {@inheritDoc}
*/
@Override
public void finishStreamableExecution(final StreamableOperatorInternals internals, final ExecutionContext exec, final PortOutput[] output) throws Exception {
final StreamInternalForPMMLPortObject poInternals = (StreamInternalForPMMLPortObject) internals;
PMMLPortObject ret = poInternals.getObject();
ret.validate();
((PortObjectOutput) output[1]).setPortObject(ret);
}
use of org.knime.core.node.streamable.PortObjectOutput in project knime-core by knime.
the class CategoryToNumberNodeModel 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 {
ColumnRearranger cr = createRearranger((DataTableSpec) inSpecs[0]);
cr.createStreamableFunction(0, 0).runFinal(inputs, outputs, exec);
// the optional PMML in port (can be null)
PMMLPortObject inPMMLPort = null;
if (m_pmmlInEnabled && inputs[1] != null) {
inPMMLPort = (PMMLPortObject) ((PortObjectInput) inputs[1]).getPortObject();
}
PMMLPortObjectSpecCreator creator = new PMMLPortObjectSpecCreator(inPMMLPort, cr.createSpec());
PMMLPortObject outPMMLPort = new PMMLPortObject(creator.createSpec(), inPMMLPort);
for (CategoryToNumberCellFactory factory : m_factories) {
PMMLMapValuesTranslator trans = new PMMLMapValuesTranslator(factory.getConfig(), new DerivedFieldMapper(inPMMLPort));
outPMMLPort.addGlobalTransformations(trans.exportToTransDict());
}
PortObjectOutput portObjectOutput = (PortObjectOutput) outputs[1];
portObjectOutput.setPortObject(outPMMLPort);
}
};
}
use of org.knime.core.node.streamable.PortObjectOutput in project knime-core by knime.
the class DataColumnSpecFilterPMMLNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
final ColumnRearranger corea = createColumnRearranger((DataTableSpec) inSpecs[0]);
final StreamableFunction fct = corea.createStreamableFunction();
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
// execute streamable in- and outport (0)
fct.init(exec);
fct.runFinal(inputs, outputs, exec);
fct.finish();
DataTableSpec outSpec = corea.createSpec();
// pmml ports
PMMLPortObject pmmlIn = (PMMLPortObject) ((PortObjectInput) inputs[1]).getPortObject();
final PMMLPortObject pmmlOut = createPMMLOut(pmmlIn, outSpec, getFilterResult((DataTableSpec) inSpecs[0]));
((PortObjectOutput) outputs[1]).setPortObject(pmmlOut);
}
};
}
use of org.knime.core.node.streamable.PortObjectOutput in project knime-core by knime.
the class VirtualSubNodeInputNodeModel method createStreamableOperator.
@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 {
assert inputs.length == 0;
PortObject[] dataFromParent = ArrayUtils.remove(m_subNodeContainer.fetchInputDataFromParent(), 0);
for (int i = 0; i < outputs.length; i++) {
if (BufferedDataTable.TYPE.equals(getOutPortType(i))) {
// stream port content if it's data
BufferedDataTable bdt = (BufferedDataTable) (dataFromParent[i]);
RowOutput rowOutput = (RowOutput) outputs[i];
for (DataRow dr : bdt) {
rowOutput.push(dr);
}
rowOutput.close();
} else {
((PortObjectOutput) outputs[i]).setPortObject(dataFromParent[i]);
}
}
}
};
}
Aggregations