Search in sources :

Example 96 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project gradoop by dbs-leipzig.

the class HBaseLabelInTest method testToHBaseFilter.

/**
 * Test the toHBaseFilter function
 */
@Test
public void testToHBaseFilter() {
    String testLabel1 = "test1";
    String testLabel2 = "test2";
    HBaseLabelIn<EPGMEdge> edgeFilter = new HBaseLabelIn<>(testLabel1, testLabel2);
    FilterList expectedFilterList = new FilterList(FilterList.Operator.MUST_PASS_ONE);
    for (String label : Arrays.asList(testLabel2, testLabel1)) {
        SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_META), Bytes.toBytesBinary(COL_LABEL), CompareFilter.CompareOp.EQUAL, Bytes.toBytesBinary(label));
        expectedFilterList.addFilter(valueFilter);
    }
    assertEquals(edgeFilter.toHBaseFilter(false).toString(), expectedFilterList.toString());
}
Also used : SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) EPGMEdge(org.gradoop.common.model.impl.pojo.EPGMEdge) HBaseLabelIn(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBaseLabelIn) FilterList(org.apache.hadoop.hbase.filter.FilterList) Test(org.testng.annotations.Test)

Example 97 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project gradoop by dbs-leipzig.

the class HBasePropEqualsTest method testToHBaseFilter.

/**
 * Test the toHBaseFilter function
 */
@Test(dataProvider = "property values")
public void testToHBaseFilter(String propertyKey, Object value) {
    PropertyValue propertyValue = PropertyValue.create(value);
    HBasePropEquals<EPGMVertex> vertexFilter = new HBasePropEquals<>(propertyKey, propertyValue);
    FilterList expectedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
    SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_PROPERTY_VALUE), Bytes.toBytesBinary(propertyKey), CompareFilter.CompareOp.EQUAL, PropertyValueUtils.BytesUtils.getRawBytesWithoutType(propertyValue));
    // Define that the entire row will be skipped if the column is not found
    valueFilter.setFilterIfMissing(true);
    SingleColumnValueFilter typeFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_PROPERTY_TYPE), Bytes.toBytesBinary(propertyKey), CompareFilter.CompareOp.EQUAL, PropertyValueUtils.BytesUtils.getTypeByte(propertyValue));
    // Define that the entire row will be skipped if the column is not found
    typeFilter.setFilterIfMissing(true);
    expectedFilter.addFilter(valueFilter);
    expectedFilter.addFilter(typeFilter);
    assertEquals(vertexFilter.toHBaseFilter(false).toString(), expectedFilter.toString(), "Failed during filter comparison for type [" + propertyValue.getType() + "].");
}
Also used : EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) PropertyValue(org.gradoop.common.model.impl.properties.PropertyValue) FilterList(org.apache.hadoop.hbase.filter.FilterList) HBasePropEquals(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropEquals) Test(org.testng.annotations.Test)

Example 98 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project gradoop by dbs-leipzig.

the class HBasePropRegTest method testToHBaseFilter.

/**
 * Test the toHBaseFilter function
 */
@Test
public void testToHBaseFilter() {
    String key = "key";
    Pattern pattern = Pattern.compile("^FooBar.*$");
    HBasePropReg<EPGMVertex> vertexFilter = new HBasePropReg<>(key, pattern);
    FilterList expectedFilter = new FilterList(FilterList.Operator.MUST_PASS_ALL);
    SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_PROPERTY_VALUE), Bytes.toBytesBinary(key), CompareFilter.CompareOp.EQUAL, new RegexStringComparator(pattern.pattern()));
    // Define that the entire row will be skipped if the column is not found
    valueFilter.setFilterIfMissing(true);
    SingleColumnValueFilter typeFilter = new SingleColumnValueFilter(Bytes.toBytesBinary(CF_PROPERTY_TYPE), Bytes.toBytesBinary(key), CompareFilter.CompareOp.EQUAL, new byte[] { Type.STRING.getTypeByte() });
    // Define that the entire row will be skipped if the column is not found
    typeFilter.setFilterIfMissing(true);
    expectedFilter.addFilter(typeFilter);
    expectedFilter.addFilter(valueFilter);
    assertEquals(vertexFilter.toHBaseFilter(false).toString(), expectedFilter.toString(), "Failed during filter comparison for key [" + key + "].");
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) Pattern(java.util.regex.Pattern) EPGMVertex(org.gradoop.common.model.impl.pojo.EPGMVertex) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) HBasePropReg(org.gradoop.storage.hbase.impl.predicate.filter.impl.HBasePropReg) FilterList(org.apache.hadoop.hbase.filter.FilterList) Test(org.testng.annotations.Test)

Example 99 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project gradoop by dbs-leipzig.

the class HBaseFilterUtils method getPropRegFilter.

