?HBase?,????????Scan????????????????,???????Scan??????????:
import org.apache.hadoop.hbase.HBaseConfiguration; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.*; import org.apache.hadoop.hbase.util.Bytes; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class HBaseBatchQueryWithPagination { public static void main(String[] args) throws IOException { // ??HBase???? Configuration conf = HBaseConfiguration.create(); // ?????? Connection connection = ConnectionFactory.createConnection(conf); // ????? TableName tableName = TableName.valueOf("your_table_name"); Table table = connection.getTable(tableName); // ?????? Scan scan = new Scan(); // ?????? int pageSize = 10; // ???????? int offset = 0; // ???,??????????? // ??????(??:??????????) scan.addFamily(Bytes.toBytes("cf1")); scan.addColumn(Bytes.toBytes("cf1"), Bytes.toBytes("column1")); // ?????? Listresults = new ArrayList<>(); // ????????? do { // ?????????(??) if (offset > 0) { byte[] startRow = Bytes.toBytes(String.format("d", offset)); scan.setStartRow(startRow); } // ?????? ResultScanner scanner = table.getScanner(scan); try { for (Result result : scanner) { results.add(result); } } finally { scanner.close(); } // ?????????? offset += pageSize; } while (results.size() == pageSize); // ?????? table.close(); connection.close(); // ?????? for (Result result : results) { System.out.println("Row: " + Bytes.toString(result.getRow())); // ????????... } } }
??????,?????????HBase?????????,????????????????,???????Scan??,????????(pageSize?offset)???????????,?????????????
??,????do-while??????????????????,???????????(??),??????,???????????????,????????????,????????????????
??????,?????????,?????????