use of org.knime.core.node.streamable.MergeOperator in project knime-core by knime.
the class SimpleStreamableFunctionWithInternalsNodeModel method createMergeOperator.
/**
* {@inheritDoc}
*/
@Override
public MergeOperator createMergeOperator() {
return new MergeOperator() {
@Override
public StreamableOperatorInternals mergeFinal(final StreamableOperatorInternals[] internals) {
@SuppressWarnings("unchecked") T[] castedInternals = (T[]) Array.newInstance(m_class, internals.length);
for (int i = 0; i < internals.length; i++) {
StreamableOperatorInternals o = internals[i];
if (o == null) {
throw new NullPointerException("internals at position " + i + " is null");
} else if (!m_class.isInstance(o)) {
throw new IllegalStateException(String.format("Internals at position %d is not of expected " + "class \"%s\", it's a \"%s\"", i, m_class.getSimpleName(), o.getClass().getSimpleName()));
}
castedInternals[i] = m_class.cast(o);
}
return mergeStreamingOperatorInternals(castedInternals);
}
};
}
use of org.knime.core.node.streamable.MergeOperator in project knime-core by knime.
the class ReferenceColumnResorterNodeModel method createMergeOperator.
/**
* {@inheritDoc}
*/
@Override
public MergeOperator createMergeOperator() {
return new MergeOperator() {
/**
* {@inheritDoc}
*/
@Override
public StreamableOperatorInternals mergeIntermediate(final StreamableOperatorInternals[] operators) {
return mergeFinal(operators);
}
@Override
public StreamableOperatorInternals mergeFinal(final StreamableOperatorInternals[] operators) {
StreamableOperatorInternals result = operators[0];
String[] refOrder = readOrderFromStreamableOperatorInternals(result);
for (int i = 1; i < operators.length; i++) {
final String[] curOrder = readOrderFromStreamableOperatorInternals(operators[i]);
if (!Arrays.equals(refOrder, curOrder)) {
StringBuilder b = new StringBuilder();
b.append("Inconsistent internals -- all workers should see same dictionary table; ");
b.append("index ").append(i).append("is different to position 0: ");
b.append(refOrder).append(" vs. ").append(curOrder);
}
}
return result;
}
};
}
use of org.knime.core.node.streamable.MergeOperator in project knime-core by knime.
the class AbstractConditionalStreamingNodeModel method createMergeOperator.
/**
* {@inheritDoc}
*/
@Override
public MergeOperator createMergeOperator() {
return new MergeOperator() {
/**
* {@inheritDoc}
*/
@Override
public StreamableOperatorInternals mergeIntermediate(final StreamableOperatorInternals[] operators) {
// sum up the row counts if necessary
long count = 0;
for (int i = 0; i < operators.length; i++) {
SimpleStreamableOperatorInternals simpleInternals = (SimpleStreamableOperatorInternals) operators[i];
CheckUtils.checkState(simpleInternals.getConfig().containsKey(CFG_ROW_COUNT), "Config for key " + CFG_ROW_COUNT + " isn't set.");
try {
count += simpleInternals.getConfig().getLong(CFG_ROW_COUNT);
} catch (InvalidSettingsException e) {
// should not happen since we checked already
throw new RuntimeException(e);
}
}
SimpleStreamableOperatorInternals res = new SimpleStreamableOperatorInternals();
if (count > 0) {
res.getConfig().addLong(CFG_ROW_COUNT, count);
}
return res;
}
@Override
public StreamableOperatorInternals mergeFinal(final StreamableOperatorInternals[] operators) {
// nothing to do here
return null;
}
};
}
use of org.knime.core.node.streamable.MergeOperator in project knime-core by knime.
the class StringToDurationPeriodNodeModel method createMergeOperator.
@Override
public MergeOperator createMergeOperator() {
return new MergeOperator() {
@Override
public StreamableOperatorInternals mergeIntermediate(final StreamableOperatorInternals[] operators) {
final SimpleStreamableOperatorInternals internals = new SimpleStreamableOperatorInternals();
final Config config = internals.getConfig();
for (StreamableOperatorInternals operator : operators) {
final Config configToMerge = ((SimpleStreamableOperatorInternals) operator).getConfig();
final int sizeRow = configToMerge.getInt("sizeRow", -1);
config.addInt("sizeRow", sizeRow);
for (int i = 0; i < sizeRow; i++) {
if (!config.containsKey("type" + i) && configToMerge.getDataType("type" + i, null) != null) {
config.addDataType("type" + i, configToMerge.getDataType("type" + i, null));
config.addString("colname" + i, configToMerge.getString("colname" + i, null));
}
if (!config.containsKey("detected_type" + i) && configToMerge.getDataType("detected_type" + i, null) != null) {
config.addDataType("detected_type" + i, configToMerge.getDataType("detected_type" + i, null));
}
}
}
// if a column's type could not be detected, guess it to be a PeriodCell
final Config configToMerge = ((SimpleStreamableOperatorInternals) operators[0]).getConfig();
for (int i = 0; i < configToMerge.getInt("sizeRow", -1); i++) {
if (!config.containsKey("type" + i)) {
config.addDataType("type" + i, PeriodCellFactory.TYPE);
config.addString("colname" + i, configToMerge.getString("colname" + i, null));
}
if (!config.containsKey("detected_type" + i)) {
config.addDataType("detected_type" + i, PeriodCellFactory.TYPE);
}
}
return internals;
}
@Override
public StreamableOperatorInternals mergeFinal(final StreamableOperatorInternals[] operators) {
return null;
}
};
}
use of org.knime.core.node.streamable.MergeOperator in project knime-core by knime.
the class RuleEngineNodeModel method createMergeOperator.
/**
* {@inheritDoc}
*/
@Override
public MergeOperator createMergeOperator() {
return new MergeOperator() {
/**
* {@inheritDoc}
*/
@Override
public StreamableOperatorInternals mergeIntermediate(final StreamableOperatorInternals[] operators) {
// sum up the row counts if necessary
long count = 0;
for (int i = 0; i < operators.length; i++) {
SimpleStreamableOperatorInternals simpleInternals = (SimpleStreamableOperatorInternals) operators[i];
CheckUtils.checkState(simpleInternals.getConfig().containsKey(CFG_ROW_COUNT), "Config for key " + CFG_ROW_COUNT + " isn't set.");
try {
count += simpleInternals.getConfig().getLong(CFG_ROW_COUNT);
} catch (InvalidSettingsException e) {
// should not happen since we checked already
throw new RuntimeException(e);
}
}
SimpleStreamableOperatorInternals res = new SimpleStreamableOperatorInternals();
if (count > 0) {
res.getConfig().addLong(CFG_ROW_COUNT, count);
}
return res;
}
@Override
public StreamableOperatorInternals mergeFinal(final StreamableOperatorInternals[] operators) {
// nothing to do here
return null;
}
};
}
Aggregations