/**
 * Creates a HBase Filter object representation of propReg predicate
 *
 * @param key the property key to filter for
 * @param reg the pattern to search for
 * @param negate flag to define if this filter should be negated
 * @return the HBase filter representation
 */
public static Filter getPropRegFilter(@Nonnull String key, @Nonnull Pattern reg, boolean negate) {
    // Handle negation
    CompareFilter.CompareOp compareOp = negate ? CompareFilter.CompareOp.NOT_EQUAL : CompareFilter.CompareOp.EQUAL;
    FilterList.Operator listOperator = negate ? FilterList.Operator.MUST_PASS_ONE : FilterList.Operator.MUST_PASS_ALL;
    FilterList filterList = new FilterList(listOperator);
    SingleColumnValueFilter valueFilter = new SingleColumnValueFilter(CF_PROPERTY_VALUE_BYTES, Bytes.toBytesBinary(key), compareOp, new RegexStringComparator(reg.pattern()));
    // Define that the entire row will be skipped if the column is not found
    valueFilter.setFilterIfMissing(true);
    SingleColumnValueFilter typeFilter = new SingleColumnValueFilter(CF_PROPERTY_TYPE_BYTES, Bytes.toBytesBinary(key), compareOp, new byte[] { Type.STRING.getTypeByte() });
    // Define that the entire row will be skipped if the column is not found
    typeFilter.setFilterIfMissing(true);
    filterList.addFilter(typeFilter);
    filterList.addFilter(valueFilter);
    return filterList;
}
Also used : RegexStringComparator(org.apache.hadoop.hbase.filter.RegexStringComparator) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) CompareFilter(org.apache.hadoop.hbase.filter.CompareFilter) FilterList(org.apache.hadoop.hbase.filter.FilterList)

Example 100 with SingleColumnValueFilter

use of org.apache.hadoop.hbase.filter.SingleColumnValueFilter in project java-demo by xiaofu.

the class ClientOp method scanerReturnRow.

public static List<String> scanerReturnRow(String tablename) throws IOException {
    List<String> lists = Lists.newArrayList();
    HTable table = null;
    try {
        table = new HTable(conf, tablename);
        Scan s = new Scan();
        s.addFamily(Bytes.toBytes("main"));
        // s.addColumn(Bytes.toBytes("main"), Bytes.toBytes("_keyid"));
        FilterList filterLists = new FilterList();
        filterLists.addFilter(new KeyOnlyFilter());
        filterLists.addFilter(new SingleColumnValueFilter());
        s.setCaching(1000);
        s.setCacheBlocks(false);
        // s.setFilter(filterLists);
        ResultScanner rs = table.getScanner(s);
        int count = 0;
        final int len = 50000;
        for (Result r : rs) {
            KeyValue[] kv = r.raw();
            lists.add(new String(r.getRow()));
            count++;
            if (count == len)
                break;
        }
        rs.close();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        table.close();
    }
    return lists;
}
Also used : KeyOnlyFilter(org.apache.hadoop.hbase.filter.KeyOnlyFilter) SingleColumnValueFilter(org.apache.hadoop.hbase.filter.SingleColumnValueFilter) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) KeyValue(org.apache.hadoop.hbase.KeyValue) FilterList(org.apache.hadoop.hbase.filter.FilterList) IOException(java.io.IOException) HTable(org.apache.hadoop.hbase.client.HTable) Result(org.apache.hadoop.hbase.client.Result) Scan(org.apache.hadoop.hbase.client.Scan)

Aggregations

SingleColumnValueFilter (org.apache.hadoop.hbase.filter.SingleColumnValueFilter)134 Test (org.junit.Test)64 FilterList (org.apache.hadoop.hbase.filter.FilterList)52 Scan (org.apache.hadoop.hbase.client.Scan)38 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)35 Result (org.apache.hadoop.hbase.client.Result)27 Filter (org.apache.hadoop.hbase.filter.Filter)26 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)21 Table (org.apache.hadoop.hbase.client.Table)21 CompareFilter (org.apache.hadoop.hbase.filter.CompareFilter)19 Put (org.apache.hadoop.hbase.client.Put)18 ArrayList (java.util.ArrayList)13 RegexStringComparator (org.apache.hadoop.hbase.filter.RegexStringComparator)12 RowFilter (org.apache.hadoop.hbase.filter.RowFilter)11 IOException (java.io.IOException)10 Delete (org.apache.hadoop.hbase.client.Delete)10 ByteArrayComparable (org.apache.hadoop.hbase.filter.ByteArrayComparable)10 TableName (org.apache.hadoop.hbase.TableName)8 BitComparator (org.apache.hadoop.hbase.filter.BitComparator)7 CompareOp (org.apache.hadoop.hbase.filter.CompareFilter.CompareOp)7