Search in sources :

Example 26 with Filter

use of org.apache.hadoop.hbase.filter.Filter 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 27 with Filter

use of org.apache.hadoop.hbase.filter.Filter 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 28 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project hive by apache.

the class HBaseReadWrite method scanPartitionsInternal.

private PartitionScanInfo scanPartitionsInternal(String dbName, String tableName, List<String> partVals, int maxPartitions) throws IOException, NoSuchObjectException {
    // First, build as much of the key as we can so that we make the scan as tight as possible.
    List<String> keyElements = new ArrayList<>();
    keyElements.add(dbName);
    keyElements.add(tableName);
    int firstStar = -1;
    for (int i = 0; i < partVals.size(); i++) {
        if ("*".equals(partVals.get(i))) {
            firstStar = i;
            break;
        } else {
            // means star
            if (partVals.get(i).equals("")) {
                break;
            } else {
                keyElements.add(partVals.get(i));
            }
        }
    }
    byte[] keyPrefix;
    // We need to fetch the table to determine if the user fully specified the partitions or
    // not, as it affects how we build the key.
    Table table = getTable(dbName, tableName);
    if (table == null) {
        throw new NoSuchObjectException("Unable to find table " + dbName + "." + tableName);
    }
    keyPrefix = HBaseUtils.buildPartitionKey(dbName, tableName, HBaseUtils.getPartitionKeyTypes(table.getPartitionKeys().subList(0, keyElements.size() - 2)), keyElements.subList(2, keyElements.size()));
    // Now, build a filter out of the remaining keys
    List<PartitionKeyComparator.Range> ranges = new ArrayList<PartitionKeyComparator.Range>();
    List<Operator> ops = new ArrayList<Operator>();
    if (!(partVals.size() == table.getPartitionKeys().size() && firstStar == -1)) {
        for (int i = Math.max(0, firstStar); i < table.getPartitionKeys().size() && i < partVals.size(); i++) {
            if ("*".equals(partVals.get(i))) {
                PartitionKeyComparator.Operator op = new PartitionKeyComparator.Operator(PartitionKeyComparator.Operator.Type.LIKE, table.getPartitionKeys().get(i).getName(), ".*");
                ops.add(op);
            } else {
                PartitionKeyComparator.Range range = new PartitionKeyComparator.Range(table.getPartitionKeys().get(i).getName(), new PartitionKeyComparator.Mark(partVals.get(i), true), new PartitionKeyComparator.Mark(partVals.get(i), true));
                ranges.add(range);
            }
        }
    }
    Filter filter = null;
    if (!ranges.isEmpty() || !ops.isEmpty()) {
        filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new PartitionKeyComparator(StringUtils.join(HBaseUtils.getPartitionNames(table.getPartitionKeys()), ","), StringUtils.join(HBaseUtils.getPartitionKeyTypes(table.getPartitionKeys()), ","), ranges, ops));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Scanning partitions with prefix <" + new String(keyPrefix) + "> and filter <" + filter + ">");
    }
    return new PartitionScanInfo(dbName, tableName, keyPrefix, HBaseUtils.getEndPrefix(keyPrefix), maxPartitions, filter);
}
Also used : Operator(org.apache.hadoop.hive.metastore.hbase.PartitionKeyComparator.Operator) Table(org.apache.hadoop.hive.metastore.api.Table) ArrayList(java.util.ArrayList) 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) NoSuchObjectException(org.apache.hadoop.hive.metastore.api.NoSuchObjectException) Operator(org.apache.hadoop.hive.metastore.hbase.PartitionKeyComparator.Operator)

Example 29 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project honeycomb by altamiracorp.

the class MockHTable method get.

