Java Code Examples for storm.trident.tuple.TridentTuple#getValue()

The following examples show how to use storm.trident.tuple.TridentTuple#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TweetSplitterFunction.java    From storm-example with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String tweet = (String) tuple.getValue(0);
    LOG.error("SPLITTING TWEET [" + tweet + "]");
    Pattern p = Pattern.compile("[a-zA-Z]+");
    Matcher m = p.matcher(tweet);
    List<String> result = new ArrayList<String>();
    while (m.find()) {
        String word = m.group();
        if (word.length() > 0) {
            List<Object> newTuple = new ArrayList<Object>();
            newTuple.add(word);
            collector.emit(newTuple);
        }
    }
}
 
Example 2
Source File: CityAssignment.java    From storm-example with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    DiagnosisEvent diagnosis = (DiagnosisEvent) tuple.getValue(0);
    double leastDistance = Double.MAX_VALUE;
    String closestCity = "NONE";
    for (Entry<String, double[]> city : CITIES.entrySet()) {
        double R = 6371; // km
        double x = (city.getValue()[0] - diagnosis.lng) * Math.cos((city.getValue()[0] + diagnosis.lng) / 2);
        double y = (city.getValue()[1] - diagnosis.lat);
        double d = Math.sqrt(x * x + y * y) * R;
        if (d < leastDistance) {
            leastDistance = d;
            closestCity = city.getKey();
        }
    }
    List<Object> values = new ArrayList<Object>();
    values.add(closestCity);
    LOG.debug("Closest city to lat=[" + diagnosis.lat + "], lng=[" + diagnosis.lng + "] == ["
            + closestCity + "], d=[" + leastDistance + "]");
    collector.emit(values);
}
 
Example 3
Source File: HourAssignment.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    DiagnosisEvent diagnosis = (DiagnosisEvent) tuple.getValue(0);
    String city = (String) tuple.getValue(1);
    long timestamp = diagnosis.time;
    long hourSinceEpoch = timestamp / 1000 / 60 / 60;
    LOG.debug("Key =  [" + city + ":" + hourSinceEpoch + "]");
    String key = city + ":" + diagnosis.diagnosisCode + ":" + hourSinceEpoch;

    List<Object> values = new ArrayList<Object>();
    values.add(hourSinceEpoch);
    values.add(key);
    collector.emit(values);
}
 
Example 4
Source File: VectorBuilder.java    From first-stories-twitter with MIT License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
	Tweet tweet = (Tweet) tuple.getValue(0);
	String tweetBody = tweet.getBody();

       String words[] = tweetBody.toLowerCase().split(regex);
       if (words.length > 0) {
       	collector.emit(getValues(tweet, words));
       } else {
           tweetBody = "ONLYLINKSANDMENTIONZ";
           String dummyWord[] = {tweetBody};
           collector.emit(getValues(tweet, dummyWord));
       }
}
 
Example 5
Source File: BucketsStateQuery.java    From first-stories-twitter with MIT License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, ArrayList<Tweet> collidingTweets,
		TridentCollector collector) {
	//emit by tweet id
	Tweet tw = (Tweet) tuple.getValue(0);
	collector.emit(new Values(tw.getID(), collidingTweets));
}
 
Example 6
Source File: ExpandList.java    From first-stories-twitter with MIT License 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
	@SuppressWarnings("rawtypes")
	List<Tweet> l = (List<Tweet>) tuple.getValue(0);
	if (l != null) {
		for (Tweet o : l) {
			collector.emit(new Values(o, o.getID()));
		}
	}
}
 
Example 7
Source File: TridentReach.java    From flink-perf with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
  List l = (List) tuple.getValue(0);
  if (l != null) {
    for (Object o : l) {
      collector.emit(new Values(o));
    }
  }
}
 
Example 8
Source File: Expand.java    From storm-benchmark with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
  Iterable iterable = (Iterable) tuple.getValue(0);
  Iterator iterator = iterable.iterator();
  while (iterator.hasNext()) {
   collector.emit(new Values(iterator.next()));
  }
}
 
Example 9
Source File: DruidStateUpdater.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void updateState(DruidState state, List<TridentTuple> tuples, TridentCollector collector) {
    //LOG.info("Updating [" + state + "]");
    for (TridentTuple tuple : tuples) {
        FixMessageDto message = (FixMessageDto) tuple.getValue(0);
        state.aggregateMessage(message);
    }
}
 
