Search in sources :

Example 1 with FilterList

use of org.apache.gora.filter.FilterList in project gora by apache.

the class DefaultFactoryTest method testCreateFilter_list_2.

@Test
public void testCreateFilter_list_2() throws Exception {
    FilterList<String, WebPage> filter = new FilterList<>();
    MapFieldValueFilter<String, WebPage> hFilter = createHeadersFilter();
    hFilter.setFilterIfMissing(true);
    hFilter.setFilterOp(FilterOp.EQUALS);
    filter.addFilter(hFilter);
    SingleFieldValueFilter<String, WebPage> urlFilter = createUrlFilter();
    urlFilter.setFilterIfMissing(true);
    urlFilter.setFilterOp(FilterOp.EQUALS);
    filter.addFilter(urlFilter);
    DBObject dbObject = filterFactory.createFilter(filter, store);
    assertEquals("{ \"h.C·T\" : \"text/html\" , \"url\" : \"http://www.example.com\"}", dbObject.toString());
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) FilterList(org.apache.gora.filter.FilterList) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 2 with FilterList

use of org.apache.gora.filter.FilterList 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());
        CompareOp 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());
        CompareOp 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) SingleFieldValueFilter(org.apache.gora.filter.SingleFieldValueFilter) CompareOp(org.apache.hadoop.hbase.filter.CompareFilter.CompareOp) MapFieldValueFilter(org.apache.gora.filter.MapFieldValueFilter)

Example 3 with FilterList

use of org.apache.gora.filter.FilterList in project gora by apache.

the class DefaultFactoryTest method testCreateFilter_list_empty.

@Test
public void testCreateFilter_list_empty() throws Exception {
    FilterList<String, WebPage> filter = new FilterList<>();
    DBObject dbObject = filterFactory.createFilter(filter, store);
    assertEquals("{ }", dbObject.toString());
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) FilterList(org.apache.gora.filter.FilterList) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Aggregations

FilterList (org.apache.gora.filter.FilterList)3 DBObject (com.mongodb.DBObject)2 WebPage (org.apache.gora.examples.generated.WebPage)2 Test (org.junit.Test)2 MapFieldValueFilter (org.apache.gora.filter.MapFieldValueFilter)1 SingleFieldValueFilter (org.apache.gora.filter.SingleFieldValueFilter)1 HBaseColumn (org.apache.gora.hbase.store.HBaseColumn)1 CompareOp (org.apache.hadoop.hbase.filter.CompareFilter.CompareOp)1 SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)1