当前位置: 首页 > news >正文

做猎头要用的网站知乎济南头条今日新闻

做猎头要用的网站知乎,济南头条今日新闻,营销型网站建设比较好,建筑网站上海Table接口:负责表数据的基本操作。 Admin类:负责管理建表、删表、该表等元数据操作的接口。 1、Put方法 1.1、了解put方法之前,必须知道的相关知识。 在HBase中有一个理念:所有的数据皆为bytes。因此在HBase中所有的数据最终都…

        Table接口:负责表数据的基本操作。

       Admin类:负责管理建表、删表、该表等元数据操作的接口。

1、Put方法

1.1、了解put方法之前,必须知道的相关知识。

  1. 在HBase中有一个理念:所有的数据皆为bytes。因此在HBase中所有的数据最终都会被序列化为bytes[ ]保存。
  2. 最简单的将字符串转化为bytes[ ]的方法为:Bytes.toBytes()。

1.2、Put方法的构造函数

        Put(bytes[ ]  row)

        Put(ByteBuffer  row)

        Put(Put  putToCopy)

        Put(bytes[ ]  row , long  ts) 等等;

1.3、addColumn方法常用到调用方式

        addColumn(byte[ ]  family , byte[ ]  qualifier , byte[ ]  value)

        addColumn(byte[ ]  family , byte[ ]  qualifier , long  ts , byte[ ]  value)

        addColumn(byte[ ]  family , ByteBuffer  qualifier , long  ts , ByteBuffer  value)

        注:Put提供了一个语法糖,每一个addColumn返回的都是Put对象自己,因此可以把所有的列添加方法连接起来写。

以下为测试代码:

public static void main(String[] args) throws IOException {//1.实例化配置文件对象Configuration configuration = HBaseConfiguration.create();//2.设置连接接的数据库的IP地址configuration.set("hbase.zookeeper.quorum","master");//3.创建连接对象Connection connection = ConnectionFactory.createConnection(configuration);//4.创建Table接口对象Table table = connection.getTable(TableName.valueOf("user"));//实例化Put对象Put put = new Put(Bytes.toBytes("row1"));//5.准备新增的数据put.addColumn(Bytes.toBytes("info"),Bytes.toBytes("name"),666,Bytes.toBytes("jack")).addColumn(Bytes.toBytes("info"),Bytes.toBytes("age"),Bytes.toBytes("23")).addColumn(Bytes.toBytes("info"),Bytes.toBytes("address"),Bytes.toBytes("河南开封"));//6.执行新增操作table.put(put);//7.控制台打印运行完毕标识语句System.out.println("新增数据执行完毕~");
}

1.4Put对象中其他方法

            append方法 用于追加字符;increment方法  用于数值增加或增减(前提:该数据为long格式的)

2、Get方法

2.1、Get的构造函数

Get  get = new Get(byte[ ]  row)

2.2、Get对象相关方法

        为了提高查询效率。

        addFamily(byte[ ]  family) 添加要取出来的列族

        addColumn(byte[ ]  family , byte[ ]  qualifier)添加要取出来的列族和列

        setTimeRange(long minStramp , long maxStramp)设置要取出的版本范围

      setMaxVersions()设置要取出的版本数,默认为1,不传入参数直接调用就是把MaxVersions设置为Integer.MAV_VEALUE。

2.3、Result类

        byte value()把查询结果的第1列提取出来的快捷写法,用于你只查了一个列的情况。

        boolean isEmpty()查询结果是否为空,可以用来判断是否查询到数据。

        Int size()返回查找到的列数量,也可以提供size是否大于0判断是否查询到数据

        以下为测试代码案例:

public static void main(String[] args) throws IOException {Configuration configuration = HBaseConfiguration.create();configuration.set("hbase.zookeeper.quorum","master");Connection connection = ConnectionFactory.createConnection(configuration);Table table = connection.getTable(TableName.valueOf("user"));Get get = new Get(Bytes.toBytes ("row1"));Result result = table.get(get);System.out.println(Bytes.toString(result.value()));System.out.println("判断查询结果是否为空:"+result.isEmpty());System.out.println("查找到的列数为:"+result.size());System.exit(-1);
}

3、exists方法

Table接口提供的exists方法用来快速查询某一个数据是否存在的。

4、delet方法

4.1、Delete对象构造器

        Delete delete = new Delete(byte[ ]  row);

4.2、Delete对象相关方法

        addFamily(byte[ ] family) 删除指定列族

        addFamily(byte[ ] family , long timestamp) 删除指定列族中所以版本号等于或小于给定的版本号的列

        addColumn(byte[ ] family , byte[ ] qualifiler) 删除指定列的最新版本

        addColumn(byte[ ] family , byte[ ] qualifiler , long timestamp) 删除指定列的特定版本

        addColumns(byte[ ] family , byte[ ] qualifiler) 删除指定列的所有版本

        addColumns(byte[ ] family , byte[ ] qualifiler , long timestamp) 删除指定列的等于或小于给定版本号的所有版本。

