Created
June 6, 2012 20:38
-
-
Save TylerBrock/2884606 to your computer and use it in GitHub Desktop.
Twitter MapReduce with MongoDB+Hadoop Streaming Adapter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
curl https://stream.twitter.com/1/statuses/sample.json -u<login>:<password> | mongoimport -d test -c live |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'mongo-hadoop' | |
MongoHadoop.map do |document| | |
{ :_id => document['user']['time_zone'], :count => 1 } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'mongo-hadoop' | |
MongoHadoop.reduce do |key, values| | |
count = sum = 0 | |
values.each do |value| | |
count += 1 | |
sum += value['num'] | |
end | |
{ :_id => key, :average => sum / count } | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hadoop jar mongo-hadoop-streaming-assembly*.jar -mapper mapper.rb -reducer reducer.rb -inputURI mongodb://127.0.0.1/twitter.in -outputURI mongodb://127.0.0.1/twitter.out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment