hbase的eclipse集成开发环境搭建
1.在原来搭建的hadoop的eclipse环境中导入hbase目录下lib中的所有jar包
导入到hadoop原来的classpath中(Referenced Libraries)中即可
2.在mapreduce项目中新建conf文件夹,导入hbase-site.xml文件
3.Referenced Libraries构建路径,导入conf即可
利用mapreduce多表关联后向Hbase中写入结果数据
1.map程序:
package Test;
import java.io.IOException;
import java.util.StringTokenizer;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
public class GLMap extends Mapper<LongWritable, Text, Text, Text> {
Text key=new Text();Text value=new Text();
public void map(LongWritable ikey, Text ivalue, Context context) throws IOException, InterruptedException {
StringTokenizer cutter =new StringTokenizer(ivalue.toString());
int i=0;
while(cutter.hasMoreTokens()) {
String word=cutter.nextToken();
if(word.contains("SiteInfo")||word.contains("CityInfo")==true) {return;}
System.out.println(word);
String flag=new String();
if(word.charAt(0)>='a' && word.charAt(0)<='z') {
if(i>0) {flag="";}else {flag="@";}
value.set(word+flag);
}
else {
key.set(word);
i++;
}
}
context.write(key,value);
}
}
2.reduce程序:
package RuducerClass;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
public class HbaseReducer extends Reducer<Text, Text, Text, Text>