HBase table Get Data 获取数据
来源:互联网 发布:加油卡办卡通知 编辑:程序博客网 时间:2024/06/01 19:49
HBase 版本: 1.2.1
package com.feng.hbase;import java.io.IOException;import org.apache.hadoop.conf.Configuration;import org.apache.hadoop.hbase.Cell;import org.apache.hadoop.hbase.HBaseConfiguration;import org.apache.hadoop.hbase.TableName;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.Result;import org.apache.hadoop.hbase.client.Table;import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;import org.apache.hadoop.hbase.filter.Filter;import org.apache.hadoop.hbase.filter.FilterList;import org.apache.hadoop.hbase.filter.SingleColumnValueFilter;import org.apache.hadoop.hbase.util.Bytes;public class GetData { public static void main(String[] args) { String talbeName = "test1"; String columnFamily = "cf"; String columnFamily2 = "cf2"; String attribute = "a"; String rowkey = "row1"; Connection connection = null; Table table = null; try { Configuration config = HBaseConfiguration.create(); config.set("hbase.zookeeper.quorum", "localhost"); connection = ConnectionFactory.createConnection(config); table = connection.getTable(TableName.valueOf(talbeName)); if (table != null) { System.out.println("========第一种========"); // 第一种利用 Get 获取值 Get get = new Get(Bytes.toBytes(rowkey)); get.setMaxVersions(1);// will return last 4 versions of row Result result = table.get(get); if (!result.isEmpty()) { // 根据 columnFamily 和 attribute 取value值 byte[] value = result.getValue(Bytes.toBytes(columnFamily), Bytes.toBytes(attribute)); String valueStr = Bytes.toString(value); System.out.println(rowkey + " GET value : " + valueStr); // 用cell取的值 不太好用 Cell cell = result.getColumnLatestCell( Bytes.toBytes(columnFamily), Bytes.toBytes(attribute)); System.out.println("cell.getFamilyLength(): " + cell.getFamilyLength()); System.out.println("cell.getValueArray(): " + Bytes.toString(cell.getValueArray())); System.out.println("cell.getQualifierArray(): " + Bytes.toString(cell.getQualifierArray())); } else { System.out.println(rowkey + " is null rowkey!"); } System.out.println("========第二种========"); // 第二种利用 Get 获取值加过滤器获取值 好像是filter 没什么用 get = new Get(Bytes.toBytes(rowkey)); get.setMaxVersions(2); FilterList listFilter = new FilterList( FilterList.Operator.MUST_PASS_ONE); Filter filter = new SingleColumnValueFilter( Bytes.toBytes(columnFamily), Bytes.toBytes(attribute), CompareOp.EQUAL, Bytes.toBytes("")); listFilter.addFilter(filter); get.setFilter(listFilter); result = table.get(get); if (!result.isEmpty()) { // 根据 columnFamily 和 attribute 取value值 byte[] value = result.getValue(Bytes.toBytes(columnFamily), Bytes.toBytes(attribute)); String valueStr = Bytes.toString(value); System.out.println(rowkey + " GET value : " + valueStr); } else { System.out.println(rowkey + " is null rowkey!"); } } else { System.out.println("There is not " + talbeName); } } catch (Exception e) { e.printStackTrace(); } finally { if (table != null) { try { table.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { try { connection.close(); } catch (IOException e) { e.printStackTrace(); } } } }}
0 0
- HBase table Get Data 获取数据
- HBase table SCan Data 获取数据
- java客户端通过get方法获取Hbase的数据
- HBase table Put 插入数据
- Hbase coprocessor获取数据
- easyui 获取数据表格中选中行的数据 Get selected row data from...
- easyui 获取数据表格中选中行的数据 Get selected row data from...
- X5 获取前台所有data数据 和后台的 table 使用
- js获取GET数据
- get方式数据获取
- ajax post data 获取不到数据,注意 content-type的设置 、post/get
- ajax post data 获取不到数据,注意content-type的设置post/get
- ajax post data 获取不到数据,注意content-type的设置post/get
- Hbase之遍历获取数据
- 表数据网关(Table Data Gateway)
- 将Excel数据导入QTP Data Table
- 12. 表数据入口(Table Data Gateway)
- Get data from an Excel file without importing the data to the data table
- Shell字符串
- JSP自定义标签开发入门
- spring mvc 条件查询导出excel
- Git搭建
- mysql乐观锁总结和实践
- HBase table Get Data 获取数据
- Java获取本机公网ip
- LeetCode 347. Top K Frequent Elements
- WTL 通过IWebBrowser2接口使WebBrowser控件在自己的窗口打开网页
- JSON 入门指南
- 通过路径获取视频 缩略图
- vim编辑器的使用
- linux下创建多线程执行
- iphone——日期处理