use of org.apache.hadoop.hbase.filter.FuzzyRowFilter in project java-bigtable-hbase by googleapis.
the class AbstractTestFilters method testFuzzyDifferentSizes.
@Test
public void testFuzzyDifferentSizes() throws Exception {
if (!sharedTestEnv.isBigtable()) {
// See issue #1770
return;
}
Table table = getDefaultTable();
List<byte[]> keys = Collections.unmodifiableList(Arrays.asList(createKey(1, 2, 3, 4, 5, 6), createKey(1, 9, 9, 4, 9, 9), createKey(2, 3, 4, 5, 6, 7)));
List<Put> puts = new ArrayList<>();
for (byte[] key : keys) {
puts.add(new Put(key).addColumn(SharedTestEnvRule.COLUMN_FAMILY, Bytes.toBytes(0), Bytes.toBytes(0)));
}
table.put(puts);
// match keys with 1 in the first position and 4 in the 4th position
Pair<byte[], byte[]> fuzzyData = Pair.newPair(createKey(1, 0, 0, 4), createFuzzyMask(0, 1, 1, 0));
Scan scan = new Scan().setFilter(new FuzzyRowFilter(ImmutableList.of(fuzzyData)));
// only the first and second keys should be matched
try (ResultScanner scanner = table.getScanner(scan)) {
assertMatchingRow(scanner.next(), keys.get(0));
assertMatchingRow(scanner.next(), keys.get(1));
assertNull(scanner.next());
}
}
use of org.apache.hadoop.hbase.filter.FuzzyRowFilter in project java-bigtable-hbase by googleapis.
the class AbstractTestFilters method testFuzzyRowFilter.
/**
* Test {@link FuzzyRowFilter} to make sure that a String that matches the following regex is
* matched: '.{8}-fuzzy-row-suffix'
*/
@Test
public void testFuzzyRowFilter() throws IOException {
if (!sharedTestEnv.isBigtable()) {
// thing.
return;
}
final String rowSuffix = "-fuzzy-row-suffix";
final byte[] qualA = dataHelper.randomData("qualA");
byte[] value = Bytes.toBytes("Important data goes here");
// 'bad' comes before 'fuzzy' alphabetically and 'other' comes after 'fuzzy'.
byte[] missKey1 = dataHelper.randomData("a", "-bad-row-suffix");
byte[] missKey2 = dataHelper.randomData("b", "-fuzzy-bad-row-suffix");
byte[] missKey3 = dataHelper.randomData("c", "-other-row-suffix");
// dataHelper.randomData() adds 8 random characters between the prefix and suffix
byte[] hitKey1 = dataHelper.randomData("a", rowSuffix);
byte[] hitKey2 = dataHelper.randomData("b", rowSuffix);
byte[] hitKey3 = dataHelper.randomData("c", rowSuffix);
byte[] hitKey4 = dataHelper.randomData("d", rowSuffix);
StringBuilder filterString = new StringBuilder();
final int prefixSize = 9;
int size = prefixSize + rowSuffix.length();
byte[] filterBytes = new byte[size];
for (int i = 0; i < prefixSize; i++) {
filterString.append("\\x00");
filterBytes[i] = 1;
}
filterString.append(rowSuffix);
for (int i = 0; i < rowSuffix.length(); i++) {
filterBytes[i + prefixSize] = 0;
}
FuzzyRowFilter fuzzyFilter = new FuzzyRowFilter(Arrays.asList(new Pair<byte[], byte[]>(Bytes.toBytesBinary(filterString.toString()), filterBytes)));
Scan scan = new Scan();
scan.setFilter(fuzzyFilter);
Table table = getDefaultTable();
List<Put> puts = new ArrayList<>();
for (byte[] key : Arrays.asList(missKey1, missKey2, missKey3, hitKey1, hitKey2, hitKey3, hitKey4)) {
puts.add(new Put(key).addColumn(COLUMN_FAMILY, qualA, value));
}
table.put(puts);
try (ResultScanner scanner = table.getScanner(scan)) {
assertNextEquals(scanner, hitKey1);
assertNextEquals(scanner, hitKey2);
assertNextEquals(scanner, hitKey3);
assertNextEquals(scanner, hitKey4);
Assert.assertNull(scanner.next());
}
}
Aggregations