HBase1.0.1.1 API与原来有所不同
package com.felix.hbaseapi_test; /*
这是旧版的 API操作
*/
public class hbaseapifelix { public static final String TABLE_NAME = "testapi";
public static final String COLUMNFAMILY_NAME = "cf";
public static final String ROW_KEY = "rowkey1"; public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
HBaseAdmin admin=new HBaseAdmin(conf);
createtable(admin);
HTable htable=new HTable(conf, TABLE_NAME); put(htable,"age","25");
put(htable,"age","26");
put(htable,"age","27");
put(htable,"age","28"); //Get
Get get=new Get(ROW_KEY.getBytes());
htable.get(get); //scan
Scan scan=new Scan();
ResultScanner scanner = htable.getScanner(scan);
} private static void put(HTable htable,String column,String value) throws IOException {
Put put=new Put(ROW_KEY.getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), column.getBytes(), value.getBytes());
htable.put(put);
} private static void createtable(HBaseAdmin admin) throws IOException {
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor family = new HColumnDescriptor(COLUMNFAMILY_NAME);
desc.addFamily(family);
family.setMaxVersions(3);
if (!admin.tableExists(TABLE_NAME)) {
//该表不存在,直接创建
admin.createTable(desc);
}else{
//该表存在,删除后再创建
if(!admin.isTableAvailable(TABLE_NAME)){
//该表disable,直接删除
admin.deleteTable(TABLE_NAME);
}else{
//该表enable,先disable,再删除
admin.disableTable(TABLE_NAME);
admin.deleteTable(TABLE_NAME);
}
admin.createTable(desc);
}
} }
package com.felix.hbaseapi_test; 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.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Get;
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.client.Table; public class hbaseapifelix { public static final String TABLE_NAME = "testapi";
public static final String COLUMNFAMILY_NAME = "cf";
public static final String ROW_KEY = "rowkey1"; public static void main(String[] args) throws Exception {
Configuration conf = HBaseConfiguration.create();
//下面的配置,在configuration文件中都配置过了这里没必要配置,也不方便
//conf.set("hbase.rootdir", "hdfs://centos:9000/hbase");
//conf.set("hbase.zookeeper.quorum","centos");
//conf.set("hbase.zookeeper.property.clientPort", "2181"); Connection connection = ConnectionFactory.createConnection(conf);
Admin admin = connection.getAdmin();
Table table = connection.getTable(TableName.valueOf("user"));
TableName name = table.getName(); initBeforeCreate(admin, name);
createTable(admin, table); try {
Put put=new Put("rowkey".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "25".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "26".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "27".getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), "age".getBytes(), "28".getBytes());
table.put(put);
} finally {
table.close();
connection.close();
} Get get = new Get(ROW_KEY.getBytes());
Result result = table.get(get); Scan scan=new Scan();
ResultScanner scanner = table.getScanner(scan); /* HBaseAdmin admin=new HBaseAdmin(conf);
createtable(admin); HTable htable=new HTable(conf, TABLE_NAME); put(htable,"age","25");
put(htable,"age","26");
put(htable,"age","27");
put(htable,"age","28"); //Get
Get get=new Get(ROW_KEY.getBytes());
htable.get(get); //scan
Scan scan=new Scan();
ResultScanner scanner = htable.getScanner(scan);*/
} private static void initBeforeCreate(Admin admin, TableName name)
throws IOException {
/*创建前存在就删除
* */
if(admin.tableExists(name)){
if(admin.isTableEnabled(name)){
admin.disableTable(name);
}
admin.deleteTable(name);
}
} private static void createTable(Admin admin, Table table)
throws IOException {
HTableDescriptor desc=new HTableDescriptor(table.getName());
HColumnDescriptor family=new HColumnDescriptor(COLUMNFAMILY_NAME);
family.setMaxVersions(3);
family.setMinVersions(0);
desc.addFamily(family);
admin.createTable(desc);
} /*private static void put(HTable htable,String column,String value) throws IOException {
Put put=new Put(ROW_KEY.getBytes());
put.addColumn(COLUMNFAMILY_NAME.getBytes(), column.getBytes(), value.getBytes());
htable.put(put);
} private static void createtable(HBaseAdmin admin) throws IOException {
HTableDescriptor desc = new HTableDescriptor(TABLE_NAME);
HColumnDescriptor family = new HColumnDescriptor(COLUMNFAMILY_NAME);
desc.addFamily(family);
family.setMaxVersions(3);
if (!admin.tableExists(TABLE_NAME)) {
//该表不存在,直接创建
admin.createTable(desc);
}else{
//该表存在,删除后再创建
if(!admin.isTableAvailable(TABLE_NAME)){
//该表disable,直接删除
admin.deleteTable(TABLE_NAME);
}else{
//该表enable,先disable,再删除
admin.disableTable(TABLE_NAME);
admin.deleteTable(TABLE_NAME);
}
admin.createTable(desc);
}
}*/ }
具体改成什么了,以及为什么修改,源码里面说的很清楚,比如:
HBaseAdmin is no longer a client API. It is marked InterfaceAudience.Private indicating that
* this is an HBase-internal class as defined in
* https://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/InterfaceClassification.html
* There are no guarantees for backwards source / binary compatibility and methods or class can
* change or go away without deprecation.
* Use {@link Connection#getAdmin()} to obtain an instance of {@link Admin} instead of constructing
* an HBaseAdmin directly.
其他的自己关联源码自己看吧!
HBase1.0.1.1 API与原来有所不同的更多相关文章
- Hbase1.0 客户端api
最近在试用Hbase1.0的客户端API,发觉变化还是挺大(以前版本也不熟).到处都是deprecated. 现在应该是这样子: Configuration conf = HBaseConfigur ...
- HBase1.0以上版本的API改变
HBase1.0以上版本已经废弃了 HTableInterface,HTable,HBaseAdmin等API的使用,新增了一些API来实现之前的功能: Connectioninterface: Co ...
- HBase1.0以上版本号的API改变
HBase1.0以上版本号已经废弃了 HTableInterface,HTable,HBaseAdmin等API的使用.新增了一些API来实现之前的功能: Connectioninterface: C ...
- ElasticSearch 5.0.1 java API操作
今天来说下使用ES 5.0.1的API来进行编码. 开始之前,简单说下5.0.1跟之前的几个变化.之前的ES自身是不支持delete-by-query的,也就是通过查询来删除,可以达到批量的效果,是因 ...
- hadoop: hbase1.0.1.1 伪分布安装
环境:hadoop 2.6.0 + hbase 1.0.1.1 + mac OS X yosemite 10.10.3 安装步骤: 一.下载解压 到官网 http://hbase.apache.org ...
- 使用OAuth2.0访问豆瓣API
如何计算某个用户的access_token过期时间?开发者可以通过两种方式计算:用户授权时,oauth2/access_token接口返回的expires_in值就是access_token的生命周期 ...
- Android 8.0 功能和 API
Android 8.0 为用户和开发者引入多种新功能.本文重点介绍面向开发者的新功能. 用户体验 通知 在 Android 8.0 中,我们已重新设计通知,以便为管理通知行为和设置提供更轻松和更统一的 ...
- laravel Passport - 创建 REST API 用户认证以及Dingo/Api v2.0+Passport实现api认证
第一部分: 安装passport 使⽤ Composer 依赖包管理器安装 Passport : composer require laravel/passport 接下来,将 Passport 的服 ...
- Web3.js 0.20.x API 中文版翻译
文档原始链接为:https://web3.learnblockchain.cn/0.2x.x/,欢迎大家前往查阅,本文只是节选开头部分的介绍及API列表索引,以下为翻译正文: 为了开发一个基于以太坊的 ...
随机推荐
- 【转载】阿里云服务器为网站选配Https证书
数字证书是一个经权威授权机构数字签名.包含公开密钥拥有者信息以及公开密钥的文件,是权威机构颁发给网站的可信凭证.最简单的证书包含一个公开密钥.证书名称以及证书授权中心的数字签名,只在特定的时间内有效. ...
- .NET-ORM框架EF-Code First代码优先
前言 Code First顾名思义,通告代码创建实体与数据库.示例中我们会创建表,分表是Studen,Teacher. Code First实战示例 打开VS2013,创建一个项目我这里是用的MVC框 ...
- Redis常用命令与配置
常用命令 测试客户端与服务器是否正常连接:ping ( 补:返回pong表示成功 ) 正则获取键:keys pattern 判断一个键是否存在:exists key 删除一个键:del key 获 ...
- MySQL分页查询性能优化
当需要从数据库查询的表有上万条记录的时候,一次性查询所有结果会变得很慢,特别是随着数据量的增加特别明显,这时需要使用分页查询.对于数据库分页查询,也有很多种方法和优化的点.下面简单说一下我知道的一些方 ...
- C#开源框架(转载)
Json.NET http://json.codeplex.com/ Json.Net 是一个读写Json效率比较高的.Net框架.Json.Net 使得在.Net环境下使用Json更加简单.通过Li ...
- Git合并指定文件到另一个分支
经常被问到如何从一个分支合并特定的文件到另一个分支.其实,只合并你需要的那些commits,不需要的commits就不合并进去了. 合并某个分支上的单个commit 首先,用git log或sourc ...
- 积累一些不太常用的C/C++语言知识(不断更新)
这里积累一些日常编程用得比较少的知识,不断添加. scanf("%c%*c%c",&a,&b); 其中的*表示跳过,本来输入三个数字,结果中间那个读入后被抛弃,a和 ...
- session图片验证码,页面和请求是两个地址。android手机好用,iphone 失效。
问题描述:之前在H5页面用session做了一个验证码.安卓手机好使.但是到苹果就不好使了(页面访问是一个域名地址,ajax请求是用另外的一个ip地址). 详细说明: 验证码请求后台图片正常显示,an ...
- eclipse编写js代码没有提示
安装插件 点击Help,选择Eclipse Marketplace... 搜索js,安装AngularJS Eclipse 重启eclipse,右键项目,选择Configure(配置),选择Conve ...
- JS预解析机制
JS的预解析过程: 1,预解析 2,再逐行解读代码, 实例: ---------------------------- <script> var name="xm& ...