hbase scan 操作
直接上代码了
啥也没讲
方法一 直接hbase shell -> scan '表名'
方法二:Java api
package hbasetest;
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.util.Bytes;
public class scan {
public static void main(String[] args) throws IOException{
conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "hadoop01,hadoop02,hadoop03");
conf.set("hbase.zookeeper.property.clientPort", "2181");
try {
conn = ConnectionFactory.createConnection(conf);
} catch (IOException e) {
e.printStackTrace();
}
Table table = conn.getTable(TableName.valueOf("stu"));
Scan scan = new Scan();
ResultScanner rsacn = table.getScanner(scan);
for(Result rs:rsacn) {
String rowkey = Bytes.toString(rs.getRow());
System.out.println("row key :"+rowkey);
Cell[] cells = rs.rawCells();
for(Cell cell : cells) {
System.out.println(Bytes.toString(cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength())+"::"+
Bytes.toString(cell.getValueArray(), cell.getValueOffset(), cell.getValueLength()));
}
System.out.println("-----------------------------------------");
}
}
static Configuration conf = null;
static Connection conn = null;
}