Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ::::::::::::::
- dp_hpt_mr.hh
- ::::::::::::::
- #ifndef __DP_HPT_MR_HH__
- #define __DP_HPT_MR_HH__
- #include <Pipes.hh>
- namespace dp_hpt
- {
- class word_count_mapper : public HadoopPipes::Mapper
- {
- public:
- word_count_mapper(const HadoopPipes::TaskContext &) {};
- void map(HadoopPipes::MapContext & context);
- };
- class word_count_reducer : public HadoopPipes::Reducer
- {
- public:
- word_count_reducer(const HadoopPipes::TaskContext &) {};
- void reduce(HadoopPipes::ReduceContext & context);
- };
- };
- #endif //__DP_HPT_MR_HH__
- ::::::::::::::
- dp_hadoop_pipes_test.cpp
- ::::::::::::::
- #include "dp_hpt_mr.hh"
- #include <iostream>
- #include <TemplateFactory.hh>
- using namespace std;
- int
- main(int argc,
- char * argv[])
- {
- HadoopPipes::TemplateFactory2<dp_hpt::word_count_mapper,
- dp_hpt::word_count_reducer> factory;
- return HadoopPipes::runTask(factory);
- }
- ::::::::::::::
- dp_hpt_mr.cpp
- ::::::::::::::
- #include "dp_hpt_mr.hh"
- #include <boost/algorithm/string.hpp>
- #include <boost/tokenizer.hpp>
- #include <boost/lexical_cast.hpp>
- #include <string>
- namespace dp_hpt
- {
- void word_count_mapper::map(HadoopPipes::MapContext & context)
- {
- typedef boost::tokenizer<> tokenizer_t;
- tokenizer_t tokenizer(context.getInputValue());
- for(tokenizer_t::const_iterator i = tokenizer.begin();
- tokenizer.end() != i;
- ++i)
- {
- context.emit(boost::to_lower_copy(*i), "1");
- }
- }
- void word_count_reducer::reduce(HadoopPipes::ReduceContext & context)
- {
- uint32_t count(0);
- do
- {
- ++count;
- }
- while(context.nextValue());
- context.emit(context.getInputKey(),
- boost::lexical_cast<std::string>(count));
- }
- };
- ::::::::::::::
- ../conf/dp_hpt_conf.xml
- ::::::::::::::
- <?xml version="1.0"?>
- <configuration>
- <property>
- <name>hadoop.pipes.executable</name>
- <value>/path/to/dp_hadoop_pipes_test</value>
- </property>
- <property>
- <name>hadoop.pipes.java.recordreader</name>
- <value>true</value>
- </property>
- <property>
- <name>hadoop.pipes.java.recordwriter</name>
- <value>true</value>
- </property>
- </configuration>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement