Search in sources :

Example 46 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project gora by apache.

the class DefaultFactory method createFilter.

@Override
public org.apache.hadoop.hbase.filter.Filter createFilter(Filter<K, T> filter, HBaseStore<K, T> store) {
    if (filter instanceof FilterList) {
        FilterList<K, T> filterList = (FilterList<K, T>) filter;
        org.apache.hadoop.hbase.filter.FilterList hbaseFilter = new org.apache.hadoop.hbase.filter.FilterList(Operator.valueOf(filterList.getOperator().name()));
        for (Filter<K, T> rowFitler : filterList.getFilters()) {
            FilterFactory<K, T> factory = getHbaseFitlerUtil().getFactory(rowFitler);
            if (factory == null) {
                LOG.warn("HBase remote filter factory not yet implemented for " + rowFitler.getClass().getCanonicalName());
                return null;
            }
            org.apache.hadoop.hbase.filter.Filter hbaseRowFilter = factory.createFilter(rowFitler, store);
            if (hbaseRowFilter != null) {
                hbaseFilter.addFilter(hbaseRowFilter);
            }
        }
        return hbaseFilter;
    } else if (filter instanceof SingleFieldValueFilter) {
        SingleFieldValueFilter<K, T> fieldFilter = (SingleFieldValueFilter<K, T>) filter;
        HBaseColumn column = store.getMapping().getColumn(fieldFilter.getFieldName());
        CompareOperator compareOp = getCompareOp(fieldFilter.getFilterOp());
        byte[] family = column.getFamily();
        byte[] qualifier = column.getQualifier();
        byte[] value = HBaseByteInterface.toBytes(fieldFilter.getOperands().get(0));
        SingleColumnValueFilter hbaseFilter = new SingleColumnValueFilter(family, qualifier, compareOp, value);
        hbaseFilter.setFilterIfMissing(fieldFilter.isFilterIfMissing());
        return hbaseFilter;
    } else if (filter instanceof MapFieldValueFilter) {
        MapFieldValueFilter<K, T> mapFilter = (MapFieldValueFilter<K, T>) filter;
        HBaseColumn column = store.getMapping().getColumn(mapFilter.getFieldName());
        CompareOperator compareOp = getCompareOp(mapFilter.getFilterOp());
        byte[] family = column.getFamily();
        byte[] qualifier = HBaseByteInterface.toBytes(mapFilter.getMapKey());
        byte[] value = HBaseByteInterface.toBytes(mapFilter.getOperands().get(0));
        SingleColumnValueFilter hbaseFilter = new SingleColumnValueFilter(family, qualifier, compareOp, value);
        hbaseFilter.setFilterIfMissing(mapFilter.isFilterIfMissing());
        return hbaseFilter;
    } else {
        LOG.warn("HBase remote filter not yet implemented for " + filter.getClass().getCanonicalName());
        return null;
    }
}
Also used : HBaseColumn(org.apache.gora.hbase.store.HBaseColumn) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) FilterList(org.apache.gora.filter.FilterList) CompareOperator(org.apache.hadoop.hbase.CompareOperator) SingleFieldValueFilter(org.apache.gora.filter.SingleFieldValueFilter) MapFieldValueFilter(org.apache.gora.filter.MapFieldValueFilter)

Example 47 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hbase by apache.

the class TestAsyncTable method testCheckAndMutateWithMultipleFiltersForOldApi.

@Test
@Deprecated
public void testCheckAndMutateWithMultipleFiltersForOldApi() throws Throwable {
    AsyncTable<?> table = getTable.get();
    // Put one row
    Put put = new Put(row);
    put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"));
    put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"));
    put.addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"));
    table.put(put).get();
    // Put with success
    boolean ok = table.checkAndMutate(row, new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, Bytes.toBytes("b")))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))).get();
    assertTrue(ok);
    Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
    assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));
    // Put with failure
    ok = table.checkAndMutate(row, new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, Bytes.toBytes("c")))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e"))).get();
    assertFalse(ok);
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());
    // Delete with success
    ok = table.checkAndMutate(row, new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, Bytes.toBytes("b")))).thenDelete(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D"))).get();
    assertTrue(ok);
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());
    // Mutate with success
    ok = table.checkAndMutate(row, new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, Bytes.toBytes("b")))).thenMutate(new RowMutations(row).add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))).add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A")))).get();
    assertTrue(ok);
    result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
    assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) FilterList(org.apache.hadoop.hbase.filter.FilterList) Test(org.junit.Test)

Example 48 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hbase by apache.

the class TestAsyncTable method testCheckAndMutateWithSingleFilterForOldApi.

@Test
@Deprecated
public void testCheckAndMutateWithSingleFilterForOldApi() throws Throwable {
    AsyncTable<?> table = getTable.get();
    // Put one row
    Put put = new Put(row);
    put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"));
    put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"));
    put.addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"));
    table.put(put).get();
    // Put with success
    boolean ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a"))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))).get();
    assertTrue(ok);
    Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
    assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));
    // Put with failure
    ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("b"))).thenPut(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e"))).get();
    assertFalse(ok);
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());
    // Delete with success
    ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a"))).thenDelete(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D"))).get();
    assertTrue(ok);
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());
    // Mutate with success
    ok = table.checkAndMutate(row, new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, Bytes.toBytes("b"))).thenMutate(new RowMutations(row).add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))).add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A")))).get();
    assertTrue(ok);
    result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
    assertEquals("d", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("D"))));
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Test(org.junit.Test)

Example 49 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hbase by apache.

the class TestAsyncTable method testCheckAndMutateWithSingleFilter.

@Test
public void testCheckAndMutateWithSingleFilter() throws Throwable {
    AsyncTable<?> table = getTable.get();
    // Put one row
    Put put = new Put(row);
    put.addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"));
    put.addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b"));
    put.addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c"));
    table.put(put).get();
    // Put with success
    CheckAndMutateResult result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a"))).build(new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d")))).get();
    assertTrue(result.isSuccess());
    assertNull(result.getResult());
    Result r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
    assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
    // Put with failure
    result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("b"))).build(new Put(row).addColumn(FAMILY, Bytes.toBytes("E"), Bytes.toBytes("e")))).get();
    assertFalse(result.isSuccess());
    assertNull(result.getResult());
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("E"))).get());
    // Delete with success
    result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a"))).build(new Delete(row).addColumns(FAMILY, Bytes.toBytes("D")))).get();
    assertTrue(result.isSuccess());
    assertNull(result.getResult());
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get());
    // Mutate with success
    result = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("B"), CompareOperator.EQUAL, Bytes.toBytes("b"))).build(new RowMutations(row).add((Mutation) new Put(row).addColumn(FAMILY, Bytes.toBytes("D"), Bytes.toBytes("d"))).add((Mutation) new Delete(row).addColumns(FAMILY, Bytes.toBytes("A"))))).get();
    assertTrue(result.isSuccess());
    assertNull(result.getResult());
    r = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("D"))).get();
    assertEquals("d", Bytes.toString(r.getValue(FAMILY, Bytes.toBytes("D"))));
    assertFalse(table.exists(new Get(row).addColumn(FAMILY, Bytes.toBytes("A"))).get());
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) Test(org.junit.Test)

Example 50 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project hbase by apache.

the class TestAsyncTable method testCheckAndAppend.

@Test
public void testCheckAndAppend() throws Throwable {
    AsyncTable<?> table = getTable.get();
    table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a"))).get();
    // CheckAndAppend with correct value
    CheckAndMutateResult res = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("a")).build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();
    assertTrue(res.isSuccess());
    assertEquals("b", Bytes.toString(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));
    Result result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
    assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));
    // CheckAndAppend with correct value
    res = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifEquals(FAMILY, Bytes.toBytes("A"), Bytes.toBytes("b")).build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("b")))).get();
    assertFalse(res.isSuccess());
    assertNull(res.getResult());
    result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
    assertEquals("b", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));
    table.put(new Put(row).addColumn(FAMILY, Bytes.toBytes("C"), Bytes.toBytes("c")));
    // CheckAndAppend with a filter and correct value
    res = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("a")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL, Bytes.toBytes("c")))).build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("bb")))).get();
    assertTrue(res.isSuccess());
    assertEquals("bbb", Bytes.toString(res.getResult().getValue(FAMILY, Bytes.toBytes("B"))));
    result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
    assertEquals("bbb", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));
    // CheckAndAppend with a filter and wrong value
    res = table.checkAndMutate(CheckAndMutate.newBuilder(row).ifMatches(new FilterList(new SingleColumnValueFilter(FAMILY, Bytes.toBytes("A"), CompareOperator.EQUAL, Bytes.toBytes("b")), new SingleColumnValueFilter(FAMILY, Bytes.toBytes("C"), CompareOperator.EQUAL, Bytes.toBytes("d")))).build(new Append(row).addColumn(FAMILY, Bytes.toBytes("B"), Bytes.toBytes("bb")))).get();
    assertFalse(res.isSuccess());
    assertNull(res.getResult());
    result = table.get(new Get(row).addColumn(FAMILY, Bytes.toBytes("B"))).get();
    assertEquals("bbb", Bytes.toString(result.getValue(FAMILY, Bytes.toBytes("B"))));
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) FilterList(org.apache.hadoop.hbase.filter.FilterList) Test(org.junit.Test)

Aggregations

SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)71 Test (org.junit.Test)39 FilterList (org.apache.hadoop.hbase.filter.FilterList)28 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)16 Scan (org.apache.hadoop.hbase.client.Scan)15 Put (org.apache.hadoop.hbase.client.Put)13 Result (org.apache.hadoop.hbase.client.Result)13 Filter (org.apache.hadoop.hbase.filter.Filter)12 Delete (org.apache.hadoop.hbase.client.Delete)8 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)8 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)8 TableName (org.apache.hadoop.hbase.TableName)7 Table (org.apache.hadoop.hbase.client.Table)7 BitComparator (org.apache.hadoop.hbase.filter.BitComparator)7 ArrayList (java.util.ArrayList)6 CheckAndMutateResult (org.apache.hadoop.hbase.client.CheckAndMutateResult)6 Get (org.apache.hadoop.hbase.client.Get)6 Mutation (org.apache.hadoop.hbase.client.Mutation)6 ByteArrayComparable (org.apache.hadoop.hbase.filter.ByteArrayComparable)6 CompareOp (org.apache.hadoop.hbase.filter.CompareFilter.CompareOp)6