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 ...
随机推荐
- udacity android 实践笔记: lesson 4 part b
udacity android 实践笔记: lesson 4 part b 作者:干货店打杂的 /titer1 /Archimedes 出处:https://code.csdn.net/titer1 ...
- JavaScript概述.pdf
第1章 JavaScript概述 第2章 使用JavaScript 第3章 语法.关键保留字及变量 第4章 数据类型 第5章 运算符 第6章 流程控制语句 第7章 函数 //没有参数的函数 funct ...
- java 错误汇总
一.怎么处理警告:编码 GBK 的不可映射字符 解决办法是:应该使用-encoding参数指明编码方式:javac -encoding UTF-8 XX.java,这下没警告了,运行也正确了在JCre ...
- EasyUI Window和Layout
我们建立tabs内容. <div class="easyui-window" title="Layout Window" icon="icon- ...
- ORDER BY 语句用于对结果集进行排序。
ORDER BY 语句 ORDER BY 语句用于根据指定的列对结果集进行排序. ORDER BY 语句默认按照升序对记录进行排序. 如果您希望按照降序对记录进行排序,可以使用 DESC 关键字.
- -pie can only be used when targeting iOS 4.2 or later
网上下载的demo,执行报错-pie can only be used when targeting iOS 4.2 or later 解决的方法:选择target==>改动developmen ...
- 第一个内核模块hello world
1.源码树的下载和编译(只是研究内核模块的话,应该不需要源码树的) 下载很简单,压缩包解压 编译:make menuconfig make bzImage -j4 参考 2. cd /usr/src ...
- 关东升的iOS实战系列图书 《iOS实战:入门与提高卷(Swift版)》已经上市
承蒙广大读者的厚爱我的 <iOS实战:入门与提高卷(Swift版)>京东上市了,欢迎广大读者提出宝贵意见.http://item.jd.com/11766718.html ...
- LAMP集群项目四 安装apache、php及其插件
rpm -qa httpd* 查看是否有apache rpm -e httpd-2.2.22.2 卸载该文件,如果不让卸载,则加参数:--nodeps 不做软件中的依赖检查 ./configure ...
- 深入理解ByteBuffer
ByteBuffer类是在Java NIO中常常使用的一个缓冲区类,使用它可以进行高效的IO操作,但是,如果对常用方法的理解有错误,那么就会出现意想不到的bug. ByteBuffer类的常用方法 先 ...