Search in sources :

Example 1 with Pageview

use of org.apache.gora.jet.generated.Pageview in project gora by apache.

the class JetTest method testNewJetSource.

@Test
public void testNewJetSource() throws Exception {
    DataStore<Long, Pageview> dataStoreIn;
    dataStoreIn = DataStoreFactory.getDataStore(Long.class, Pageview.class, utility.getConfiguration());
    dataStoreOut = DataStoreFactory.getDataStore(Long.class, ResultPageView.class, utility.getConfiguration());
    query = dataStoreIn.newQuery();
    query.setStartKey(0L);
    query.setEndKey(55L);
    JetEngine<Long, Pageview, Long, ResultPageView> jetEngine = new JetEngine<>();
    BatchSource<JetInputOutputFormat<Long, Pageview>> fileSource = jetEngine.createDataSource(dataStoreIn, query);
    Pipeline p = Pipeline.create();
    p.drawFrom(fileSource).filter(item -> item.getValue().getIp().toString().equals("88.240.129.183")).map(e -> {
        ResultPageView resultPageView = new ResultPageView();
        resultPageView.setIp(e.getValue().getIp());
        resultPageView.setTimestamp(e.getValue().getTimestamp());
        resultPageView.setUrl(e.getValue().getUrl());
        return new JetInputOutputFormat<Long, ResultPageView>(e.getValue().getTimestamp(), resultPageView);
    }).drainTo(jetEngine.createDataSink(dataStoreOut));
    JetInstance jet = Jet.newJetInstance();
    Jet.newJetInstance();
    try {
        jet.newJob(p).join();
    } finally {
        Jet.shutdownAll();
    }
    Query<Long, ResultPageView> query = dataStoreOut.newQuery();
    Result<Long, ResultPageView> result = query.execute();
    int noOfOutputRecords = 0;
    String ip = "";
    while (result.next()) {
        noOfOutputRecords++;
        ip = result.get().getIp().toString();
        assertEquals("88.240.129.183", ip);
    }
    assertEquals(2, noOfOutputRecords);
}
Also used : AggregateOperations.counting(com.hazelcast.jet.aggregate.AggregateOperations.counting) JetInstance(com.hazelcast.jet.JetInstance) BatchSource(com.hazelcast.jet.pipeline.BatchSource) BeforeClass(org.junit.BeforeClass) Pipeline(com.hazelcast.jet.pipeline.Pipeline) DataStore(org.apache.gora.store.DataStore) Functions.wholeItem(com.hazelcast.jet.function.Functions.wholeItem) Sinks(com.hazelcast.jet.pipeline.Sinks) Test(org.junit.Test) Pageview(org.apache.gora.jet.generated.Pageview) ResultPageView(org.apache.gora.jet.generated.ResultPageView) Result(org.apache.gora.query.Result) DataStoreFactory(org.apache.gora.store.DataStoreFactory) IMap(com.hazelcast.core.IMap) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) Query(org.apache.gora.query.Query) Traversers.traverseArray(com.hazelcast.jet.Traversers.traverseArray) Jet(com.hazelcast.jet.Jet) Pattern(java.util.regex.Pattern) GoraException(org.apache.gora.util.GoraException) Assert.assertEquals(org.junit.Assert.assertEquals) JetInstance(com.hazelcast.jet.JetInstance) Pipeline(com.hazelcast.jet.pipeline.Pipeline) Pageview(org.apache.gora.jet.generated.Pageview) ResultPageView(org.apache.gora.jet.generated.ResultPageView) Test(org.junit.Test)

Aggregations

IMap (com.hazelcast.core.IMap)1 Jet (com.hazelcast.jet.Jet)1 JetInstance (com.hazelcast.jet.JetInstance)1 Traversers.traverseArray (com.hazelcast.jet.Traversers.traverseArray)1 AggregateOperations.counting (com.hazelcast.jet.aggregate.AggregateOperations.counting)1 Functions.wholeItem (com.hazelcast.jet.function.Functions.wholeItem)1 BatchSource (com.hazelcast.jet.pipeline.BatchSource)1 Pipeline (com.hazelcast.jet.pipeline.Pipeline)1 Sinks (com.hazelcast.jet.pipeline.Sinks)1 Pattern (java.util.regex.Pattern)1 Pageview (org.apache.gora.jet.generated.Pageview)1 ResultPageView (org.apache.gora.jet.generated.ResultPageView)1 Query (org.apache.gora.query.Query)1 Result (org.apache.gora.query.Result)1 DataStore (org.apache.gora.store.DataStore)1 DataStoreFactory (org.apache.gora.store.DataStoreFactory)1 GoraException (org.apache.gora.util.GoraException)1 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 BeforeClass (org.junit.BeforeClass)1