forked from larsgeorge/hbase-book
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
84a54ce
commit 7ccb5bd
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package client; | ||
|
||
// cc ScanSlicingExample Example using offset and limit parameters for scans | ||
import java.io.IOException; | ||
|
||
import org.apache.hadoop.conf.Configuration; | ||
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 util.HBaseHelper; | ||
|
||
public class ScanSlicingExample { | ||
|
||
private static Table table = null; | ||
|
||
// vv ScanSlicingExample | ||
private static void scan(int num, int caching, int batch, int offset, | ||
int maxResults, int maxResultSize) throws IOException { | ||
int count = 1; | ||
Scan scan = new Scan() | ||
.setCaching(caching) | ||
.setBatch(batch) | ||
.setRowOffsetPerColumnFamily(offset) | ||
.setMaxResultsPerColumnFamily(maxResults) | ||
.setMaxResultSize(maxResultSize); | ||
ResultScanner scanner = table.getScanner(scan); | ||
System.out.println("Scan #" + num + " running..."); | ||
for (Result result : scanner) { | ||
System.out.println("Result [" + count++ + "]:" + result); | ||
} | ||
scanner.close(); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
// ^^ ScanSlicingExample | ||
Configuration conf = HBaseConfiguration.create(); | ||
|
||
HBaseHelper helper = HBaseHelper.getHelper(conf); | ||
helper.dropTable("testtable"); | ||
helper.createTable("testtable", "colfam1", "colfam2"); | ||
helper.fillTable("testtable", 1, 10, 10, 2, true, "colfam1", "colfam2"); | ||
|
||
Connection connection = ConnectionFactory.createConnection(conf); | ||
table = connection.getTable(TableName.valueOf("testtable")); | ||
|
||
// vv ScanSlicingExample | ||
/*...*/ | ||
scan(1, 100, 0, 0, 2, -1); | ||
scan(2, 100, 0, 4, 2, -1); | ||
scan(3, 100, 2, 0, 5, -1); | ||
scan(4, 1, 0, 0, -1, 50); | ||
/*...*/ | ||
// ^^ ScanSlicingExample | ||
table.close(); | ||
connection.close(); | ||
helper.close(); | ||
// vv ScanSlicingExample | ||
} | ||
// ^^ ScanSlicingExample | ||
} |