Search in sources :

Example 96 with Fields

use of org.apache.storm.tuple.Fields in project flink by apache.

the class WordCountTopology method buildTopology.

public static TopologyBuilder buildTopology(boolean indexOrName) {
    final TopologyBuilder builder = new TopologyBuilder();
    // get input data
    if (fileInputOutput) {
        // read the text file from given input path
        final String[] tokens = textPath.split(":");
        final String inputFile = tokens[tokens.length - 1];
        // inserting NullTerminatingSpout only required to stabilize integration test
        builder.setSpout(spoutId, new NullTerminatingSpout(new WordCountFileSpout(inputFile)));
    } else {
        builder.setSpout(spoutId, new WordCountInMemorySpout());
    }
    if (indexOrName) {
        // split up the lines in pairs (2-tuples) containing: (word,1)
        builder.setBolt(tokenierzerId, new BoltTokenizer(), 4).shuffleGrouping(spoutId);
        // group by the tuple field "0" and sum up tuple field "1"
        builder.setBolt(counterId, new BoltCounter(), 4).fieldsGrouping(tokenierzerId, new Fields(BoltTokenizer.ATTRIBUTE_WORD));
    } else {
        // split up the lines in pairs (2-tuples) containing: (word,1)
        builder.setBolt(tokenierzerId, new BoltTokenizerByName(), 4).shuffleGrouping(spoutId);
        // group by the tuple field "0" and sum up tuple field "1"
        builder.setBolt(counterId, new BoltCounterByName(), 4).fieldsGrouping(tokenierzerId, new Fields(BoltTokenizerByName.ATTRIBUTE_WORD));
    }
    // emit result
    if (fileInputOutput) {
        // read the text file from given input path
        final String[] tokens = outputPath.split(":");
        final String outputFile = tokens[tokens.length - 1];
        builder.setBolt(sinkId, new BoltFileSink(outputFile, formatter)).shuffleGrouping(counterId);
    } else {
        builder.setBolt(sinkId, new BoltPrintSink(formatter), 4).shuffleGrouping(counterId);
    }
    return builder;
}
Also used : WordCountFileSpout(org.apache.flink.storm.wordcount.operators.WordCountFileSpout) BoltCounter(org.apache.flink.storm.wordcount.operators.BoltCounter) BoltCounterByName(org.apache.flink.storm.wordcount.operators.BoltCounterByName) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) WordCountInMemorySpout(org.apache.flink.storm.wordcount.operators.WordCountInMemorySpout) BoltPrintSink(org.apache.flink.storm.util.BoltPrintSink) NullTerminatingSpout(org.apache.flink.storm.util.NullTerminatingSpout) BoltFileSink(org.apache.flink.storm.util.BoltFileSink) Fields(org.apache.storm.tuple.Fields) BoltTokenizer(org.apache.flink.storm.wordcount.operators.BoltTokenizer) BoltTokenizerByName(org.apache.flink.storm.wordcount.operators.BoltTokenizerByName)

Example 97 with Fields

use of org.apache.storm.tuple.Fields in project flink by apache.

the class WrapperSetupHelper method processSingleOperator.

/**
	 * Sets up {@code taskToComponents}, {@code componentToSortedTasks}, and {@code componentToStreamToFields} for a
	 * single instance of a Spout or Bolt (ie, task or executor). Furthermore, is computes the unique task-id.
	 * 
	 * @param componentId
	 *            The ID of the Spout/Bolt in the topology.
	 * @param common
	 *            The common operator object (that is all Spouts and Bolts have).
	 * @param operatorName
	 *            The Flink operator name.
	 * @param index
	 *            The index of the currently processed tasks with its operator.
	 * @param dop
	 *            The parallelism of the operator.
	 * @param taskToComponents
	 *            OUTPUT: A map from all task IDs of the topology to their component IDs.
	 * @param componentToSortedTasks
	 *            OUTPUT: A map from all component IDs to their sorted list of corresponding task IDs.
	 * @param componentToStreamToFields
	 *            OUTPUT: A map from all component IDs to there output streams and output fields.
	 * 
	 * @return A unique task ID if the currently processed Spout or Bolt ({@code componentId}) is equal to the current
	 *         Flink operator {@code operatorName} -- {@code null} otherwise.
	 */
