Java Code Examples for storm.trident.tuple.TridentTuple#getDoubleByField()
The following examples show how to use
storm.trident.tuple.TridentTuple#getDoubleByField() .
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: Decider.java From first-stories-twitter with MIT License | 6 votes |
@Override public NearNeighbour init(TridentTuple tuple) { Tweet tw = (Tweet) tuple.getValueByField("tweet_obj"); Tweet bucketTweet = (Tweet) tuple.getValueByField("coltweet_obj"); double cosineBuckets = tuple.getDoubleByField("cosSimBckts"); Object closestRecentObj = tuple.getValueByField("nnRecentTweet"); NearNeighbour closestRecent = null; if (closestRecentObj != null) closestRecent = (NearNeighbour) closestRecentObj; if (closestRecent != null) { if (cosineBuckets >= closestRecent.getCosine()) return new NearNeighbour(cosineBuckets, bucketTweet); else return closestRecent; } else { return new NearNeighbour(cosineBuckets, bucketTweet); } }
Example 2
Source File: RecentTweetsStateQuery.java From first-stories-twitter with MIT License | 5 votes |
@Override public List<NearNeighbour> batchRetrieve(RecentTweetsDB state, List<TridentTuple> args) { List<NearNeighbour> tweets = new ArrayList<NearNeighbour>(); for (TridentTuple tuple : args) { Tweet tw = (Tweet) tuple.getValueByField("tweet_obj"); double cosSimBuckets = tuple.getDoubleByField("cosSimBckts"); NearNeighbour closestNeighbour = null; // check if comparisons are needed and iterate over all recent // tweets and find the closest if (cosSimBuckets <= threshold) closestNeighbour = state.getClosestNeighbour(tw); // else a close enough tweet has been found in the buckets tweets.add(closestNeighbour); //not every tweet should be inserted into the most recent tweets of each state //Insert in all partitions in a round-robin fashion //we sacrifice fault-tolerance here. If a partition fails and recovers, //two partitions may insert at the same time myturn++; if (myturn == numPartitions) { state.insert(tw); myturn = 0; } } return tweets; }