HBase 二次开发 java api和demo
长处代码简单,须要打包的内容少。
长处是。明白。无歧义。
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.TableName;
public class Main {
public static void main(String[] args) throws IOException{
Configuration hbase_conf = new Configuration();
hbase_conf.set("hbase.zookeeper.quorum", "brianxxxooo"); //brianxxxooo是A里的zookeeper机器的hostname
hbase_conf.set("hbase.zookeeper.property.clientPort","2181");
Configuration conf = HBaseConfiguration.create(hbase_conf);
String tablename="scores";
String[] familys = {"grade", "course"};
HBaseAdmin admin = new HBaseAdmin(conf);
if (admin.tableExists(tablename)){
System.out.println("table exist, return!");
return;
}
HTableDescriptor td = new HTableDescriptor(TableName.valueOf(tablename));
for(int i = 0; i < familys.length; i++){
td.addFamily(new HColumnDescriptor(familys[i]));
}
admin.createTable(td);
System.out.println("create table "+tablename+" ok.");
}
}
, 而不是0.94的api。
但HBaseAdmin在0.94的api是有的,在2.0.0里没有。很混乱。
预计这个局面还要持续一段时间。
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.*;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
public class Main {
public static void main(String[] args) throws IOException{
Configuration hbase_conf = new Configuration();
hbase_conf.set("hbase.zookeeper.quorum", "brianvxxxxooooo");
hbase_conf.set("hbase.zookeeper.property.clientPort","2181");
Configuration conf = HBaseConfiguration.create(hbase_conf);
String tablename="scores";
String[] familys = {"grade", "course"};
HBaseAdmin admin = new HBaseAdmin(conf);
if (admin.tableExists(tablename)){
System.out.println("table exist!");
}else{
HTableDescriptor td = new HTableDescriptor(TableName.valueOf(tablename));
for(int i = 0; i < familys.length; i++){
td.addFamily(new HColumnDescriptor(familys[i]));
}
admin.createTable(td);
System.out.println("create table "+tablename+" ok.");
}
HTable table = new HTable(conf, "scores");
Put put = new Put(Bytes.toBytes("row1"));
//create
put.add(Bytes.toBytes("grade"), Bytes.toBytes("g1"), Bytes.toBytes(781));
put.add(Bytes.toBytes("grade"), Bytes.toBytes("g2"), Bytes.toBytes("this is test"));
table.put(put);
//read
Get get = new Get(Bytes.toBytes("row1"));
get.addColumn(Bytes.toBytes("grade"), Bytes.toBytes("g1"));
Result result = table.get(get);
byte[] val = result.getValue(Bytes.toBytes("grade"), Bytes.toBytes("g1"));
System.out.println(Bytes.toInt(val));
}
}
HBase 二次开发 java api和demo的更多相关文章
- HBase学习(二) 基本命令 Java api
一.Hbase shell 1.Region信息观察 创建表指定命名空间 在创建表的时候可以选择创建到bigdata17这个namespace中,如何实现呢? 使用这种格式即可:'命名空间名称:表名' ...
- HBase二次开发之搭建HBase调试环境,如何远程debug HBase源代码
版本 HDP:3.0.1.0 HBase:2.0.0 一.前言 之前的文章也提到过,最近工作中需要对HBase进行二次开发(参照HBase的AES加密方法,为HBase增加SMS4数据加密类型).研究 ...
- Ubuntu下搭建Hbase单机版并实现Java API访问
工具:Ubuntu12.04 .Eclipse.Java.Hbase 1.在Ubuntu上安装Eclipse,可以在Ubuntu的软件中心直接安装,也可以通过命令安装,第一次安装失败了,又试了一次,开 ...
- HBase 增删改查Java API
1. 创建NameSpaceAndTable package com.HbaseTest.hdfs; import java.io.IOException; import org.apache.had ...
- ElasticSearch7.3学习(二十三)----RestHighLevelClient Java api实现match_all、ids、match、term、multi_match、bool、filter、sort等不同的搜索方式
1.数据准备 首先创建book索引 PUT /book/ { "settings": { "number_of_shards": 1, "number ...
- hadoop学习记录(二)HDFS java api
FSDateinputStream 对象 FileSystem对象中的open()方法返回的是FSDateInputStream对象,改类继承了java.io.DateInoutStream接口.支持 ...
- python开发初期及二次开发C api
1,python2 or python 区别, https://wiki.python.org/moin/Python2orPython3 python software foundation 2,p ...
- HBase里的官方Java API
见 https://hbase.apache.org/apidocs/index.html
- ElasticSearch排序Java api简单Demo
代码: String time1 = ConstValue.GetCurrentDate(); SortBuilder sortBuilder = SortBuilders.fieldSort(&qu ...
随机推荐
- [Eth]网络查看命令:route
最近在调试网络,出现问题,两个网口分别接外网内网,结果不同 http://www.cnblogs.com/peida/archive/2013/03/05/2943698.html
- [转]SOA接口的两种常用实现比较:SOAP vs REST
原文链接:http://blog.csdn.net/zhaohuabing/article/details/39643127 SOA架构用于异构系统的协作,因此需要一种跨操作系统.跨语言的通用的消息交 ...
- jquery1.7+里不能用checked获得checkbox的属性
jquery1.7+以后用.attr('checked')得到的,都是undefined. 结论就是.attr()不能用于普通对象,数组,窗口,文档.要重新获取改变的dom属性,需要用.prop()方 ...
- javascript -- 事件捕获,事件冒泡
使用js的时候,当给子元素和父元素定义了相同的事件,比如都定义了onclick事件,单击子元素时,父元素的onclick事件也会被触发.js里称这种事件连续发生的机制为事件冒泡或者事件捕获. 为什么会 ...
- PWA(Progressive Web App)入门系列:(一)PWA简单介绍
前言 PWA做为一门Google推出的WEB端的新技术,长处不言而喻.但眼下对于相关方面的知识不是非常丰富.这里我推出一下这方面的新手教程系列.提供PWA方面学习. 什么是PWA PWA全称Progr ...
- 学习:在Eclipse中用TODO标签管理任务(Task)。
1.Windows->Perferences->Java->Compile->Task Tags,我们就可以自定义任务标签,Eclipse中可以支持HIgh,Normal,Lo ...
- 用ssh和互信链接建立批量执行
main server: 192.168.100.101 sub sever1: 192.168.100.102 sub server2: 192.168.100.103 main server执行脚 ...
- thinkPHP 上传文件的中文乱码
最新版本~用了里面的上传文件类,发现在保存文件原本名称的时候当有中文名的时候保存文件会显示乱码,看了下源代码发现在Tp上传驱动那里有点问题. // if (!move_uploaded_file($f ...
- Java8:使用 Optional 处理 null
写过 Java 程序的同学,一般都遇到过 NullPointerException :) —— 为了不抛出这个异常,我们便会写如下的代码: User user = getUserById(id); i ...
- [Openwrt]wifi桥接设置
1/连接wifi,用扫描加入,新建一个ingerface client模式 2/新建wifi ,network选lan和自身新建的interface.此interface设置为bridge模式,连接 ...