6.9 获取某一行指定列的数据


/**
 * 获取到指定行指定的列数据
 *
 * @param tableName
 * @param row
 * @param cf
 * @param c
 */
private static void getDataByColumn(String tableName, String row, String cf, String c) throws IOException {
    Table table = conn.getTable(TableName.valueOf(tableName));
    Get get = new Get(Bytes.toBytes(row));

    get.addColumn(Bytes.toBytes(cf), Bytes.toBytes(c));
    Result result = table.get(get);
    List<Cell> cells = result.listCells();
    for (Cell cell : cells) {
        String family = Bytes.toString(CellUtil.cloneFamily(cell));
        String value = Bytes.toString(CellUtil.cloneValue(cell));
        String rowName = Bytes.toString(CellUtil.cloneRow(cell));
        String column = Bytes.toString(CellUtil.cloneQualifier(cell));
        System.out.println("column = " + column);
        System.out.println("rowName = " + rowName);
        System.out.println("value = " + value);
        System.out.println("family = " + family);
    }
}
Copyright © 尚硅谷大数据 2019 all right reserved,powered by Gitbook
该文件最后修订时间: 2019-03-26 08:52:09

results matching ""

    No results matching ""