更新时间:2023-04-28 GMT+08:00
分享

写入数据

写入数据接口和HBase原生API一致。

样例代码

public void testPut() {
  LOG.info("Entering testPut.");
  try(Table table = conn.getTable(tableName)) {
    List<Put> puts = new ArrayList<>();
    Arrays.stream(SPLIT.split(LemonConstants.COMMA))
      .forEach(startkey -> {
        // Instantiate a Put object.
        Put put = new Put(Bytes.toBytes(startkey + "-rowkey001"));
        put.addColumn(FAM_M, QUA_M, Bytes.toBytes("bachelor"));
        put.addColumn(FAM_N, QUA_N, Bytes.toBytes("xiaowang"));
        puts.add(put);

        Put put1 = new Put(Bytes.toBytes(startkey + "-rowkey0012"));
        put1.addColumn(FAM_M, QUA_M, Bytes.toBytes("master"));
        put1.addColumn(FAM_N, QUA_N, Bytes.toBytes("xiaoming"));
        puts.add(put1);

        // Submit a put request.
        try {
          table.put(puts);
        } catch (IOException e) {
          LOG.info("put exception", e);
        }
      });
    LOG.info("Put successfully.");
  } catch (IOException e) {
    LOG.error("Put failed ", e);
  }
  LOG.info("Exiting testPut.");
}
分享:

    相关文档

    相关产品