你的位置:首页 > Java教程

[Java教程]hbase 二级索引创建


在单机上运行hbase 二级索引:

import java.io.IOException;import java.util.HashMap;import java.util.Map;import java.util.Set;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.fs.Path;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.client.Put;import org.apache.hadoop.hbase.client.Result;import org.apache.hadoop.hbase.client.Scan;import org.apache.hadoop.hbase.io.ImmutableBytesWritable;import org.apache.hadoop.hbase.mapreduce.MultiTableOutputFormat;import org.apache.hadoop.hbase.mapreduce.TableInputFormat;import org.apache.hadoop.hbase.mapreduce.TableMapReduceUtil;import org.apache.hadoop.hbase.mapreduce.TableMapper;import org.apache.hadoop.hbase.util.Bytes;import org.apache.hadoop.mapreduce.Job;import org.apache.hadoop.mapreduce.Mapper;import com.tansun.di.core.di.core.hbase.HBaseDaoPool;public class IndexCreateExample extends		TableMapper<ImmutableBytesWritable, Put> {	public static Configuration conf = null;	private String familyName;	// 原始表	private Map<byte[], ImmutableBytesWritable> indexes = new HashMap<byte[], ImmutableBytesWritable>();	 static {	    conf = new Configuration();	    String filePath = "hbase-site.

 出现异常信息:内存不足

or more detailed output, check application tracking page:http://ts.node2.com:8088/proxy/application_1472537544791_0007/Then, click on links to logs of each attempt.Diagnostics: Container [pid=3984,containerID=container_1472537544791_0007_02_000001] is running beyond physical memory limits. Current usage: 285.6 MB of 256 MB physical memory used; 1.5 GB of 537.6 MB virtual memory used. Killing container.Dump of the process-tree for container_1472537544791_0007_02_000001 :	|- PID PPID PGRPID SESSID CMD_NAME USER_MODE_TIME(MILLIS) SYSTEM_TIME(MILLIS) VMEM_USAGE(BYTES) RSSMEM_USAGE(PAGES) FULL_CMD_LINE	|- 3984 3982 3984 3984 (bash) 0 0 108617728 338 /bin/bash -c /usr/java/jdk1.7.0_79/bin/java -Dlog4j.configuration=container-log4j.properties -Dyarn.app.container.log.dir=/var/log/hadoop-yarn/container/application_1472537544791_0007/container_1472537544791_0007_02_000001 -Dyarn.app.container.log.filesize=0 -Dhadoop.root.logger=INFO,CLA -Djava.net.preferIPv4Stack=true -Xmx825955249 org.apache.hadoop.mapreduce.v2.app.MRAppMaster 1>/var/log/hadoop-yarn/container/application_1472537544791_0007/container_1472537544791_0007_02_000001/stdout 2>/var/log/hadoop-yarn/container/application_1472537544791_0007/container_1472537544791_0007_02_000001/stderr 	|- 3999 3984 3984 3984 (java) 2183 69 1504305152 72786 /usr/java/jdk1.7.0_79/bin/java -Dlog4j.configuration=container-log4j.properties -Dyarn.app.container.log.dir=/var/log/hadoop-yarn/container/application_1472537544791_0007/container_1472537544791_0007_02_000001 -Dyarn.app.container.log.filesize=0 -Dhadoop.root.logger=INFO,CLA -Djava.net.preferIPv4Stack=true -Xmx825955249 org.apache.hadoop.mapreduce.v2.app.MRAppMaster Container killed on request. Exit code is 143Container exited with a non-zero exit code 143Failing this attempt. Failing the application.16/09/01 11:07:56 INFO mapreduce.Job: Counters: 0

 异常2:

 

 

创建原始表hbase(main):002:0> create 'studentinfo','f1'0 row(s) in 0.6520 seconds=> Hbase::Table - studentinfohbase(main):003:0> put 'studentinfo','1','f1:name','zhangsan'0 row(s) in 0.1640 secondshbase(main):004:0> put 'studentinfo','2','f1:name','lisi'0 row(s) in 0.0240 secondshbase(main):005:0> put 'studentinfo','3','f1:name','wangwu'0 row(s) in 0.0290 secondshbase(main):006:0> scan 'studentinfo'ROW           COLUMN+CELL 1            column=f1:name, timestamp=1436262175823, value=zhangsan 2            column=f1:name, timestamp=1436262183922, value=lisi 3            column=f1:name, timestamp=1436262189250, value=wangwu3 row(s) in 0.0530 seconds

 

创建索引表 hbase(main):007:0> create 'studentinfo-name','f1'

0 row(s) in 0.7740 seconds => Hbase::Table - studentinfo-name