Search in sources :

Example 31 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class DefaultFactoryTest method createHeadersFilter.

private MapFieldValueFilter<String, WebPage> createHeadersFilter() {
    MapFieldValueFilter<String, WebPage> filter = new MapFieldValueFilter<>();
    filter.setFieldName(WebPage.Field.HEADERS.toString());
    filter.setMapKey(new Utf8("C.T"));
    filter.getOperands().add("text/html");
    return filter;
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Utf8(org.apache.avro.util.Utf8) MapFieldValueFilter(org.apache.gora.filter.MapFieldValueFilter)

Example 32 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class DefaultFactoryTest method testCreateFilter_handlingUtf8.

/**
   * Check that <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a> is fixed.
   * @see <a href="https://issues.apache.org/jira/browse/GORA-388">GORA-388</a>
   */
@Test
public void testCreateFilter_handlingUtf8() throws Exception {
    SingleFieldValueFilter<String, WebPage> filter = new SingleFieldValueFilter<>();
    filter.setFieldName(WebPage.Field.URL.toString());
    filter.setFilterOp(FilterOp.EQUALS);
    filter.getOperands().add(new Utf8("http://www.example.com"));
    filter.setFilterIfMissing(true);
    DBObject dbObject = filterFactory.createFilter(filter, store);
    assertEquals("{ \"url\" : \"http://www.example.com\"}", dbObject.toString());
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) SingleFieldValueFilter(org.apache.gora.filter.SingleFieldValueFilter) Utf8(org.apache.avro.util.Utf8) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 33 with WebPage

use of org.apache.gora.examples.generated.WebPage 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 34 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class DefaultFactoryTest method testCreateFilter_mapField_equalsOrNull.

@Test
public void testCreateFilter_mapField_equalsOrNull() throws Exception {
    MapFieldValueFilter<String, WebPage> filter = createHeadersFilter();
    filter.setFilterOp(FilterOp.EQUALS);
    // include doc with missing field
    filter.setFilterIfMissing(false);
    DBObject dbObject = filterFactory.createFilter(filter, store);
    assertEquals("{ \"$or\" : [ { \"h.C·T\" : { \"$exists\" : false}} , { \"h.C·T\" : \"text/html\"}]}", dbObject.toString());
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) DBObject(com.mongodb.DBObject) Test(org.junit.Test)

Example 35 with WebPage

use of org.apache.gora.examples.generated.WebPage in project gora by apache.

the class TestSingleFieldValueFilter method testFilterBasics.

@Test
public void testFilterBasics() {
    SingleFieldValueFilter<String, WebPage> filter = new SingleFieldValueFilter<>();
    //set filter field to url
    filter.setFieldName(WebPage.Field.URL.toString());
    filter.setFilterOp(FilterOp.EQUALS);
    filter.setFilterIfMissing(true);
    filter.getOperands().add(new Utf8("example.org"));
    WebPage page = WebPage.newBuilder().build();
    page.setUrl(new Utf8("example.org"));
    assertFalse(filter.filter("irrelevant", page));
    page.setUrl(new Utf8("mismatch.whatever"));
    assertTrue(filter.filter("irrelevant", page));
    page = new WebPage();
    assertTrue(filter.filter("irrelevant", page));
    filter.setFilterIfMissing(false);
    assertFalse(filter.filter("irrelevant", page));
}
Also used : WebPage(org.apache.gora.examples.generated.WebPage) Utf8(org.apache.avro.util.Utf8) Test(org.junit.Test)

Aggregations

WebPage (org.apache.gora.examples.generated.WebPage)67 Test (org.junit.Test)33 Utf8 (org.apache.avro.util.Utf8)32 DBObject (com.mongodb.DBObject)7 Configuration (org.apache.hadoop.conf.Configuration)6 Employee (org.apache.gora.examples.generated.Employee)5 Metadata (org.apache.gora.examples.generated.Metadata)4 BeanFactoryImpl (org.apache.gora.persistency.impl.BeanFactoryImpl)4 ByteBuffer (java.nio.ByteBuffer)3 org.apache.hadoop.hbase.client (org.apache.hadoop.hbase.client)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Field (org.apache.avro.Schema.Field)2 TokenDatum (org.apache.gora.examples.generated.TokenDatum)2 FilterList (org.apache.gora.filter.FilterList)2 TableName (org.apache.hadoop.hbase.TableName)2 Job (org.apache.hadoop.mapreduce.Job)2 Properties (java.util.Properties)1