
# 使用Get读取HBase冷热分离数据
#### 功能介绍
要从表中读取一条数据，首先需要实例化该表对应的Table实例，然后创建一个Get对象。也可以为Get对象设定参数值，如列族的名称和列的名称。查询到的行数据存储在Result对象中，Result中可以存储多个Cell。
针对开启冷热分离特性的列族，可以从冷热存储中查询数据，也可以只从热存储中查询数据。
#### 代码样例
- 不指定HOT_ONLY参数来查询数据。在这种情况下，将会查询冷存储中的数据。
  ```
  public void testGet() {
    LOG.info("Entering testGet.");
    // Specify the column family name.
    byte[] familyName = Bytes.toBytes("info");
    // Specify the column name.
    byte[][] qualifier = { Bytes.toBytes("temp"), Bytes.toBytes("hum") };
    // Specify RowKey.
    byte[] rowKey = Bytes.toBytes("Shenzhen#Longgang#2017/7/1 03:00:00");
    Table table = null;
    try {
      // Create the Table instance.
      table = conn.getTable(tableName);
      // Instantiate a Get object.
      Get get = new Get(rowKey);
      // Set the column family name and column name.
      get.addColumn(familyName, qualifier[0]);
      get.addColumn(familyName, qualifier[1]);
      // Submit a get request.
      Result result = table.get(get);
      // Print query results.
      for (Cell cell : result.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("Get data successfully.");
    } catch (IOException e) {
      LOG.error("Get data failed " ,e);
    } finally {
      if (table != null) {
        try {
          // Close the HTable object.
          table.close();
        } catch (IOException e) {
          LOG.error("Close table failed " ,e);
        }
      }
    }
    LOG.info("Exiting testGet.");
  }
  ```
  

- 通过指定HOT_ONLY参数来查询数据。在这种情况下，只会查询热存储中的数据。
  ```
  public void testGet() {
    LOG.info("Entering testGet.");
    // Specify the column family name.
    byte[] familyName = Bytes.toBytes("info");
    // Specify the column name.
    byte[][] qualifier = { Bytes.toBytes("temp"), Bytes.toBytes("hum") };
    // Specify RowKey.
    byte[] rowKey = Bytes.toBytes("Shenzhen#Longgang#2017/7/2 10:00:00");
    Table table = null;
    try {
      // Create the Table instance.
      table = conn.getTable(tableName);
      // Instantiate a Get object.
      Get get = new Get(rowKey);
      // Set HOT_ONLY.
      get.setAttribute(HBaseConstants.HOT_ONLY, Bytes.toBytes(true));
      // Set the column family name and column name.
      get.addColumn(familyName, qualifier[0]);
      get.addColumn(familyName, qualifier[1]);
      // Submit a get request.
      Result result = table.get(get);
      // Print query results.
      for (Cell cell : result.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("Get data successfully.");
    } catch (IOException e) {
      LOG.error("Get data failed " ,e);
    } finally {
      if (table != null) {
        try {
          // Close the HTable object.
          table.close();
        } catch (IOException e) {
          LOG.error("Close table failed " ,e);
        }
      }
    }
    LOG.info("Exiting testGet.");
  }
  ```
  
 
