熟悉常用的HBase操作,编写MapReduce作业

1

***创建数据表studen
   其中info,course分别为表studen的两个列族,
info存储学生个人信息——学号、姓名、性别、年龄
course 则存储课程信息***
create 'studen','info','course'



接着添加学号为2015001的学生信息
put 'studen','001','info:S_No','2015001'
此行代码插入一个行健为001的数据,且在列族info中添加一个列S_No,值为2015001。同时由于Hbase一次只能添加一个列数据,所以下面继续添加2015001其他信息
put 'studen','001','info:S_Name','Zhangsan'
put 'studen','001','info:S_Sex','male'
put 'studen','001','info:S_Age','23'

2

3

cd /home/hadoop/wc
sudo gedit mapper.py

import sys
for i in stdin:
    i = i.strip()
    words = i.split()
    for word in words:
    print '%s\t%s' % (word,1)

from operator import itemgetter
import sys

current_word = None
current_count = 0
word = None

for i in stdin:
    i = i.strip()
    word, count = i.split('\t',1)
    try:
    count = int(count)
    except ValueError:
    continue

    if current_word == word:
    current_count += count 
    else:
    if current_word:
        print '%s\t%s' % (current_word, current_count)
    current_count = count
    current_word = word

if current_word == word:
    print '%s\t%s' % (current_word, current_count)

cd /home/hadoop/wc
sudo gedit reducer.py

chmod a+x /home/hadoop/mapper.py


#上传
cd  /home/hadoop/wc
wget http://www.gutenberg.org/files/5000/5000-8.txt
wget http://www.gutenberg.org/cache/epub/20417/pg20417.txt

#下载
cd /usr/hadoop/wc
hdfs dfs -put /home/hadoop/hadoop/gutenberg/*.txt /user/hadoop/input

 

转载于:https://www.cnblogs.com/168-hui/p/9010953.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值