use of org.apache.gora.query.Query in project gora by apache.
the class TestCassandraStore method testDeleteByQueryFields.
@Test
public void testDeleteByQueryFields() throws Exception {
preConfiguration();
log.info("test method: testQueryByQueryFields");
// test 5 - delete all with some fields
WebPageDataCreator.createWebPageData(webPageStore);
Query query = webPageStore.newQuery();
query.setFields("outlinks", "parsedContent", "content");
for (String SORTED_URL : SORTED_URLS) {
query.setKey(SORTED_URL);
webPageStore.deleteByQuery(query);
WebPage page = webPageStore.get(SORTED_URL);
assertNotNull(page);
assertNotNull(page.getUrl());
assertEquals(page.getUrl().toString(), SORTED_URL);
assertEquals("Map of Outlinks should have a size of '0' as the deleteByQuery " + "not only removes the data but also the data structure.", 0, page.getOutlinks().size());
assertEquals(0, page.getParsedContent().size());
if (page.getContent() != null) {
LOG.info("url:" + page.getUrl().toString());
LOG.info("limit:" + page.getContent().limit());
} else {
assertNull(page.getContent());
}
}
}
use of org.apache.gora.query.Query 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.Query in project camel by apache.
the class GoraConsumerTest method consumerInstantiationWithMocksShouldSucceed.
@Test
public void consumerInstantiationWithMocksShouldSucceed() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
final Query mockQuery = mock(Query.class);
when(mockDatastore.newQuery()).thenReturn(mockQuery);
GoraConsumer goraConsumer = new GoraConsumer(mockGoraEndpoint, mockGoraProcessor, mockGoraConfiguration, mockDatastore);
}
use of org.apache.gora.query.Query in project gora by apache.
the class RedisStore method deleteByQuery.
@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
Collection<K> range = runQuery(query);
RBatch batchInstance = redisInstance.createBatch();
RLexSortedSetAsync secundaryIndex = batchInstance.getLexSortedSet(generateIndexKey());
if (query.getFields() != null && query.getFields().length < mapping.getFields().size()) {
List<String> dbFields = new ArrayList<>();
List<RedisType> dbTypes = new ArrayList<>();
for (String af : query.getFields()) {
dbFields.add(mapping.getFields().get(af));
dbTypes.add(mapping.getTypes().get(af));
}
for (K key : range) {
if (mode == StorageMode.SINGLEKEY) {
RMapAsync<Object, Object> map = batchInstance.getMap(generateKeyHash(key));
dbFields.forEach((field) -> {
map.removeAsync(field);
});
} else {
for (int indexField = 0; indexField < dbFields.size(); indexField++) {
String field = dbFields.get(indexField);
RedisType type = dbTypes.get(indexField);
switch(type) {
case STRING:
RBucketAsync<Object> bucket = batchInstance.getBucket(generateKeyString(field, key));
bucket.deleteAsync();
break;
case LIST:
RListAsync<Object> rlist = batchInstance.getList(generateKeyString(field, key));
rlist.deleteAsync();
break;
case HASH:
RMapAsync<Object, Object> map = batchInstance.getMap(generateKeyString(field, key));
map.deleteAsync();
break;
default:
throw new AssertionError(type.name());
}
}
}
}
} else {
range.stream().map((key) -> {
secundaryIndex.removeAsync(key);
return key;
}).forEachOrdered((key) -> {
if (mode == StorageMode.SINGLEKEY) {
RMapAsync<Object, Object> map = batchInstance.getMap(generateKeyHash(key));
map.deleteAsync();
} else {
redisInstance.getKeys().deleteByPattern(generateKeyStringBase(key) + WILDCARD);
}
});
}
batchInstance.execute();
return range.size();
}
use of org.apache.gora.query.Query in project gora by apache.
the class OrientDBStore method get.
/**
* {@inheritDoc}
*/
@Override
public T get(K key, String[] fields) throws GoraException {
String[] dbFields = getFieldsToQuery(fields);
com.github.raymanrt.orientqb.query.Query selectQuery = new com.github.raymanrt.orientqb.query.Query();
for (String k : dbFields) {
String dbFieldName = orientDBMapping.getDocumentField(k);
if (dbFieldName != null && dbFieldName.length() > 0) {
selectQuery.select(dbFieldName);
}
}
selectQuery.from(orientDBMapping.getDocumentClass()).where(projection("_id").eq(Parameter.parameter("key")));
Map<String, Object> params = new HashMap<String, Object>();
params.put("key", key);
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>(selectQuery.toString());
try (ODatabaseDocumentTx selectTx = connectionPool.acquire()) {
selectTx.activateOnCurrentThread();
List<ODocument> result = selectTx.command(query).execute(params);
if (result.size() == 1) {
return convertOrientDocToAvroBean(result.get(0), dbFields);
} else {
return null;
}
} catch (Exception e) {
throw new GoraException(e);
}
}
Aggregations