Example 10
Source File: PrinterFunction.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    FixMessageDto message = (FixMessageDto) tuple.getValue(0);
    Log.error("MESSAGE RECEIVED [" + message + "]");
    List<Object> values = new ArrayList<Object>();
    values.add(message);
    collector.emit(values);
}
 
Example 11
Source File: Equals.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isKeep(TridentTuple tuple) {
    for (int i = 0; i < tuple.size() - 1; i++) {
        Object o1 = tuple.getValue(i);
        Object o2 = tuple.getValue(i + 1);
        if (o1 == null && o2 != null || o1 != null && !o1.equals(o2)) {
            return false;
        }
    }
    return true;
}
 
Example 12
Source File: DispatchAlert.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String alert = (String) tuple.getValue(0);
    Log.error("ALERT RECEIVED [" + alert + "]");
    Log.error("Dispatch the national guard!");
    System.exit(0);
}
 
Example 13
Source File: OutbreakDetector.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String key = (String) tuple.getValue(0);
    Long count = (Long) tuple.getValue(1);
    if (count > THRESHOLD) {
        List<Object> values = new ArrayList<Object>();
        values.add("Outbreak detected for [" + key + "]!");
        collector.emit(values);
    }
}
 
Example 14
Source File: TridentReach.java    From jstorm with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    List l = (List) tuple.getValue(0);
    if (l != null) {
        for (Object o : l) {
            collector.emit(new Values(o));
        }
    }
}
 
Example 15
Source File: StormFirehose.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public InputRow nextRow() {
    final Map<String, Object> theMap = Maps.newTreeMap(String.CASE_INSENSITIVE_ORDER);
    try {
        TridentTuple tuple = null;
        tuple = BLOCKING_QUEUE.poll();
        if (tuple != null) {
            String phrase = (String) tuple.getValue(0);
            String word = (String) tuple.getValue(2);
            Long baseline = (Long) tuple.getValue(3);
            theMap.put("searchphrase", phrase);
            theMap.put("word", word);
            theMap.put("baseline", baseline);
        }

        if (BLOCKING_QUEUE.isEmpty()) {
            STATUS.putInLimbo(TRANSACTION_ID);
            LIMBO_TRANSACTIONS.add(TRANSACTION_ID);
            LOG.info("Batch is fully consumed by Druid. Unlocking [FINISH]");
            synchronized (FINISHED) {
                FINISHED.notify();
            }
        }
    } catch (Exception e) {
        LOG.error("Error occurred in nextRow.", e);
    }
    final LinkedList<String> dimensions = new LinkedList<String>();
    dimensions.add("searchphrase");
    dimensions.add("word");
    return new MapBasedInputRow(System.currentTimeMillis(), dimensions, theMap);
}
 
Example 16
Source File: WordFrequencyFunction.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String word = (String) tuple.getValue(2);
    Long baseline = this.getLikelihood(word);
    List<Object> newTuple = new ArrayList<Object>();
    newTuple.add(baseline);
    collector.emit(newTuple);
}
 
Example 17
Source File: PrinterFunction.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String terms = (String) tuple.getValue(0);
    String tweet = (String) tuple.getValue(1);
    String word = (String) tuple.getValue(2);
    LOG.error("[" + terms + "],[" + tweet + "],[" + word + "]");
}
 
Example 18
Source File: CampaignEffectiveness.java    From storm-example with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String campaign = (String) tuple.getValue(0);
    Long impressions_count = (Long) tuple.getValue(1);
    Long click_thru_count = (Long) tuple.getValue(2);
    if (click_thru_count == null)
        click_thru_count = new Long(0);
    double effectiveness = (double) click_thru_count / (double) impressions_count;
    Log.error("[" + campaign + "," + String.valueOf(click_thru_count) + "," + impressions_count + ", " + effectiveness + "]");
    List<Object> values = new ArrayList<Object>();
    values.add(campaign);
    collector.emit(values);
}
 
Example 19
Source File: IndexMapStateTest.java    From storm-trident-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    Document t = (Document)tuple.getValue(0);
    collector.emit(new Values(t.getId(), t.getName(), t.getType()));
}
 
Example 20
Source File: ExtractSearchArgs.java    From storm-trident-elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    String args = (String)tuple.getValue(0);
    String[] split = args.split(" ");
    collector.emit(new Values(split[0], Lists.newArrayList(split[1]), Lists.newArrayList(split[2])));
}