HBase客户端程序
来源:互联网 发布:vb手机版 编辑:程序博客网 时间:2024/06/01 09:23
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.MasterNotRunningException;import org.apache.hadoop.hbase.ZooKeeperConnectionException;import org.apache.hadoop.hbase.client.Get;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.hbase.client.Result;import org.apache.hadoop.hbase.client.ResultScanner;import org.apache.hadoop.hbase.client.Scan;import org.apache.hadoop.hbase.util.Bytes;public class ExampleClient {/** * @param args * @throws IOException * @throws MasterNotRunningException */public static void main(String[] args) throws MasterNotRunningException, IOException {// TODO Auto-generated method stubConfiguration config = HBaseConfiguration.create();//Create tableHBaseAdmin admin = new HBaseAdmin(config);HTableDescriptor htd = new HTableDescriptor("test"); // 要创建的表的名称HColumnDescriptor hcd = new HColumnDescriptor("profile"); // 创建一个列族htd.addFamily(hcd);admin.createTable(htd);byte[] tablename = htd.getName(); // HBase Table DescriptorHTableDescriptor[] tables = admin.listTables();System.out.println(tables.length);if(tables.length != 1 && Bytes.equals(tablename, tables[0].getName()))throw new IOException("Failed create of table");HTable table = new HTable(config, tablename);byte[] row1 = Bytes.toBytes("88888888");Put p1 = new Put(row1); // Create a Put operation for the specified row.byte[] profile = Bytes.toBytes("profile");p1.add(profile, Bytes.toBytes("gender"), Bytes.toBytes("male"));table.put(p1); // 存储Get g1 = new Get(row1);Result result = table.get(g1);System.out.println("Get: " + result);Scan scan = new Scan();ResultScanner scanner = table.getScanner(scan);try{for(Result scannerResult : scanner){System.out.println("Scan: " + scannerResult);}}finally{scanner.close();}// admin.disableTable(tablename);// admin.deleteTable(tablename);}}
HTableDescriptor 包含了HTable的名字和它的所有列族。
HColumnDescriptor 包含了列族的一些信息,像是版本的数量,压缩设置等等。当创建一个表或者是增加一个列的时候,它被用作输入。一旦设定,为列制定的参数只能通过先删除列再重新创建来实现。如果这个列中存储了数据,删除列的同时也会删除数据。
HBaseAdmin提供了管理HBase数据库表元数据的借口,和通用的管理功能。使用它来创建、删除、列出、打开和关闭表。添加和删除列族也是使用它。
- HBase客户端程序
- Hbase客户端
- Hadoop学习笔记之HBase客户端程序开发
- HBase(使用kerberos)服务请求客户端程序
- HBase 客户端开发初探
- HBase Java客户端编程
- HBase JAVA WEB客户端
- HBase Java客户端编程
- Hbase java客户端操作
- HBase Java客户端编程
- Hbase 基础客户端API
- HBase Java客户端编程
- HBase Java客户端编程
- HBase 客户端读取实现
- HBase Java客户端编程
- hbase客户端安装操作
- HBase JAVA WEB客户端
- hbase 客户端HTablePool
- 不使用第三个变量,交换两个变量的值!
- 在Domino环境下开发WAP页面-1:第1个页面
- Ajax
- titanium mobile httpClient 在ios下的使用,后端应用服务器为nginx时注意事项
- IE/Firefox每次刷新时自动检查网页更新,无需手动清空缓存的设置方法
- HBase客户端程序
- 我的2011——一个通信设备商程序员的年度总结
- eclipse反编译工具安装
- Android UI之ImageView图片视图
- Hibernate懒加载解析
- UNICODE 基础知识
- Oracle group by 基本及的拓展 ROLLUP, CUBE, GROUPING 功能and GROUPING 集合
- ListBox的数据库绑定
- Gvim 字体大小设置