Search in sources :

Example 76 with Fields

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

the class ByTopicRecordTranslator method cacheNCheckFields.

private void cacheNCheckFields(RecordTranslator<K, V> translator) {
    for (String stream : translator.streams()) {
        Fields fromTrans = translator.getFieldsFor(stream);
        Fields cached = streamToFields.get(stream);
        if (cached != null && !fromTrans.equals(cached)) {
            throw new IllegalArgumentException("Stream " + stream + " currently has Fields of " + cached + " which is not the same as those being added in " + fromTrans);
        }
        if (cached == null) {
            streamToFields.put(stream, fromTrans);
        }
    }
}
Also used : Fields(org.apache.storm.tuple.Fields)

Example 77 with Fields

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

the class ByTopicRecordTranslatorTest method testTopicCollision.

@Test(expected = IllegalStateException.class)
public void testTopicCollision() {
    ByTopicRecordTranslator<String, String> trans = new ByTopicRecordTranslator<>((r) -> new Values(r.key()), new Fields("key"));
    trans.forTopic("foo", (r) -> new Values(r.value()), new Fields("value"), "foo1");
    trans.forTopic("foo", (r) -> new Values(r.key(), r.value()), new Fields("key", "value"), "foo2");
}
Also used : Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 78 with Fields

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

the class ByTopicRecordTranslatorTest method testFieldCollision.

@Test(expected = IllegalArgumentException.class)
public void testFieldCollision() {
    ByTopicRecordTranslator<String, String> trans = new ByTopicRecordTranslator<>((r) -> new Values(r.key()), new Fields("key"));
    trans.forTopic("foo", (r) -> new Values(r.value()), new Fields("value"));
}
Also used : Fields(org.apache.storm.tuple.Fields) Values(org.apache.storm.tuple.Values) Test(org.junit.Test)

Example 79 with Fields

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

the class DefaultRecordTranslatorTest method testBasic.

@Test
public void testBasic() {
    DefaultRecordTranslator<String, String> trans = new DefaultRecordTranslator<>();
    assertEquals(Arrays.asList("default"), trans.streams());
    assertEquals(new Fields("topic", "partition", "offset", "key", "value"), trans.getFieldsFor("default"));
    ConsumerRecord<String, String> cr = new ConsumerRecord<>("TOPIC", 100, 100, "THE KEY", "THE VALUE");
    assertEquals(Arrays.asList("TOPIC", 100, 100l, "THE KEY", "THE VALUE"), trans.apply(cr));
}
Also used : Fields(org.apache.storm.tuple.Fields) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 80 with Fields

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

the class KafkaTridentSpoutManager method getFields.

Fields getFields() {
    if (fields == null) {
        RecordTranslator<K, V> translator = kafkaSpoutConfig.getTranslator();
        Fields fs = null;
        for (String stream : translator.streams()) {
            if (fs == null) {
                fs = translator.getFieldsFor(stream);
            } else {
                if (!fs.equals(translator.getFieldsFor(stream))) {
                    throw new IllegalArgumentException("Trident Spouts do not support multiple output Fields");
                }
            }
        }
        fields = fs;
    }
    LOG.debug("OutputFields = {}", fields);
    return fields;
}
Also used : Fields(org.apache.storm.tuple.Fields)

Aggregations

Fields (org.apache.storm.tuple.Fields)176 Test (org.junit.Test)44 Values (org.apache.storm.tuple.Values)38 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)36 HashMap (java.util.HashMap)32 TridentTopology (org.apache.storm.trident.TridentTopology)32 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 Map (java.util.Map)15 ArrayList (java.util.ArrayList)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