码迷,mamicode.com
首页 > 编程语言 > 详细

HBase-java api 基本操作

时间:2014-11-11 15:55:04      阅读:344      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   io   color   ar   os   使用   


使用的是完全分布式,详细信息为:

bubuko.com,布布扣


 

操作的Java 代码(抄的别人的)

  1 package org.admln.hbase;
  2 
  3 import java.util.ArrayList;
  4 import java.util.List;
  5 
  6 import org.apache.hadoop.conf.Configuration;
  7 import org.apache.hadoop.hbase.HBaseConfiguration;
  8 import org.apache.hadoop.hbase.HColumnDescriptor;
  9 import org.apache.hadoop.hbase.HTableDescriptor;
 10 import org.apache.hadoop.hbase.KeyValue;
 11 import org.apache.hadoop.hbase.TableName;
 12 import org.apache.hadoop.hbase.client.Delete;
 13 import org.apache.hadoop.hbase.client.Get;
 14 import org.apache.hadoop.hbase.client.HBaseAdmin;
 15 import org.apache.hadoop.hbase.client.HTable;
 16 import org.apache.hadoop.hbase.client.Put;
 17 import org.apache.hadoop.hbase.client.Result;
 18 import org.apache.hadoop.hbase.client.ResultScanner;
 19 import org.apache.hadoop.hbase.client.Scan;
 20 import org.apache.hadoop.hbase.util.Bytes;
 21 
 22 public class OperateTable {
 23     // 声明静态配置
 24     private static Configuration conf = null;
 25     static {
 26         conf = HBaseConfiguration.create();
 27         conf.set("hbase.zookeeper.quorum", "slave1");
 28         conf.set("hbase.zookeeper.property.clientPort", "2181");
 29     }
 30 
 31     // 创建数据库表
 32     public static void createTable(String tableName, String[] columnFamilys)
 33             throws Exception {
 34         // 新建一个数据库管理员
 35         HBaseAdmin hAdmin = new HBaseAdmin(conf);
 36 
 37         if (hAdmin.tableExists(tableName)) {
 38             System.out.println("表已经存在");
 39             System.exit(0);
 40         } else {
 41             // 新建一个 scores 表的描述
 42             HTableDescriptor tableDesc = new HTableDescriptor(
 43                     TableName.valueOf(tableName));
 44             // 在描述里添加列族
 45             for (String columnFamily : columnFamilys) {
 46                 tableDesc.addFamily(new HColumnDescriptor(columnFamily));
 47             }
 48             // 根据配置好的描述建表
 49             hAdmin.createTable(tableDesc);
 50             System.out.println("创建表成功");
 51         }
 52     }
 53 
 54     // 删除数据库表
 55     public static void deleteTable(String tableName) throws Exception {
 56         // 新建一个数据库管理员
 57         HBaseAdmin hAdmin = new HBaseAdmin(conf);
 58 
 59         if (hAdmin.tableExists(tableName)) {
 60             // 关闭一个表
 61             hAdmin.disableTable(tableName);
 62             // 删除一个表
 63             hAdmin.deleteTable(tableName);
 64             System.out.println("删除表成功");
 65 
 66         } else {
 67             System.out.println("删除的表不存在");
 68             System.exit(0);
 69         }
 70     }
 71 
 72     // 添加一条数据
 73     public static void addRow(String tableName, String row,
 74             String columnFamily, String column, String value) throws Exception {
 75         HTable table = new HTable(conf, tableName);
 76         Put put = new Put(Bytes.toBytes(row));
 77         // 参数出分别:列族、列、值
 78         put.add(Bytes.toBytes(columnFamily), Bytes.toBytes(column),
 79                 Bytes.toBytes(value));
 80         table.put(put);
 81     }
 82 
 83     // 删除一条数据
 84     public static void delRow(String tableName, String row) throws Exception {
 85         HTable table = new HTable(conf, tableName);
 86         Delete del = new Delete(Bytes.toBytes(row));
 87         table.delete(del);
 88     }
 89 
 90     // 删除多条数据
 91     public static void delMultiRows(String tableName, String[] rows)
 92             throws Exception {
 93         HTable table = new HTable(conf, tableName);
 94         List<Delete> list = new ArrayList<Delete>();
 95 
 96         for (String row : rows) {
 97             Delete del = new Delete(Bytes.toBytes(row));
 98             list.add(del);
 99         }
100 
101         table.delete(list);
102     }
103 
104     // get row
105     public static void getRow(String tableName, String row) throws Exception {
106         HTable table = new HTable(conf, tableName);
107         Get get = new Get(Bytes.toBytes(row));
108         Result result = table.get(get);
109         // 输出结果
110         for (KeyValue rowKV : result.raw()) {
111             System.out.print("Row Name: " + new String(rowKV.getRow()) + " ");
112             System.out.print("Timestamp: " + rowKV.getTimestamp() + " ");
113             System.out.print("column Family: " + new String(rowKV.getFamily())
114                     + " ");
115             System.out.print("Row Name:  " + new String(rowKV.getQualifier())
116                     + " ");
117             System.out.println("Value: " + new String(rowKV.getValue()) + " ");
118         }
119     }
120 
121     // get all records
122     public static void getAllRows(String tableName) throws Exception {
123         HTable table = new HTable(conf, tableName);
124         Scan scan = new Scan();
125         ResultScanner results = table.getScanner(scan);
126         // 输出结果
127         for (Result result : results) {
128             for (KeyValue rowKV : result.raw()) {
129                 System.out.print("Row Name: " + new String(rowKV.getRow())
130                         + " ");
131                 System.out.print("Timestamp: " + rowKV.getTimestamp() + " ");
132                 System.out.print("column Family: "
133                         + new String(rowKV.getFamily()) + " ");
134                 System.out.print("Row Name:  "
135                         + new String(rowKV.getQualifier()) + " ");
136                 System.out.println("Value: " + new String(rowKV.getValue())
137                         + " ");
138             }
139         }
140     }
141 
142     // main
143     public static void main(String[] args) {
144         try {
145             String tableName = "users2";
146 
147             // 第一步:创建数据库表:“users2”
148             String[] columnFamilys = { "info", "course" };
149             OperateTable.createTable(tableName, columnFamilys);
150 
151             // 第二步:向数据表的添加数据
152             // 添加第一行数据
153             OperateTable.addRow(tableName, "tht", "info", "age", "20");
154             OperateTable.addRow(tableName, "tht", "info", "sex", "boy");
155             OperateTable.addRow(tableName, "tht", "course", "china", "97");
156             OperateTable.addRow(tableName, "tht", "course", "math", "128");
157             OperateTable.addRow(tableName, "tht", "course", "english", "85");
158             // 添加第二行数据
159             OperateTable.addRow(tableName, "xiaoxue", "info", "age", "19");
160             OperateTable.addRow(tableName, "xiaoxue", "info", "sex", "boy");
161             OperateTable.addRow(tableName, "xiaoxue", "course", "china", "90");
162             OperateTable.addRow(tableName, "xiaoxue", "course", "math", "120");
163             OperateTable
164                     .addRow(tableName, "xiaoxue", "course", "english", "90");
165             // 添加第三行数据
166             OperateTable.addRow(tableName, "qingqing", "info", "age", "18");
167             OperateTable.addRow(tableName, "qingqing", "info", "sex", "girl");
168             OperateTable
169                     .addRow(tableName, "qingqing", "course", "china", "100");
170             OperateTable.addRow(tableName, "qingqing", "course", "math", "100");
171             OperateTable.addRow(tableName, "qingqing", "course", "english",
172                     "99");
173             // 第三步:获取一条数据
174             System.out.println("获取一条数据");
175             OperateTable.getRow(tableName, "tht");
176             // 第四步:获取所有数据
177             System.out.println("获取所有数据");
178             OperateTable.getAllRows(tableName);
179             // 第五步:删除一条数据
180             System.out.println("删除一条数据");
181             OperateTable.delRow(tableName, "tht");
182             OperateTable.getAllRows(tableName);
183             // 第六步:删除多条数据
184             System.out.println("删除多条数据");
185             String[] rows = { "xiaoxue", "qingqing" };
186             OperateTable.delMultiRows(tableName, rows);
187             OperateTable.getAllRows(tableName);
188             // 第八步:删除数据库
189             System.out.println("删除数据库");
190             OperateTable.deleteTable(tableName);
191 
192         } catch (Exception err) {
193             err.printStackTrace();
194         }
195     }
196 }

