use of org.apache.gora.query.Result 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);
}
use of org.apache.gora.query.Result in project camel by apache.
the class GoraConsumer method poll.
@Override
protected int poll() throws Exception {
final Exchange exchange = this.getEndpoint().createExchange();
// compute time (approx) since last update
if (firstRun) {
this.query.setStartTime(System.currentTimeMillis());
} else {
this.query.setStartTime(System.currentTimeMillis() - getDelay());
}
//proceed with query
final Result result = query.execute();
LOG.trace("Processing exchange [{}]...", exchange);
try {
getProcessor().process(exchange);
} finally {
if (exchange.getException() != null) {
getExceptionHandler().handleException("Error processing exchange", exchange, exchange.getException());
}
}
return Long.valueOf(result.getOffset()).intValue();
}
Aggregations