Search in sources :

Example 1 with RegexStringComparator

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;
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) Filter(org.apache.hadoop.hbase.filter.Filter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) BloomFilter(org.apache.hive.common.util.BloomFilter) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result)

Example 2 with RegexStringComparator

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;
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) Filter(org.apache.hadoop.hbase.filter.Filter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) BloomFilter(org.apache.hive.common.util.BloomFilter) ArrayList(java.util.ArrayList) Scan(org.apache.hadoop.hbase.client.Scan) HTableInterface(org.apache.hadoop.hbase.client.HTableInterface) Result(org.apache.hadoop.hbase.client.Result)

Example 3 with RegexStringComparator

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;
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) Role(org.apache.hadoop.hive.metastore.api.Role) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) Filter(org.apache.hadoop.hbase.filter.Filter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) BloomFilter(org.apache.hive.common.util.BloomFilter) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result)

Example 4 with RegexStringComparator

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;
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) Filter(org.apache.hadoop.hbase.filter.Filter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) BloomFilter(org.apache.hive.common.util.BloomFilter) ArrayList(java.util.ArrayList) Database(org.apache.hadoop.hive.metastore.api.Database) Result(org.apache.hadoop.hbase.client.Result)

Example 5 with RegexStringComparator

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();
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) TableName(org.apache.hadoop.hbase.TableName) FirstKeyOnlyFilter(org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter) WhileMatchFilter(org.apache.hadoop.hbase.filter.WhileMatchFilter) PrefixFilter(org.apache.hadoop.hbase.filter.PrefixFilter) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) InclusiveStopFilter(org.apache.hadoop.hbase.filter.InclusiveStopFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) Filter(org.apache.hadoop.hbase.filter.Filter) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Cell(org.apache.hadoop.hbase.Cell) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) QualifierFilter(org.apache.hadoop.hbase.filter.QualifierFilter) Test(org.junit.Test)

Aggregations

RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)28 Filter (org.apache.hadoop.hbase.filter.Filter)24 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)24 FirstKeyOnlyFilter (org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter)13 CompareFilter (org.apache.hadoop.hbase.filter.CompareFilter)10 QualifierFilter (org.apache.hadoop.hbase.filter.QualifierFilter)10 Result (org.apache.hadoop.hbase.client.Result)9 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)9 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)9 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)8 Scan (org.apache.hadoop.hbase.client.Scan)7 BloomFilter (org.apache.hive.common.util.BloomFilter)7 ByteArrayComparable (org.apache.hadoop.hbase.filter.ByteArrayComparable)6 CompareOp (org.apache.hadoop.hbase.filter.CompareFilter.CompareOp)6 InclusiveStopFilter (org.apache.hadoop.hbase.filter.InclusiveStopFilter)6 SchemaPath (org.apache.drill.common.expression.SchemaPath)5 NullComparator (org.apache.hadoop.hbase.filter.NullComparator)5 ValueFilter (org.apache.hadoop.hbase.filter.ValueFilter)5