运行结果为:

  1 2014-11-11 14:09:00,368 WARN  util.NativeCodeLoader (NativeCodeLoader.java:<clinit>(62)) - Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
  2 2014-11-11 14:09:00,455 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:zookeeper.version=3.4.5-1392090, built on 09/30/2012 17:52 GMT
  3 2014-11-11 14:09:00,455 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:host.name=WZJ-20140910JYZ
  4 2014-11-11 14:09:00,455 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:java.version=1.7.0_72
  5 2014-11-11 14:09:00,455 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:java.vendor=Oracle Corporation
  6 2014-11-11 14:09:00,455 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:java.home=C:\Program Files (x86)\Java\jre7
  7 2014-11-11 14:09:00,455 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:java.class.path= 。。。省略
  8 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:java.io.tmpdir=C:\Users\ADMINI~1\AppData\Local\Temp  9 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:java.compiler=<NA>
 10 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:os.name=Windows 7
 11 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:os.arch=x86
 12 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:os.version=6.1
 13 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:user.name=Administrator
 14 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:user.home=C:\Users\Administrator
 15 2014-11-11 14:09:00,456 INFO  zookeeper.ZooKeeper (Environment.java:logEnv(100)) - Client environment:user.dir=D:\eclipseWorkspace32\hbase
 16 2014-11-11 14:09:00,458 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=hconnection-0x21801b
 17 2014-11-11 14:09:00,482 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
 18 2014-11-11 14:09:00,498 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
 19 2014-11-11 14:09:00,500 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
 20 2014-11-11 14:09:00,513 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d6002d, negotiated timeout = 90000
 21 2014-11-11 14:09:00,680 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
 22 2014-11-11 14:09:00,683 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
 23 2014-11-11 14:09:00,683 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
 24 2014-11-11 14:09:00,684 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
 25 2014-11-11 14:09:00,686 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d6002e, negotiated timeout = 90000
 26 2014-11-11 14:09:00,711 INFO  Configuration.deprecation (Configuration.java:warnOnceIfDeprecated(840)) - hadoop.native.lib is deprecated. Instead, use io.native.lib.available
 27 2014-11-11 14:09:01,078 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d6002e closed
 28 2014-11-11 14:09:01,078 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
 29 2014-11-11 14:09:01,248 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
 30 2014-11-11 14:09:01,250 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
 31 2014-11-11 14:09:01,251 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
 32 2014-11-11 14:09:01,252 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
 33 2014-11-11 14:09:01,254 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d6002f, negotiated timeout = 90000
 34 2014-11-11 14:09:01,263 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d6002f closed
 35 2014-11-11 14:09:01,263 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
 36 创建表成功
 37 获取一条数据
 38 Row Name: tht Timestamp: 1415686141316 column Family: course Row Name:  china Value: 97 
 39 Row Name: tht Timestamp: 1415686141343 column Family: course Row Name:  english Value: 85 
 40 Row Name: tht Timestamp: 1415686141340 column Family: course Row Name:  math Value: 128 
 41 Row Name: tht Timestamp: 1415686141303 column Family: info Row Name:  age Value: 20 
 42 Row Name: tht Timestamp: 1415686141313 column Family: info Row Name:  sex Value: boy 
 43 获取所有数据
 44 Row Name: qingqing Timestamp: 1415686141375 column Family: course Row Name:  china Value: 100 
 45 Row Name: qingqing Timestamp: 1415686141381 column Family: course Row Name:  english Value: 99 
 46 Row Name: qingqing Timestamp: 1415686141378 column Family: course Row Name:  math Value: 100 
 47 Row Name: qingqing Timestamp: 1415686141362 column Family: info Row Name:  age Value: 18 
 48 Row Name: qingqing Timestamp: 1415686141365 column Family: info Row Name:  sex Value: girl 
 49 Row Name: tht Timestamp: 1415686141316 column Family: course Row Name:  china Value: 97 
 50 Row Name: tht Timestamp: 1415686141343 column Family: course Row Name:  english Value: 85 
 51 Row Name: tht Timestamp: 1415686141340 column Family: course Row Name:  math Value: 128 
 52 Row Name: tht Timestamp: 1415686141303 column Family: info Row Name:  age Value: 20 
 53 Row Name: tht Timestamp: 1415686141313 column Family: info Row Name:  sex Value: boy 
 54 Row Name: xiaoxue Timestamp: 1415686141353 column Family: course Row Name:  china Value: 90 
 55 Row Name: xiaoxue Timestamp: 1415686141359 column Family: course Row Name:  english Value: 90 
 56 Row Name: xiaoxue Timestamp: 1415686141355 column Family: course Row Name:  math Value: 120 
 57 Row Name: xiaoxue Timestamp: 1415686141347 column Family: info Row Name:  age Value: 19 
 58 Row Name: xiaoxue Timestamp: 1415686141350 column Family: info Row Name:  sex Value: boy 
 59 删除一条数据
 60 Row Name: qingqing Timestamp: 1415686141375 column Family: course Row Name:  china Value: 100 
 61 Row Name: qingqing Timestamp: 1415686141381 column Family: course Row Name:  english Value: 99 
 62 Row Name: qingqing Timestamp: 1415686141378 column Family: course Row Name:  math Value: 100 
 63 Row Name: qingqing Timestamp: 1415686141362 column Family: info Row Name:  age Value: 18 
 64 Row Name: qingqing Timestamp: 1415686141365 column Family: info Row Name:  sex Value: girl 
 65 Row Name: xiaoxue Timestamp: 1415686141353 column Family: course Row Name:  china Value: 90 
 66 Row Name: xiaoxue Timestamp: 1415686141359 column Family: course Row Name:  english Value: 90 
 67 Row Name: xiaoxue Timestamp: 1415686141355 column Family: course Row Name:  math Value: 120 
 68 Row Name: xiaoxue Timestamp: 1415686141347 column Family: info Row Name:  age Value: 19 
 69 Row Name: xiaoxue Timestamp: 1415686141350 column Family: info Row Name:  sex Value: boy 
 70 删除多条数据
 71 删除数据库
 72 2014-11-11 14:09:01,449 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
 73 2014-11-11 14:09:01,451 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
 74 2014-11-11 14:09:01,452 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
 75 2014-11-11 14:09:01,452 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
 76 2014-11-11 14:09:01,454 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d60030, negotiated timeout = 90000
 77 2014-11-11 14:09:01,459 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d60030 closed
 78 2014-11-11 14:09:01,459 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
 79 2014-11-11 14:09:01,460 INFO  client.HBaseAdmin (HBaseAdmin.java:call(908)) - Started disable of users
 80 2014-11-11 14:09:01,479 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
 81 2014-11-11 14:09:01,481 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
 82 2014-11-11 14:09:01,481 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
 83 2014-11-11 14:09:01,482 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
 84 2014-11-11 14:09:01,486 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d60031, negotiated timeout = 90000
 85 2014-11-11 14:09:01,500 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d60031 closed
 86 2014-11-11 14:09:01,500 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
 87 2014-11-11 14:09:01,601 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
 88 2014-11-11 14:09:01,603 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
 89 2014-11-11 14:09:01,604 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
 90 2014-11-11 14:09:01,604 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
 91 2014-11-11 14:09:01,606 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d60032, negotiated timeout = 90000
 92 2014-11-11 14:09:01,614 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d60032 closed
 93 2014-11-11 14:09:01,614 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
 94 2014-11-11 14:09:01,816 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
 95 2014-11-11 14:09:01,823 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
 96 2014-11-11 14:09:01,828 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
 97 2014-11-11 14:09:01,831 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
 98 2014-11-11 14:09:01,837 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d60033, negotiated timeout = 90000
 99 2014-11-11 14:09:01,856 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d60033 closed
