Search in sources :

Example 16 with Filter

use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.

the class DocStoreConverter method transformToOrFilterChainForStrArray.

private static Filter transformToOrFilterChainForStrArray(AttributeFilter attributeFilter) {
    String fieldName = attributeFilter.getName() + VALUE_LIST_VALUES_CONST;
    Filter f = new Filter();
    f.setFieldName("");
    f.setOp(Op.OR);
    f.setChildFilters(attributeFilter.getAttributeValue().getValueList().getValuesList().stream().map(rhsAttributeValue -> createEqFilterForAttributeValue(fieldName, rhsAttributeValue)).collect(Collectors.toList()).toArray(new Filter[] {}));
    return f;
}
Also used : Op(org.hypertrace.core.documentstore.Filter.Op) EntityConstants(org.hypertrace.entity.service.constants.EntityConstants) Filter(org.hypertrace.core.documentstore.Filter) SortOrder(org.hypertrace.entity.data.service.v1.SortOrder) ArrayList(java.util.ArrayList) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) Map(java.util.Map) EntityServiceConstants(org.hypertrace.entity.service.constants.EntityServiceConstants) JsonNode(com.fasterxml.jackson.databind.JsonNode) Nonnull(javax.annotation.Nonnull) Value(org.hypertrace.entity.data.service.v1.Value) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TypeCase(org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase) List(java.util.List) Operator(org.hypertrace.entity.data.service.v1.Operator) Query(org.hypertrace.entity.data.service.v1.Query) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Optional(java.util.Optional) OrderBy(org.hypertrace.core.documentstore.OrderBy) Collections(java.util.Collections) OrderByExpression(org.hypertrace.entity.data.service.v1.OrderByExpression) Filter(org.hypertrace.core.documentstore.Filter) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter)

Example 17 with Filter

use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.

the class DocStoreConverter method transform.

public static org.hypertrace.core.documentstore.Query transform(@Nonnull String tenantId, @Nonnull Query query, List<String> selections) {
    org.hypertrace.core.documentstore.Query docStoreQuery = new org.hypertrace.core.documentstore.Query();
    List<Filter> filters = new ArrayList<>();
    filters.add(getTenantIdEqFilter(tenantId));
    if (!query.getEntityIdList().isEmpty()) {
        filters.add(new Filter(Filter.Op.IN, EntityServiceConstants.ENTITY_ID, query.getEntityIdList()));
    }
    if (StringUtils.isNotEmpty(query.getEntityType())) {
        filters.add(new Filter(Filter.Op.EQ, EntityServiceConstants.ENTITY_TYPE, query.getEntityType()));
    }
    if (StringUtils.isNotEmpty(query.getEntityName())) {
        filters.add(new Filter(Filter.Op.EQ, EntityServiceConstants.ENTITY_NAME, query.getEntityName()));
    }
    if (query.hasFilter()) {
        filters.add(transform(query.getFilter()));
    }
    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);
        }
    }
    if (!selections.isEmpty()) {
        docStoreQuery.addAllSelections(selections);
    }
    if (query.getOrderByCount() > 0) {
        docStoreQuery.addAllOrderBys(transformOrderBy(query.getOrderByList()));
    }
    if (query.getLimit() > 0) {
        docStoreQuery.setLimit(query.getLimit());
    }
    if (query.getOffset() > 0) {
        docStoreQuery.setOffset(query.getOffset());
    }
    return docStoreQuery;
}
Also used : Query(org.hypertrace.entity.data.service.v1.Query) Filter(org.hypertrace.core.documentstore.Filter) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter) ArrayList(java.util.ArrayList)

Example 18 with Filter

use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.

the class DocStoreConverter method transformToNeqFilterWithValueListRhs.

