Would like to be able to do C + + programs on Hadoop, their own C + + or a bit of a plot, according to the "Hadoop authoritative guide Chinese second Edition" Hadoop pipes test, and test success
#include <algorithm> #include <limits.h> #include <stdint.h> #include <string> #include Pip Es.hh "#include" templatefactory.hh "#include" stringutils.hh "class Maxtemperaturemapper:public Hadooppipes::mappe R {Public:maxtemperaturemapper (hadooppipes::taskcontext& context) {} void Map (Hadooppipes::mapcontext& ; Context) {std::string line = Context.getinputvalue (); Std::string year = LINE.SUBSTR (15, 4); std::string airtemperature = Line.substr (87, 5); std::string q = LINE.SUBSTR (92, 1); if (airtemperature! = "+9999" && (q = = "0" | | q = = "1" | | q = "4" | | q = "5" | | q = "9") {con Text.emit (year, airtemperature); } } }; Class Maptemperaturereducer:public Hadooppipes::reducer {public:maptemperaturereducer (HadoopPipes::TaskContext&am P context) {} void Reduce (hadooppipes::reducecontext& context) {int maxValue = int_min; while (Context.nextvalUE ()) {MaxValue = Std::max (MaxValue, Hadooputils::toint (Context.getinputvalue ())); } context.emit (Context.getinputkey (), hadooputils::tostring (MaxValue)); } }; int main (int argc, char *argv[]) {return Hadooppipes::runtask (Hadooppipes::templatefactory<maxtemperaturemapper, Maptemperaturereducer> ()); }
Note: Not the same place as the book: limit.h header file
Makefile file (modified by itself):
. Suffixes:.h. C. cpp. occ=g++cppflags =-m64 RM = Rmsrcs = Max_temperature.cppprogram = Max_temperatureinc_path =-I$ (HADOO P_dev_home)/includelib_path =-l$ (hadoop_dev_home)/lib/nativelibs =-lhadooppipes-lcrypto-lhadooputils-lpthread$ ( Program): $ (SRCS) $ (CC) $ (cppflags) $ (inc_path) $<-wall $ (lib_path) $ (LIBS) -g-o2-o [email protected]. phony:cleanclean:$ (RM) $ (program)
Source data files:
0067011990999991950051507004+68750+023550fm-12+038299999v0203301n00671220001cn9999999n9+00001+99999999999
0043011990999991950051512004+68750+023550fm-12+038299999v0203201n00671220001cn9999999n9+00221+99999999999
0043011990999991950051518004+68750+023550fm-12+038299999v0203201n00261220001cn9999999n9-00111+99999999999
0043012650999991949032412004+62300+010750fm-12+048599999v0202701n00461220001cn0500001n9+01111+99999999999
0043012650999991949032418004+62300+010750fm-12+048599999v0202701n00461220001cn0500001n9+00781+99999999999
Uploaded to Hdfs:hdfs dfs-put sample.txt
Make becomes the executable file uploaded to Hdfs:hdfs dfs-put max_temperature/bin
Execution method: Hadoop pipes-d hadoop.pipes.java.recordreader=true-d hadoop.pipes.java.recordwriter=true-input/user/root/ Sample.txt-output/output-program/bin/max_temperature
Data output results:
C + + programs under Hadoop-weather examples