use of org.apache.hadoop.hbase.filter.FamilyFilter in project hadoop by apache.
the class GenericEntityReader method constructFilterListBasedOnFields.
@Override
protected FilterList constructFilterListBasedOnFields() throws IOException {
if (!needCreateFilterListBasedOnFields()) {
// Fetch all the columns. No need of a filter.
return null;
}
FilterList listBasedOnFields = new FilterList(Operator.MUST_PASS_ONE);
FilterList infoColFamilyList = new FilterList();
// By default fetch everything in INFO column family.
FamilyFilter infoColumnFamily = new FamilyFilter(CompareOp.EQUAL, new BinaryComparator(EntityColumnFamily.INFO.getBytes()));
infoColFamilyList.addFilter(infoColumnFamily);
if (!isSingleEntityRead() && fetchPartialColsFromInfoFamily()) {
// We can fetch only some of the columns from info family.
infoColFamilyList.addFilter(createFilterListForColsOfInfoFamily());
} else {
// Exclude column prefixes in info column family which are not required
// based on fields to retrieve.
excludeFieldsFromInfoColFamily(infoColFamilyList);
}
listBasedOnFields.addFilter(infoColFamilyList);
updateFilterForConfsAndMetricsToRetrieve(listBasedOnFields);
return listBasedOnFields;
}
use of org.apache.hadoop.hbase.filter.FamilyFilter in project hbase by apache.
the class TestAsyncTable method testCheckAndMutateWithTimestampFilterForOldApi.
@Test
@Deprecated
public void testCheckAndMutateWithTimestampFilterForOldApi() throws Throwable {
AsyncTable<?> table = getTable.get();
// Put with specifying the timestamp
table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a"))).get();
// Put with success
boolean ok = table.checkAndMutate(row, new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))).get();
assertTrue(ok);
Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure
ok = table.checkAndMutate(row, new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))).get();
assertFalse(ok);
assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("C"))).get());
}
use of org.apache.hadoop.hbase.filter.FamilyFilter in project hbase by apache.
the class TestCheckAndMutate method testCheckAndMutateWithTimestampFilter.
@Test
public void testCheckAndMutateWithTimestampFilter() throws Throwable {
try (Table table = createTable()) {
// Put with specifying the timestamp
table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")));
// Put with success
CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY).ifMatches(new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))).build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"))));
assertTrue(result.isSuccess());
assertNull(result.getResult());
Result r = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals("b", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure
result = table.checkAndMutate(CheckAndMutate.newBuilder(ROWKEY).ifMatches(new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))).build(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"))));
assertFalse(result.isSuccess());
assertNull(result.getResult());
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))));
}
}
use of org.apache.hadoop.hbase.filter.FamilyFilter in project hbase by apache.
the class TestCheckAndMutate method testCheckAndMutateWithTimestampFilterForOldApi.
@Test
@Deprecated
public void testCheckAndMutateWithTimestampFilterForOldApi() throws Throwable {
try (Table table = createTable()) {
// Put with specifying the timestamp
table.put(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("A"), 100, Bytes.toBytes("a")));
// Put with success
boolean ok = table.checkAndMutate(ROWKEY, new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(100L)))).thenPut(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")));
assertTrue(ok);
Result result = table.get(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("B")));
assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));
// Put with failure
ok = table.checkAndMutate(ROWKEY, new FilterList(new FamilyFilter(CompareOperator.EQUAL, new BinaryComparator(FAMILY)), new QualifierFilter(CompareOperator.EQUAL, new BinaryComparator(Bytes.toBytes("A"))), new TimestampsFilter(Collections.singletonList(101L)))).thenPut(new Put(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")));
assertFalse(ok);
assertFalse(table.exists(new Get(ROWKEY).addColumn(FAMILY, Bytes.toBytes("C"))));
}
}
Aggregations