Instance
Scenario
The sample project illustrates how to compile MapReduce jobs to visit multiple service components in HDFS, HBase, and Hive, helping users to understand key actions such as certificating and configuration loading.
The logic of the sample project is as follows:
The input data is HDFS text file and the input file is log1.txt.
YuanJing,male,10 GuoYijun,male,5
Map:
- Obtain one row of the input data and extract the user name.
- Query one piece of data from HBase.
- Query one piece of data from Hive.
- Combine the data queried from HBase and that from Hive as the output of Map as the output of Map.
Reduce:
- Obtain the last piece of data from Map output.
- Import the data to HBase.
- Save the data to HDFS.
Data Planning
- Create an HDFS data file.
- Create a text file named data.txt in the Linux-based HDFS and copy the content of log1.txt to data.txt.
- Run the following commands to create a directory /tmp/examples/multi-components/mapreduce/input/ and copy the data.txt to the directory:
- Create a HBase table and insert data into it.
- Run the source bigdata_env command on a Linux-based HBase client and run the hbase shell command.
- Run the create 'table1', 'cf' command in the HBase shell to create table1 with column family cf.
- Run the put 'table1', '1', 'cf:cid', '123' command to insert data whose rowkey is 1, column name is cid, and data value is 123.
- Run the quit command to exit the table.
- Create a Hive table and load data to it.
- Run the beeline command on a Linux-based Hive client.
- In the Hive beeline interaction window, run the CREATE TABLE person(name STRING, gender STRING, stayTime INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY ',' stored as textfile; command to create data table person with three fields.
- In the Hive beeline interaction window, run the LOAD DATA INPATH '/tmp/examples/multi-components/mapreduce/input/' OVERWRITE INTO TABLE person; command to load data files to the person table.
- Run !q to exit the table.
- The data of HDFS is cleared in the preceding step. Therefore, perform 1 again.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot