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列表索引,以下为翻译正文: 为了开发一个基于以太坊的 ...
随机推荐
- Hibernate的应用
//首先获得SessionFactory的对象 SessionFactory sessionFactory = new Configuration().configure().buildSession ...
- 解决org.hibernate.exception.SQLGrammarException:could not insert
今天在使用hibernate搭建项目时碰到了这个错误,找了好半天没能发现错误的原因, 上网求助了一下 发现出现这个bug的原因是因为数据表使用了数据库的关键字(保留字) 然后检查了一下,发现字段名称都 ...
- 缓存MEMCACHE php调用(一)
在项目中,涉及大访问量时,合理的使用缓存能减轻数据库的压力,同时提升用户体验.即在非实时性的需求的前提下,一小段时间内(若干秒),用于显示的数据从缓存中获取的,而不用直接读取数据库,能有效的减少数据库 ...
- canvas-8searchLight3.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 用webpack2.0构建vue2.0超详细精简版
初始化环境 npm init -y 初始化项目 安装各种依赖项 npm install --save vue 安装vue2.0 npm install --save-dev webpack@^2.1. ...
- 极简】如何在服务器上安装SSL证书?
本文适合任何人了解,图形化操作.下面以腾讯云为例,并且服务器(linux)也安装了宝塔面板. 1.登陆腾讯云账号进入控制台,找到SSL的产品 2.按要求申请并填写表单,记住私钥密码 3.提交后,待腾讯 ...
- Linux应用和系统库的2种安装方式---源码安装tarball和二进制rpm包
一.应用程序和系统库从哪里来? 两种机制,源码安装和二进制安装. 二.源码安装 tarball 1.核心思想是:利用开源代码,自己编译生成应用程序或者库,要求系统上必须已安装TMG(tar, make ...
- Android的ToolBar
ToolBar比ActionBar更加可控,自由.因此,Google 逐渐使用ToolBar来代替ActionBar. 使用ToolBar 1.要引入appCompat_v7支持 2.主题设置为NoA ...
- 添加/删除/修改Windows 7右键的“打开方式”
右键菜单添加/删除"打开方式" 此"打开方式"非系统的"打开方式",二者可以并存. 右键菜单添加"打开方式" 在HKEY ...
- 将html前端代码提取公因数(5)
将html前端代码提取公因数(5) 注意:这是优化html代码,对于多个html代码相同的部分提取到一个模板中,只需要编写变化的html 1,利用Django提供的render方法的第三个参数的属性 ...