use of org.molgenis.emx2.Query in project entity-service by hypertrace.
the class EntityDataServiceImpl method getRelationships.
@Override
public void getRelationships(RelationshipsQuery query, StreamObserver<EntityRelationship> responseObserver) {
logQuery(query);
Optional<String> tenantId = RequestContext.CURRENT.get().getTenantId();
if (tenantId.isEmpty()) {
responseObserver.onError(new ServiceException("Tenant id is missing in the request."));
return;
}
org.hypertrace.core.documentstore.Query docStoreQuery = new org.hypertrace.core.documentstore.Query();
List<Filter> filters = new ArrayList<>();
filters.add(DocStoreConverter.getTenantIdEqFilter(tenantId.get()));
if (query.getEntityRelationshipCount() > 0) {
filters.add(new Filter(Filter.Op.IN, EntityServiceConstants.ENTITY_RELATIONSHIP_TYPE, query.getEntityRelationshipList()));
}
if (query.getFromEntityIdCount() > 0) {
filters.add(new Filter(Filter.Op.IN, EntityServiceConstants.FROM_ENTITY_ID, query.getFromEntityIdList()));
}
if (query.getToEntityIdCount() > 0) {
filters.add(new Filter(Filter.Op.IN, EntityServiceConstants.TO_ENTITY_ID, query.getToEntityIdList()));
}
if (!filters.isEmpty()) {
if (filters.size() == 1) {
docStoreQuery.setFilter(filters.get(0));
} else {
Filter f = new Filter();
f.setOp(Filter.Op.AND);
f.setChildFilters(filters.toArray(new Filter[] {}));
docStoreQuery.setFilter(f);
}
}
searchByQueryAndStreamRelationships(docStoreQuery, responseObserver, tenantId.get());
}
use of org.molgenis.emx2.Query in project entity-service by hypertrace.
the class EntityDataServiceImpl method buildExistingEntitiesInQuery.
private org.hypertrace.core.documentstore.Query buildExistingEntitiesInQuery(java.util.Collection<String> docIds) {
org.hypertrace.core.documentstore.Query query = new org.hypertrace.core.documentstore.Query();
query.setFilter(new Filter(Filter.Op.IN, EntityServiceConstants.ID, docIds));
return query;
}
use of org.molgenis.emx2.Query in project entity-service by hypertrace.
the class EntityDataServiceImpl method buildExistingEntityQuery.
private org.hypertrace.core.documentstore.Query buildExistingEntityQuery(String tenantId, String entityType, String entityId) {
org.hypertrace.core.documentstore.Query query = new org.hypertrace.core.documentstore.Query();
String docId = this.entityNormalizer.getEntityDocKey(tenantId, entityType, entityId).toString();
query.setFilter(new Filter(Filter.Op.EQ, EntityServiceConstants.ID, docId));
return query;
}
use of org.molgenis.emx2.Query in project beam by apache.
the class DataStoreReadWriteIT method testWriteRead_viaCoreBeamIO.
@Test
public void testWriteRead_viaCoreBeamIO() {
String projectId = options.getProject();
Key ancestor = makeKey(KIND, UUID.randomUUID().toString()).build();
Key itemKey = makeKey(ancestor, KIND, UUID.randomUUID().toString()).setPartitionId(PartitionId.newBuilder().setProjectId(projectId).build()).build();
Row testWriteRow = Row.withSchema(SOURCE_SCHEMA).addValues(itemKey.toByteArray(), "4000").build();
writePipeline.apply(Create.of(testWriteRow).withRowSchema(SOURCE_SCHEMA)).apply(RowToEntity.create("__key__", KIND)).apply(DatastoreIO.v1().write().withProjectId(projectId));
writePipeline.run().waitUntilFinish();
Query.Builder query = Query.newBuilder();
query.addKindBuilder().setName(KIND);
query.setFilter(makeFilter("__key__", Operator.EQUAL, makeValue(itemKey)));
DatastoreV1.Read read = DatastoreIO.v1().read().withProjectId(projectId).withQuery(query.build());
PCollection<Row> rowsRead = readPipeline.apply(read).apply(EntityToRow.create(SOURCE_SCHEMA, "__key__"));
PAssert.that(rowsRead).containsInAnyOrder(testWriteRow);
readPipeline.run().waitUntilFinish();
}
use of org.molgenis.emx2.Query in project beam by apache.
the class DatastoreV1Test method testSplitQueryFnWithQueryLimit.
/**
* Tests {@link DatastoreV1.Read.SplitQueryFn} when the query has a user specified limit.
*/
@Test
public void testSplitQueryFnWithQueryLimit() throws Exception {
Query queryWithLimit = QUERY.toBuilder().setLimit(Int32Value.newBuilder().setValue(1)).build();
SplitQueryFn splitQueryFn = new SplitQueryFn(V_1_OPTIONS, 10, mockDatastoreFactory);
DoFnTester<Query, Query> doFnTester = DoFnTester.of(splitQueryFn);
doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE);
List<Query> queries = doFnTester.processBundle(queryWithLimit);
assertEquals(1, queries.size());
verifyNoMoreInteractions(mockDatastore);
verifyNoMoreInteractions(mockQuerySplitter);
}
Aggregations