Search in sources :

Example 16 with Query

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());
}
Also used : ServiceException(com.google.protobuf.ServiceException) Query(org.hypertrace.entity.data.service.v1.Query) RelationshipsQuery(org.hypertrace.entity.data.service.v1.RelationshipsQuery) Filter(org.hypertrace.core.documentstore.Filter) ArrayList(java.util.ArrayList)

Example 17 with Query

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;
}
Also used : Query(org.hypertrace.entity.data.service.v1.Query) RelationshipsQuery(org.hypertrace.entity.data.service.v1.RelationshipsQuery) Filter(org.hypertrace.core.documentstore.Filter)

Example 18 with 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;
}
Also used : Query(org.hypertrace.entity.data.service.v1.Query) RelationshipsQuery(org.hypertrace.entity.data.service.v1.RelationshipsQuery) Filter(org.hypertrace.core.documentstore.Filter)

Example 19 with 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();
}
Also used : Query(com.google.datastore.v1.Query) DatastoreV1(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1) ByteString(org.apache.beam.vendor.calcite.v1_28_0.org.apache.calcite.avatica.util.ByteString) Row(org.apache.beam.sdk.values.Row) EntityToRow(org.apache.beam.sdk.io.gcp.datastore.EntityToRow) Key(com.google.datastore.v1.Key) DatastoreHelper.makeKey(com.google.datastore.v1.client.DatastoreHelper.makeKey) Test(org.junit.Test)

Example 20 with Query

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);
}
Also used : GqlQuery(com.google.datastore.v1.GqlQuery) Query(com.google.datastore.v1.Query) SplitQueryFn(org.apache.beam.sdk.io.gcp.datastore.DatastoreV1.Read.SplitQueryFn) Test(org.junit.Test)

Aggregations

Query (org.jpl7.Query)88 Term (org.jpl7.Term)52 Variable (org.jpl7.Variable)32 Query (org.hypertrace.entity.data.service.v1.Query)31 Map (java.util.Map)28 Test (org.junit.jupiter.api.Test)23 Atom (org.jpl7.Atom)21 Compound (org.jpl7.Compound)18 Test (org.junit.Test)18 Filter (org.hypertrace.core.documentstore.Filter)16 Query (com.google.datastore.v1.Query)14 AttributeFilter (org.hypertrace.entity.data.service.v1.AttributeFilter)14 GqlQuery (com.google.datastore.v1.GqlQuery)7 ArrayList (java.util.ArrayList)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)6 Entity (org.hypertrace.entity.data.service.v1.Entity)6 Integer (org.jpl7.Integer)6 Query (org.molgenis.emx2.Query)6 IOException (java.io.IOException)5 Collections (java.util.Collections)5