Search in sources :

Example 26 with Builder

use of org.hypertrace.gateway.service.v1.entity.Entity.Builder in project gateway-service by hypertrace.

the class TracesService method filterTraces.

@VisibleForTesting
List<Trace> filterTraces(RequestContext context, TracesRequest request, Map<String, AttributeMetadata> attributeMetadataMap, TraceScope scope) {
    Map<String, AttributeMetadata> resultKeyToAttributeMetadataMap = AttributeMetadataUtil.remapAttributeMetadataByResultKey(request.getSelectionList(), attributeMetadataMap);
    QueryRequest.Builder builder = createQueryWithFilter(request, scope, context);
    if (!request.getSelectionList().isEmpty()) {
        request.getSelectionList().forEach(exp -> builder.addSelection(QueryAndGatewayDtoConverter.convertToQueryExpression(exp)));
    }
    // Adds the parent span id selection to the query builder for the span event
    addSortLimitAndOffset(request, builder);
    List<Trace> tracesResult = new ArrayList<>();
    QueryRequest queryRequest = builder.build();
    Iterator<ResultSetChunk> resultSetChunkIterator = queryServiceClient.executeQuery(queryRequest, context.getHeaders(), queryServiceReqTimeout);
    // form the result
    while (resultSetChunkIterator.hasNext()) {
        ResultSetChunk chunk = resultSetChunkIterator.next();
        if (LOG.isDebugEnabled()) {
            LOG.debug("Received chunk: " + chunk.toString());
        }
        if (chunk.getRowCount() < 1) {
            break;
        }
        for (Row row : chunk.getRowList()) {
            Trace.Builder traceBuilder = Trace.newBuilder();
            for (int i = 0; i < chunk.getResultSetMetadata().getColumnMetadataCount(); i++) {
                ColumnMetadata metadata = chunk.getResultSetMetadata().getColumnMetadata(i);
                String attrName = metadata.getColumnName();
                traceBuilder.putAttributes(metadata.getColumnName(), QueryAndGatewayDtoConverter.convertToGatewayValue(attrName, row.getColumn(i), resultKeyToAttributeMetadataMap));
            }
            tracesResult.add(traceBuilder.build());
        }
    }
    return tracesResult;
}
Also used : Builder(org.hypertrace.core.query.service.api.QueryRequest.Builder) ColumnMetadata(org.hypertrace.core.query.service.api.ColumnMetadata) QueryRequest(org.hypertrace.core.query.service.api.QueryRequest) ArrayList(java.util.ArrayList) Trace(org.hypertrace.gateway.service.v1.trace.Trace) AttributeMetadata(org.hypertrace.core.attribute.service.v1.AttributeMetadata) Row(org.hypertrace.core.query.service.api.Row) ResultSetChunk(org.hypertrace.core.query.service.api.ResultSetChunk) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

EntityKey (org.hypertrace.gateway.service.entity.EntityKey)15 EntitiesRequest (org.hypertrace.gateway.service.v1.entity.EntitiesRequest)15 EntitiesRequestContext (org.hypertrace.gateway.service.entity.EntitiesRequestContext)14 Builder (org.hypertrace.gateway.service.v1.entity.Entity.Builder)14 OrderByExpression (org.hypertrace.gateway.service.v1.common.OrderByExpression)12 Test (org.junit.jupiter.api.Test)11 AttributeScope (org.hypertrace.core.attribute.service.v1.AttributeScope)10 Expression (org.hypertrace.gateway.service.v1.common.Expression)10 LinkedHashMap (java.util.LinkedHashMap)9 EntitiesRequestAndResponseUtils.buildOrderByExpression (org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression)9 EntityFetcherResponse (org.hypertrace.gateway.service.common.datafetcher.EntityFetcherResponse)9 QueryRequest (org.hypertrace.core.query.service.api.QueryRequest)8 ResultSetChunk (org.hypertrace.core.query.service.api.ResultSetChunk)8 EntityResponse (org.hypertrace.gateway.service.common.datafetcher.EntityResponse)8 TimeAggregation (org.hypertrace.gateway.service.v1.common.TimeAggregation)8 AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5