Search in sources :

Example 1 with MergeOperator

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);
        }
    };
}
Also used : MergeOperator(org.knime.core.node.streamable.MergeOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals)

Example 2 with MergeOperator

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;
        }
    };
}
Also used : MergeOperator(org.knime.core.node.streamable.MergeOperator) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)

Example 3 with MergeOperator

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;
        }
    };
}
Also used : SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) MergeOperator(org.knime.core.node.streamable.MergeOperator)

Example 4 with MergeOperator

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;
        }
    };
}
Also used : SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) Config(org.knime.core.node.config.Config) MergeOperator(org.knime.core.node.streamable.MergeOperator) StreamableOperatorInternals(org.knime.core.node.streamable.StreamableOperatorInternals) SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)

Example 5 with MergeOperator

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;
        }
    };
}
Also used : SimpleStreamableOperatorInternals(org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals) InvalidSettingsException(org.knime.core.node.InvalidSettingsException) MergeOperator(org.knime.core.node.streamable.MergeOperator)

Aggregations

MergeOperator (org.knime.core.node.streamable.MergeOperator)5 SimpleStreamableOperatorInternals (org.knime.core.node.streamable.simple.SimpleStreamableOperatorInternals)4 StreamableOperatorInternals (org.knime.core.node.streamable.StreamableOperatorInternals)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)2 Config (org.knime.core.node.config.Config)1 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)1