private static Filter transformToNeqFilterWithValueListRhs(AttributeFilter attributeFilter) {
    String fieldName = attributeFilter.getName() + VALUE_LIST_VALUES_CONST;
    Filter f = new Filter();
    f.setFieldName(fieldName);
    f.setOp(Op.NEQ);
    f.setValue(prepareRhsValueForSpecialValueListCase(attributeFilter.getAttributeValue()));
    // Set child filters to empty array
    f.setChildFilters(new Filter[] {});
    return f;
}
Also used : Filter(org.hypertrace.core.documentstore.Filter) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter)

Example 19 with Filter

use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.

the class DocStoreConverter method transformToAndFilterChainForStrArray.

private static Filter transformToAndFilterChainForStrArray(AttributeFilter attributeFilter) {
    String fieldName = attributeFilter.getName() + VALUE_LIST_VALUES_CONST;
    Filter f = new Filter();
    f.setFieldName("");
    f.setOp(Op.AND);
    List<Filter> filters = attributeFilter.getAttributeValue().getValueList().getValuesList().stream().map(rhsAttributeValue -> createNeqFilterForAttributeValue(fieldName, rhsAttributeValue)).collect(Collectors.toList());
    f.setChildFilters(filters.toArray(new Filter[] {}));
    return f;
}
Also used : Op(org.hypertrace.core.documentstore.Filter.Op) EntityConstants(org.hypertrace.entity.service.constants.EntityConstants) Filter(org.hypertrace.core.documentstore.Filter) SortOrder(org.hypertrace.entity.data.service.v1.SortOrder) ArrayList(java.util.ArrayList) AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) Map(java.util.Map) EntityServiceConstants(org.hypertrace.entity.service.constants.EntityServiceConstants) JsonNode(com.fasterxml.jackson.databind.JsonNode) Nonnull(javax.annotation.Nonnull) Value(org.hypertrace.entity.data.service.v1.Value) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter) JSONDocument(org.hypertrace.core.documentstore.JSONDocument) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TypeCase(org.hypertrace.entity.data.service.v1.AttributeValue.TypeCase) List(java.util.List) Operator(org.hypertrace.entity.data.service.v1.Operator) Query(org.hypertrace.entity.data.service.v1.Query) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Optional(java.util.Optional) OrderBy(org.hypertrace.core.documentstore.OrderBy) Collections(java.util.Collections) OrderByExpression(org.hypertrace.entity.data.service.v1.OrderByExpression) Filter(org.hypertrace.core.documentstore.Filter) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter)

Example 20 with Filter

use of org.hypertrace.core.documentstore.Filter in project entity-service by hypertrace.

the class DocStoreConverter method createNeqFilterForAttributeValue.

private static Filter createNeqFilterForAttributeValue(String fieldName, AttributeValue attributeValue) {
    Filter f = new Filter();
    f.setFieldName(fieldName);
    f.setOp(Op.NEQ);
    f.setValue(prepareRhsValueForSpecialValueListCase(attributeValue));
    // Set child filters to empty array
    f.setChildFilters(new Filter[] {});
    return f;
}
Also used : Filter(org.hypertrace.core.documentstore.Filter) AttributeFilter(org.hypertrace.entity.data.service.v1.AttributeFilter)

Aggregations

Filter (org.hypertrace.core.documentstore.Filter)38 AttributeFilter (org.hypertrace.entity.data.service.v1.AttributeFilter)20 Test (org.junit.jupiter.api.Test)19 Query (org.hypertrace.entity.data.service.v1.Query)18 ArrayList (java.util.ArrayList)12 Map (java.util.Map)9 Query (org.hypertrace.core.documentstore.Query)9 JSONDocument (org.hypertrace.core.documentstore.JSONDocument)7 Document (org.hypertrace.core.documentstore.Document)6 Collection (org.hypertrace.core.documentstore.Collection)5 MongoCollection (com.mongodb.client.MongoCollection)4 IOException (java.io.IOException)4 List (java.util.List)4 SingleValueKey (org.hypertrace.core.documentstore.SingleValueKey)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)3 BasicDBObject (com.mongodb.BasicDBObject)3 Collections (java.util.Collections)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3