100 2014-11-11 14:09:01,856 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
101 2014-11-11 14:09:02,157 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
102 2014-11-11 14:09:02,161 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
103 2014-11-11 14:09:02,163 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
104 2014-11-11 14:09:02,164 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
105 2014-11-11 14:09:02,168 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d60034, negotiated timeout = 90000
106 2014-11-11 14:09:02,185 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d60034 closed
107 2014-11-11 14:09:02,185 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
108 2014-11-11 14:09:02,686 INFO  zookeeper.ZooKeeper (ZooKeeper.java:<init>(438)) - Initiating client connection, connectString=slave1:2181 sessionTimeout=90000 watcher=catalogtracker-on-hconnection-0x21801b
109 2014-11-11 14:09:02,691 INFO  zookeeper.RecoverableZooKeeper (RecoverableZooKeeper.java:<init>(120)) - Process identifier=catalogtracker-on-hconnection-0x21801b connecting to ZooKeeper ensemble=slave1:2181
110 2014-11-11 14:09:02,691 INFO  zookeeper.ClientCnxn (ClientCnxn.java:logStartConnect(966)) - Opening socket connection to server slave1/192.168.126.135:2181. Will not attempt to authenticate using SASL (unknown error)
111 2014-11-11 14:09:02,693 INFO  zookeeper.ClientCnxn (ClientCnxn.java:primeConnection(849)) - Socket connection established to slave1/192.168.126.135:2181, initiating session
112 2014-11-11 14:09:02,696 INFO  zookeeper.ClientCnxn (ClientCnxn.java:onConnected(1207)) - Session establishment complete on server slave1/192.168.126.135:2181, sessionid = 0x1499d5df1d60035, negotiated timeout = 90000
113 2014-11-11 14:09:02,721 INFO  zookeeper.ZooKeeper (ZooKeeper.java:close(684)) - Session: 0x1499d5df1d60035 closed
114 2014-11-11 14:09:02,722 INFO  zookeeper.ClientCnxn (ClientCnxn.java:run(509)) - EventThread shut down
115 2014-11-11 14:09:02,723 INFO  client.HBaseAdmin (HBaseAdmin.java:disableTable(963)) - Disabled users
116 2014-11-11 14:09:02,874 INFO  client.HBaseAdmin (HBaseAdmin.java:deleteTable(695)) - Deleted users
117 删除表成功

 