@Override
public Result get(Get get) throws IOException {
    if (!data.containsKey(get.getRow()))
        return new Result();
    byte[] row = get.getRow();
    List<KeyValue> kvs = new ArrayList<KeyValue>();
    if (!get.hasFamilies()) {
        kvs = toKeyValue(row, data.get(row), get.getMaxVersions());
    } else {
        for (byte[] family : get.getFamilyMap().keySet()) {
            if (data.get(row).get(family) == null)
                continue;
            NavigableSet<byte[]> qualifiers = get.getFamilyMap().get(family);
            if (qualifiers == null || qualifiers.isEmpty())
                qualifiers = data.get(row).get(family).navigableKeySet();
            for (byte[] qualifier : qualifiers) {
                if (qualifier == null)
                    qualifier = "".getBytes();
                if (!data.get(row).containsKey(family) || !data.get(row).get(family).containsKey(qualifier) || data.get(row).get(family).get(qualifier).isEmpty())
                    continue;
                Entry<Long, byte[]> timestampAndValue = data.get(row).get(family).get(qualifier).lastEntry();
                kvs.add(new KeyValue(row, family, qualifier, timestampAndValue.getKey(), timestampAndValue.getValue()));
            }
        }
    }
    Filter filter = get.getFilter();
    if (filter != null) {
        filter.reset();
        List<KeyValue> nkvs = new ArrayList<KeyValue>(kvs.size());
        for (KeyValue kv : kvs) {
            if (filter.filterAllRemaining()) {
                break;
            }
            if (filter.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength())) {
                continue;
            }
            if (filter.filterKeyValue(kv) == ReturnCode.INCLUDE) {
                nkvs.add(kv);
            }
        // ignoring next key hint which is a optimization to reduce file system IO
        }
        if (filter.hasFilterRow()) {
            filter.filterRow(nkvs);
        }
        kvs = nkvs;
    }
    return new Result(kvs);
}
Also used : KeyValue(org.apache.hadoop.hbase.KeyValue) Filter(org.apache.hadoop.hbase.filter.Filter) ArrayList(java.util.ArrayList) Result(org.apache.hadoop.hbase.client.Result)

Example 30 with Filter

use of org.apache.hadoop.hbase.filter.Filter in project beam by apache.

the class HBaseIOTest method testReadingWithFilter.

/** Tests reading all rows using a filter. */
@Test
public void testReadingWithFilter() throws Exception {
    final String table = "TEST-FILTER-TABLE";
    final int numRows = 1001;
    createTable(table);
    writeData(table, numRows);
    String regex = ".*17.*";
    Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
    HBaseIO.Read read = HBaseIO.read().withConfiguration(conf).withTableId(table).withFilter(filter);
    runReadTestLength(read, 20);
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) RowFilter(org.apache.hadoop.hbase.filter.RowFilter) Filter(org.apache.hadoop.hbase.filter.Filter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) Test(org.junit.Test)

Aggregations

Filter (org.apache.hadoop.hbase.filter.Filter)172 Test (org.junit.Test)96 Scan (org.apache.hadoop.hbase.client.Scan)94 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)77 SkipScanFilter (org.apache.phoenix.filter.SkipScanFilter)76 RowKeyComparisonFilter (org.apache.phoenix.filter.RowKeyComparisonFilter)74 SingleKeyValueComparisonFilter (org.apache.phoenix.filter.SingleKeyValueComparisonFilter)45 TestUtil.rowKeyFilter (org.apache.phoenix.util.TestUtil.rowKeyFilter)45 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)40 FilterList (org.apache.hadoop.hbase.filter.FilterList)39 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)37 TestUtil.multiEncodedKVFilter (org.apache.phoenix.util.TestUtil.multiEncodedKVFilter)33 TestUtil.singleKVFilter (org.apache.phoenix.util.TestUtil.singleKVFilter)33 PhoenixPreparedStatement (org.apache.phoenix.jdbc.PhoenixPreparedStatement)31 FirstKeyOnlyFilter (org.apache.hadoop.hbase.filter.FirstKeyOnlyFilter)27 PrefixFilter (org.apache.hadoop.hbase.filter.PrefixFilter)24 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)23 CompareFilter (org.apache.hadoop.hbase.filter.CompareFilter)22 ArrayList (java.util.ArrayList)19 RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)18