private static Integer processSingleOperator(final String componentId, final ComponentCommon common, final String operatorName, final int index, final int dop, final Map<Integer, String> taskToComponents, final Map<String, List<Integer>> componentToSortedTasks, final Map<String, Map<String, Fields>> componentToStreamToFields) {
    final int parallelism_hint = common.get_parallelism_hint();
    Integer taskId = null;
    if (componentId.equals(operatorName)) {
        taskId = tid + index;
    }
    List<Integer> sortedTasks = new ArrayList<Integer>(dop);
    for (int i = 0; i < parallelism_hint; ++i) {
        taskToComponents.put(tid, componentId);
        sortedTasks.add(tid);
        ++tid;
    }
    componentToSortedTasks.put(componentId, sortedTasks);
    Map<String, Fields> outputStreams = new HashMap<String, Fields>();
    for (Entry<String, StreamInfo> outStream : common.get_streams().entrySet()) {
        outputStreams.put(outStream.getKey(), new Fields(outStream.getValue().get_output_fields()));
    }
    componentToStreamToFields.put(componentId, outputStreams);
    return taskId;
}
Also used : Fields(org.apache.storm.tuple.Fields) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StreamInfo(org.apache.storm.generated.StreamInfo)

Example 98 with Fields

use of org.apache.storm.tuple.Fields in project flink by apache.

the class SplitBolt method declareOutputFields.

@Override
public void declareOutputFields(OutputFieldsDeclarer declarer) {
    Fields schema = new Fields("number");
    declarer.declareStream(EVEN_STREAM, schema);
    declarer.declareStream(ODD_STREAM, schema);
}
Also used : Fields(org.apache.storm.tuple.Fields)

Example 99 with Fields

use of org.apache.storm.tuple.Fields in project flink by apache.

the class WrapperSetupHelperTest method testTupleTypes.

private void testTupleTypes(final int numberOfAttributes) throws Exception {
    String[] schema;
    if (numberOfAttributes == -1) {
        schema = new String[1];
    } else {
        schema = new String[numberOfAttributes];
    }
    for (int i = 0; i < schema.length; ++i) {
        schema[i] = "a" + i;
    }
    IComponent boltOrSpout;
    if (this.r.nextBoolean()) {
        boltOrSpout = mock(IRichSpout.class);
    } else {
        boltOrSpout = mock(IRichBolt.class);
    }
    final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
    declarer.declare(new Fields(schema));
    PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
    HashMap<String, Integer> attributes = new HashMap<String, Integer>();
    attributes.put(Utils.DEFAULT_STREAM_ID, numberOfAttributes);
    Assert.assertEquals(attributes, WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, numberOfAttributes == -1 ? new HashSet<String>(singleton(Utils.DEFAULT_STREAM_ID)) : null));
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) IRichSpout(org.apache.storm.topology.IRichSpout) Fields(org.apache.storm.tuple.Fields) HashMap(java.util.HashMap) IComponent(org.apache.storm.topology.IComponent)

Example 100 with Fields

use of org.apache.storm.tuple.Fields in project flink by apache.

the class WrapperSetupHelperTest method testToManyAttributes.

@Test(expected = IllegalArgumentException.class)
public void testToManyAttributes() throws Exception {
    IComponent boltOrSpout;
    if (this.r.nextBoolean()) {
        boltOrSpout = mock(IRichSpout.class);
    } else {
        boltOrSpout = mock(IRichBolt.class);
    }
    final SetupOutputFieldsDeclarer declarer = new SetupOutputFieldsDeclarer();
    final String[] schema = new String[26];
    for (int i = 0; i < schema.length; ++i) {
        schema[i] = "a" + i;
    }
    declarer.declare(new Fields(schema));
    PowerMockito.whenNew(SetupOutputFieldsDeclarer.class).withNoArguments().thenReturn(declarer);
    WrapperSetupHelper.getNumberOfAttributes(boltOrSpout, null);
}
Also used : IRichBolt(org.apache.storm.topology.IRichBolt) IRichSpout(org.apache.storm.topology.IRichSpout) Fields(org.apache.storm.tuple.Fields) IComponent(org.apache.storm.topology.IComponent) Test(org.junit.Test) AbstractTest(org.apache.flink.storm.util.AbstractTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Fields (org.apache.storm.tuple.Fields)170 Test (org.junit.Test)44 Values (org.apache.storm.tuple.Values)38 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)36 TridentTopology (org.apache.storm.trident.TridentTopology)32 HashMap (java.util.HashMap)31 Config (org.apache.storm.Config)31 Stream (org.apache.storm.trident.Stream)25 LocalCluster (org.apache.storm.LocalCluster)19 LocalTopology (org.apache.storm.LocalCluster.LocalTopology)17 TridentState (org.apache.storm.trident.TridentState)17 FixedBatchSpout (org.apache.storm.trident.testing.FixedBatchSpout)16 ArrayList (java.util.ArrayList)14 Map (java.util.Map)14 HiveOptions (org.apache.storm.hive.common.HiveOptions)14 AbstractTest (org.apache.flink.storm.util.AbstractTest)13 DelimitedRecordHiveMapper (org.apache.storm.hive.bolt.mapper.DelimitedRecordHiveMapper)12 IRichBolt (org.apache.storm.topology.IRichBolt)12 StateFactory (org.apache.storm.trident.state.StateFactory)12 Tuple (org.apache.storm.tuple.Tuple)12