use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hbase by apache.
the class TestScannersWithFilters method testFilterList.
@Test
public void testFilterList() throws Exception {
// Test getting a single row, single key using Row, Qualifier, and Value
// regular expression and substring filters
// Use must pass all
List<Filter> filters = new ArrayList<>(3);
filters.add(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(".+-2")));
filters.add(new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator(".+-2")));
filters.add(new ValueFilter(CompareOperator.EQUAL, new SubstringComparator("One")));
Filter f = new FilterList(Operator.MUST_PASS_ALL, filters);
Scan s = new Scan();
s.addFamily(FAMILIES[0]);
s.setFilter(f);
KeyValue[] kvs = { new KeyValue(ROWS_ONE[2], FAMILIES[0], QUALIFIERS_ONE[2], VALUES[0]) };
verifyScanFull(s, kvs);
// Test getting everything with a MUST_PASS_ONE filter including row, qf,
// val, regular expression and substring filters
filters.clear();
filters.add(new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(".+Two.+")));
filters.add(new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator(".+-2")));
filters.add(new ValueFilter(CompareOperator.EQUAL, new SubstringComparator("One")));
f = new FilterList(Operator.MUST_PASS_ONE, filters);
s = new Scan();
s.setFilter(f);
verifyScanNoEarlyOut(s, numRows, colsPerRow);
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hbase by apache.
the class ExportUtils method getExportFilter.
private static Filter getExportFilter(String[] args) {
Filter exportFilter;
String filterCriteria = (args.length > 5) ? args[5] : null;
if (filterCriteria == null)
return null;
if (filterCriteria.startsWith("^")) {
String regexPattern = filterCriteria.substring(1, filterCriteria.length());
exportFilter = new RowFilter(CompareOperator.EQUAL, new RegexStringComparator(regexPattern));
} else {
exportFilter = new PrefixFilter(Bytes.toBytesBinary(filterCriteria));
}
return exportFilter;
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator 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 = tmpTable.getName();
final int numRows = 1001;
createAndWriteData(table, numRows);
String regex = ".*17.*";
Filter filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
runReadTestLength(HBaseIO.read().withConfiguration(conf).withTableId(table).withFilter(filter), false, 20);
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hbase by apache.
the class TestFromClientSide method testFilters.
@Test
public void testFilters() throws Exception {
final TableName tableName = name.getTableName();
try (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.setDurability(Durability.SKIP_WAL);
put.addColumn(FAMILY, QUALIFIERS[i], VALUE);
ht.put(put);
}
Scan scan = new Scan();
scan.addFamily(FAMILY);
Filter filter = new QualifierFilter(CompareOperator.EQUAL, new RegexStringComparator("col[1-5]"));
scan.setFilter(filter);
try (ResultScanner scanner = ht.getScanner(scan)) {
int expectedIndex = 1;
for (Result result : scanner) {
assertEquals(1, result.size());
assertTrue(Bytes.equals(CellUtil.cloneRow(result.rawCells()[0]), ROWS[expectedIndex]));
assertTrue(Bytes.equals(CellUtil.cloneQualifier(result.rawCells()[0]), QUALIFIERS[expectedIndex]));
expectedIndex++;
}
assertEquals(6, expectedIndex);
}
}
}
use of org.apache.hadoop.hbase.filter.RegexStringComparator in project hive by apache.
the class HBaseReadWrite method scanFunctions.
/**
* Get a list of functions.
* @param dbName Name of the database to search in.
* @param regex Regular expression to use in searching for function names. It is expected to
* be a Java regular expression. If it is null then all functions will be returned.
* @return list of functions matching the regular expression.
* @throws IOException
*/
List<Function> scanFunctions(String dbName, String regex) throws IOException {
byte[] keyPrefix = null;
if (dbName != null) {
keyPrefix = HBaseUtils.buildKeyWithTrailingSeparator(dbName);
}
Filter filter = null;
if (regex != null) {
filter = new RowFilter(CompareFilter.CompareOp.EQUAL, new RegexStringComparator(regex));
}
Iterator<Result> iter = scan(FUNC_TABLE, keyPrefix, HBaseUtils.getEndPrefix(keyPrefix), CATALOG_CF, CATALOG_COL, filter);
List<Function> functions = new ArrayList<>();
while (iter.hasNext()) {
Result result = iter.next();
functions.add(HBaseUtils.deserializeFunction(result.getRow(), result.getValue(CATALOG_CF, CATALOG_COL)));
}
return functions;
}
Aggregations