原生hbase调用

public void get() {

    String rowKey = SystemUtil.getRowKey(BizConstants.rLabel, BizConstants.sLabel, BizConstants.fLabel, BizConstants.fx);

    Object o = hbaseTemplate.get(BizConstants.HBASE_TABLE_NAME, rowKey, BizConstants.HBASE_FAMILY_NAME, new RowMapper<Object>() {
            @Override
            public Object mapRow(Result result, int i) throws Exception {

                String d = null;
                for (Cell cell : result.listCells()) {
                    String row = new String(CellUtil.cloneRow(cell));
                    String family = new String(CellUtil.cloneFamily(cell));
                    String column = new String(CellUtil.cloneQualifier(cell));
                    String value = new String(CellUtil.cloneValue(cell));
                    long timestamp = cell.getTimestamp();
                    d = value;
                    System.out.printf("%-20s column=%s:%s, timestamp=%s,value=%s\n", row, family, column, timestamp, value);
                }

                return d;
            }
        });

    System.out.println(o);
}

public void insert() {

    String rLabel = "sdf";
    String sLabel = "sdf";
    String fLabel = "L3CS426U-GD";
    String fx = "3";

    List<String> rows = new ArrayList<String>();
    rows.add(rLabel);
    rows.add(sLabel);
    rows.add(fLabel);
    rows.add(fx);

    String rowKey = StringUtils.join(rows,"_");

    for (int i = 0; i < 10; i++) {
        hbaseTemplate.put(BizConstants.HBASE_TABLE_NAME, rowKey, BizConstants.HBASE_FAMILY_NAME, BizConstants.HBASE_QUALIFIER_NAME,"0.6".getBytes());
    }
}

猜你喜欢

转载自www.cnblogs.com/yaoyao66123/p/12654196.html