下面列出了怎么用org.apache.hadoop.hbase.filter.ColumnPrefixFilter的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Returns a scanner for all namespace snapshot entries of the given namespace
* @param namespace name of the namespace whose snapshot entries are to be scanned
*/
static Scan createScanForNamespaceSnapshotSizes(String namespace) {
Scan s = new Scan();
if (namespace == null || namespace.isEmpty()) {
// Read all namespaces, just look at the row prefix
s.setRowPrefixFilter(QUOTA_NAMESPACE_ROW_KEY_PREFIX);
} else {
// Fetch the exact row for the table
byte[] rowkey = getNamespaceRowKey(namespace);
// Fetch just this one row
s.withStartRow(rowkey).withStopRow(rowkey, true);
}
// Just the usage family and only the snapshot size qualifiers
return s.addFamily(QUOTA_FAMILY_USAGE)
.setFilter(new ColumnPrefixFilter(QUOTA_SNAPSHOT_SIZE_QUALIFIER));
}
static Scan createScanForSpaceSnapshotSizes(TableName table) {
Scan s = new Scan();
if (null == table) {
// Read all tables, just look at the row prefix
s.setRowPrefixFilter(QUOTA_TABLE_ROW_KEY_PREFIX);
} else {
// Fetch the exact row for the table
byte[] rowkey = getTableRowKey(table);
// Fetch just this one row
s.withStartRow(rowkey).withStopRow(rowkey, true);
}
// Just the usage family and only the snapshot size qualifiers
return s.addFamily(QUOTA_FAMILY_USAGE).setFilter(
new ColumnPrefixFilter(QUOTA_SNAPSHOT_SIZE_QUALIFIER));
}
@Override
public Scan operationScan()
{
Scan scan = new Scan();
Filter f = new ColumnPrefixFilter(Bytes.toBytes("col-0"));
scan.setFilter(f);
return scan;
}
/**
* Test partial Result re-assembly in the presence of different filters. The Results from the
* partial scanner should match the Results returned from a scanner that receives all of the
* results in one RPC to the server. The partial scanner is tested with a variety of different
* result sizes (all of which are less than the size necessary to fetch an entire row)
* @throws Exception
*/
@Test
public void testPartialResultsWithColumnFilter() throws Exception {
testPartialResultsWithColumnFilter(new FirstKeyOnlyFilter());
testPartialResultsWithColumnFilter(new ColumnPrefixFilter(Bytes.toBytes("testQualifier5")));
testPartialResultsWithColumnFilter(new ColumnRangeFilter(Bytes.toBytes("testQualifer1"), true,
Bytes.toBytes("testQualifier7"), true));
Set<byte[]> qualifiers = new LinkedHashSet<>();
qualifiers.add(Bytes.toBytes("testQualifier5"));
testPartialResultsWithColumnFilter(new FirstKeyValueMatchingQualifiersFilter(qualifiers));
}
@Test(timeOut = 60_000)
public void testGetWithColumnPrefixFilter(ITestContext context) throws Exception {
testGet(context, new ColumnPrefixFilter(prefix));
}
@Test(timeOut = 60_000)
public void testScanWithColumnPrefixFilter(ITestContext context) throws Exception {
testScan(context, new ColumnPrefixFilter(prefix));
}
private void assertPrefixFilter(Filter filter, String prefix) {
assertTrue("Filter is not a ColumnPrefixFilter: " + filter.getClass().getSimpleName(),
filter instanceof ColumnPrefixFilter);
ColumnPrefixFilter familyFilter = (ColumnPrefixFilter)filter;
assertEquals("Unexpected prefix", prefix, Bytes.toString(familyFilter.getPrefix()));
}