表格存储服务 CloudTable-使用Scan读取数据:代码样例

时间:2023-11-01 16:16:51

代码样例

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();    scan.addColumn(Bytes.toBytes("info"), Bytes.toBytes("name"));    // 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.");}     
support.huaweicloud.com/devg-cloudtable/cloudtable_01_0059.html