use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hive by apache.
the class HBaseReadWrite method printRolesForUsers.
List<String> printRolesForUsers(String regex) throws IOException {
Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
Iterator<Result> iter = scan(USER_TO_ROLE_TABLE, null, null, CATALOG_CF, CATALOG_COL, filter);
List<String> lines = new ArrayList<>();
while (iter.hasNext()) {
Result result = iter.next();
lines.add(new String(result.getRow(), HBaseUtils.ENCODING) + ": " + org.apache.commons.lang.StringUtils.join(HBaseUtils.deserializeRoleList(result.getValue(CATALOG_CF, CATALOG_COL)), ','));
}
if (lines.size() == 0)
lines = noMatch(regex, "user");
return lines;
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hive by apache.
the class HBaseReadWrite method printTables.
/**
* Print tables
* @param regex to use to find the tables. Remember that dbname is in each
* table name.
* @return tables as strings
* @throws IOException
* @throws TException
*/
List<String> printTables(String regex) throws IOException, TException {
Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
@SuppressWarnings("deprecation") HTableInterface htab = conn.getHBaseTable(TABLE_TABLE);
Scan scan = new Scan();
scan.addColumn(CATALOG_CF, CATALOG_COL);
scan.addFamily(STATS_CF);
scan.setFilter(filter);
Iterator<Result> iter = htab.getScanner(scan).iterator();
if (!iter.hasNext())
return noMatch(regex, "table");
List<String> lines = new ArrayList<>();
while (iter.hasNext()) {
lines.add(printOneTable(iter.next()));
}
return lines;
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hive by apache.
the class HBaseReadWrite method scanRoles.
private List<Role> scanRoles(String regex) throws IOException {
Filter filter = null;
if (regex != null) {
filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
}
Iterator<Result> iter = scan(ROLE_TABLE, null, null, CATALOG_CF, CATALOG_COL, filter);
List<Role> roles = new ArrayList<>();
while (iter.hasNext()) {
Result result = iter.next();
roles.add(HBaseUtils.deserializeRole(result.getRow(), result.getValue(CATALOG_CF, CATALOG_COL)));
}
return roles;
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hive by apache.
the class HBaseReadWrite method scanDatabases.
/**
* Get a list of databases.
* @param regex Regular expression to use in searching for database names. It is expected to
* be a Java regular expression. If it is null then all databases will be returned.
* @return list of databases matching the regular expression.
* @throws IOException
*/
List<Database> scanDatabases(String regex) throws IOException {
Filter filter = null;
if (regex != null) {
filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
}
Iterator<Result> iter = scan(DB_TABLE, CATALOG_CF, CATALOG_COL, filter);
List<Database> databases = new ArrayList<>();
while (iter.hasNext()) {
Result result = iter.next();
databases.add(HBaseUtils.deserializeDatabase(result.getRow(), result.getValue(CATALOG_CF, CATALOG_COL)));
}
return databases;
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hbase by apache.
the class TestFromClientSide method testFiltersWithReverseScan.
@Test
public void testFiltersWithReverseScan() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
Table ht = TEST_UTIL.createTable(tableName, FAMILY);
byte[][] ROWS = makeN(ROW, 10);
byte[][] QUALIFIERS = { Bytes.toBytes("col0-<d2v1>-<d3v2>"), Bytes.toBytes("col1-<d2v1>-<d3v2>"), Bytes.toBytes("col2-<d2v1>-<d3v2>"), Bytes.toBytes("col3-<d2v1>-<d3v2>"), Bytes.toBytes("col4-<d2v1>-<d3v2>"), Bytes.toBytes("col5-<d2v1>-<d3v2>"), Bytes.toBytes("col6-<d2v1>-<d3v2>"), Bytes.toBytes("col7-<d2v1>-<d3v2>"), Bytes.toBytes("col8-<d2v1>-<d3v2>"), Bytes.toBytes("col9-<d2v1>-<d3v2>") };
for (int i = 0; i < 10; i++) {
Put put = new Put(ROWS[i]);
put.addColumn(FAMILY, QUALIFIERS[i], VALUE);
ht.put(put);
}
Scan scan = new Scan();
scan.setReversed(true);
scan.addFamily(FAMILY);
Filter filter = new QualifierFilter(CompareOp.EQUAL, new RegexStringComparator("col[1-5]"));
scan.setFilter(filter);
ResultScanner scanner = ht.getScanner(scan);
int expectedIndex = 5;
for (Result result : scanner) {
assertEquals(result.size(), 1);
Cell c = result.rawCells()[0];
assertTrue(Bytes.equals(c.getRowArray(), c.getRowOffset(), c.getRowLength(), ROWS[expectedIndex], 0, ROWS[expectedIndex].length));
assertTrue(Bytes.equals(c.getQualifierArray(), c.getQualifierOffset(), c.getQualifierLength(), QUALIFIERS[expectedIndex], 0, QUALIFIERS[expectedIndex].length));
expectedIndex--;
}
assertEquals(expectedIndex, 0);
scanner.close();
ht.close();
}
Aggregations