5、checkAndDelete方法

Table接口提供的,保证在一个原子操作内对数据完成修改和删除操作。

6、mutation方法

Table接口提供的,保证在任意两个操作放在他同一个原子操作内。

RowMutations类 用于整合相关操作 作为mutateRow方法的参数。

代码演示如下:

public static void main(String[] args) throws IOException {Configuration configuration = HBaseConfiguration.create();configuration.set("hbase.zookeeper.quorum","192.168.28.130");Connection connection = ConnectionFactory.createConnection(configuration);Table table = connection.getTable(TableName.valueOf("user"));//1.删除  行:row3 列: ageDelete delete = new Delete(Bytes.toBytes("row3"));delete.addColumn(Bytes.toBytes("info"),Bytes.toBytes("age"));//2.修改  name值为chrisPut put1 = new Put(Bytes.toBytes("row3"));put1.addColumn(Bytes.toBytes("info"),Bytes.toBytes("name"),Bytes.toBytes("chris"));//3.新增  info:job值为engineerPut put2 = new Put(Bytes.toBytes("row3"));put2.addColumn(Bytes.toBytes("info"),Bytes.toBytes("job"),Bytes.toBytes("engineer"));//新建RowMutations类  并且把以上操作对象添加进去RowMutations rowMutations = new RowMutations(Bytes.toBytes("row3"));rowMutations.add(delete);rowMutations.add(put1);rowMutations.add(put2);//执行删除/修改/新增操作table.mutateRow(rowMutations);System.out.println("执行完毕~");
}

7.批量操作  

        bath方法

public static void main(String[] args) throws IOException, InterruptedException {Configuration configuration = HBaseConfiguration.create();configuration.set("hbase.zookeeper.quorum","master");Connection connection = ConnectionFactory.createConnection(configuration);Table table = connection.getTable(TableName.valueOf("user"));//1.查询行row2数据Get get = new Get(Bytes.toBytes("row2"));//2.新增数据  row4 info:age  23Put put = new Put(Bytes.toBytes("row4"));put.addColumn(Bytes.toBytes("info"),Bytes.toBytes("age"),Bytes.toBytes(23));//3.删除行row1数据Delete delete = new Delete(Bytes.toBytes("row1"));//4.批量执行操作ArrayList<Row> list = new ArrayList<Row>();list.add(get);list.add(put);list.add(delete);Object[] results = new Object[list.size()];table.batch(list,results);byte[] value = ((Result) results[0]).getValue(Bytes.toBytes("info"), Bytes.toBytes("name"));System.out.println(Bytes.toString(value));
}

8、Scan扫描

public static void main(String[] args) throws IOException {Configuration configuration = HBaseConfiguration.create();configuration.set("hbase.zookeeper.quorum","master");Connection connection = ConnectionFactory.createConnection(configuration);Table table = connection.getTable(TableName.valueOf("user"));Scan scan = new Scan(Bytes.toBytes("row2"));ResultScanner results = table.getScanner(scan);Result result = results.next();byte[] value = result.getValue(Bytes.toBytes("info"), Bytes.toBytes("name"));System.out.println(Bytes.toString(value));
}

http://www.yidumall.com/news/32766.html

相关文章:

  • 在线做带字头像的网站网络快速排名优化方法
  • 点对点视频网站开发合肥网站优化排名推广
  • 17一起做网站客服seo是哪个英文的简写
  • 做网站的公司需要哪些资质万能搜索 引擎
  • 网上购物网站2024的新闻有哪些
  • html免费代码网站在线培训系统
  • 重庆做企业网站自己做的网站怎么推广
  • 做全景图有哪些网站百度收录入口在哪里
  • 在制作网站前 不需要急于做的工作是商品关键词优化的方法
  • 南京网站设计是什么电脑编程培训学校哪家好
  • 网站开发技术网站百度知道提问
  • 自己电脑做网站服务器设置百度搜索最多的关键词
  • 男生为女生做网站制作网页的步骤
  • 哪个学校设有网站开发专业2023年国家免费技能培训
  • 网页制作与网站建设 自考百度贴吧官网首页
  • 珠海做网站专业公司网络推广有哪些方法
  • 国外html 网站网站怎样优化关键词好
  • 公司网站建设需要些什么要求超级seo助手
  • 建设网站的视频长沙本地推广
  • 用织梦做的手机网站怎么才能和电脑同步合肥做网站公司哪家好
  • 有创意做网站找投资销售管理怎么带团队
  • 免费网站个人注册看b站视频软件下载安装
  • 网站建设公司新报价色盲测试卡
  • 视频做网站背景山西优化公司
  • 宁波seo行业公司推荐seo推广专员工作好做吗
  • 旅游推荐网站怎么做最近七天的新闻大事
  • 做美食推广的网站有哪些东莞疫情最新通告
  • 营销型 网站 品牌直通车推广怎么收费
  • 移动网站好处百度下载安装官方下载
  • 大连仟亿科技网站建设公司 概况域名查询 站长查询