表格存储服务 CloudTable
表格存储服务 CloudTable
- 最新动态
- 产品介绍
- 计费说明
- 快速入门
-
用户指南
- HBase用户指南
- Doris用户指南
- ClickHouse用户指南
- 权限管理
- 审计日志
- 集群日志管理
- 最佳实践
- 开发指南
- API参考
- SDK参考
-
常见问题
-
通用类
- CloudTable集群能够提供什么服务?
- 为什么要选择CloudTable服务?
- 创建CloudTable HBase集群要准备什么?
- 使用CloudTable服务时需要关注什么?
- CloudTable HBase集群支持哪些压缩算法?
- 能停止CloudTable服务吗?
- CloudTable中的HBase外部接口支持哪些编程语言?
- 故障RegionServer个数怎么判断?
- CloudTable HBase支持的特殊符号?
- CloudTable数据进行删除,导致索引表和数据表不对应查询异常处理办法?
- python通过thrift访问cloudtable,多个任务并行缓慢
- 如何查看HBase shell的TTL属性?
- 服务器资源为什么会被释放?
- 资源停止服务或逾期释放说明
- 哪些场景会影响数据均衡?
- 如何调整数据均衡的灵敏度,调整后有哪些影响?
- Doris集群回收站数据处理
- 连接访问类
- 数据读写类
- 数据导入
- 网络配置
- 计费类
-
通用类
- 文档下载
- 通用参考
链接复制成功!
使用Scan读取数据
功能介绍
要从表中读取数据,首先需要实例化该表对应的Table实例,然后创建一个Scan对象,并针对查询条件设置Scan对象的参数值,为了提高查询效率,最好指定StartRow和StopRow。查询结果的多行数据保存在ResultScanner对象中,每行数据以Result对象形式存储,Result中存储了多个Cell。
代码样例
- 不指定HOT_ONLY参数来查询数据。在这种情况下,将会查询冷存储中的数据。
public void testScanData() { LOG.info("Entering testScanData."); Table table = null; // Instantiate a ResultScanner object. ResultScanner rScanner = null; try { // Create the Configuration instance. table = conn.getTable(tableName); // Instantiate a Get object. Scan scan = new Scan(); byte[] startRow = Bytes.toBytes(Shenzhen#Longgang#2017/7/1 00:00:00); byte[] stopRow = Bytes.toBytes(Shenzhen#Longgang#2017/7/3 00:00:00); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addColumn(Bytes.toBytes("info"), Bytes.toBytes("temp")); // Set the cache size. scan.setCaching(1000); // Submit a scan request. rScanner = table.getScanner(scan); // Print query results. for (Result r = rScanner.next(); r != null; r = rScanner.next()) { for (Cell cell : r.rawCells()) { LOG.info(Bytes.toString(CellUtil.cloneRow(cell)) + ":" + Bytes.toString(CellUtil.cloneFamily(cell)) + "," + Bytes.toString(CellUtil.cloneQualifier(cell)) + "," + Bytes.toString(CellUtil.cloneValue(cell))); } } LOG.info("Scan data successfully."); } catch (IOException e) { LOG.error("Scan data failed " ,e); } finally { if (rScanner != null) { // Close the scanner object. rScanner.close(); } if (table != null) { try { // Close the HTable object. table.close(); } catch (IOException e) { LOG.error("Close table failed " ,e); } } } LOG.info("Exiting testScanData."); }
- 通过指定HOT_ONLY参数来查询数据。在这种情况下,只会查询热存储中的数据。
public void testScanData() { LOG.info("Entering testScanData."); Table table = null; // Instantiate a ResultScanner object. ResultScanner rScanner = null; try { // Create the Configuration instance. table = conn.getTable(tableName); // Instantiate a Get object. Scan scan = new Scan(); byte[] startRow = Bytes.toBytes(Shenzhen#Longgang#2017/7/1 00:00:00); byte[] stopRow = Bytes.toBytes(Shenzhen#Longgang#2017/7/3 00:00:00); scan.setStartRow(startRow); scan.setStopRow(stopRow); scan.addColumn(Bytes.toBytes("info"), Bytes.toBytes("temp")); // Set HOT_ONLY. scan.setAttribute(HBaseConstants.HOT_ONLY, Bytes.toBytes(true)); // Set the cache size. scan.setCaching(1000); // Submit a scan request. rScanner = table.getScanner(scan); // Print query results. for (Result r = rScanner.next(); r != null; r = rScanner.next()) { for (Cell cell : r.rawCells()) { LOG.info(Bytes.toString(CellUtil.cloneRow(cell)) + ":" + Bytes.toString(CellUtil.cloneFamily(cell)) + "," + Bytes.toString(CellUtil.cloneQualifier(cell)) + "," + Bytes.toString(CellUtil.cloneValue(cell))); } } LOG.info("Scan data successfully."); } catch (IOException e) { LOG.error("Scan data failed " ,e); } finally { if (rScanner != null) { // Close the scanner object. rScanner.close(); } if (table != null) { try { // Close the HTable object. table.close(); } catch (IOException e) { LOG.error("Close table failed " ,e); } } } LOG.info("Exiting testScanData."); }
父主题: 样例代码说明