没报什么错误,只有一个没有找到hadoop本地库的警告


 关于新建表时的新API操作TableName.valueOf(tablename);我看了一下TableName的源码

 1 /**
 2    * @throws IllegalArgumentException if fullName equals old root or old meta. Some code
 3    *  depends on this.
 4    */
 5   public static TableName valueOf(String name) {
 6     for (TableName tn : tableCache) {
 7       if (name.equals(tn.getNameAsString())) {
 8         return tn;
 9       }
10     }
11 
12     int namespaceDelimIndex = name.indexOf(NAMESPACE_DELIM);
13     byte[] nameB = Bytes.toBytes(name);
14 
15     if (namespaceDelimIndex < 0) {
16       return createTableNameIfNecessary(
17           ByteBuffer.wrap(NamespaceDescriptor.DEFAULT_NAMESPACE_NAME),
18           ByteBuffer.wrap(nameB));
19     } else {
20       return createTableNameIfNecessary(
21           ByteBuffer.wrap(nameB, 0, namespaceDelimIndex),
22           ByteBuffer.wrap(nameB, namespaceDelimIndex + 1,
23               nameB.length - (namespaceDelimIndex + 1)));
24     }
25   }

valueOf是它的一个静态方法。注释我看不太懂,看代码可以看出多了两个判断,一个判断它是否已经在表缓存中了,一个是判断它的前缀问题,如果有就去掉。我不知道第二个具体有什么作用。


 

HBase-java api 基本操作

标签:des   style   blog   http   io   color   ar   os   使用   

原文地址:http://www.cnblogs.com/admln/p/HBase-Java-api-operate.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!