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;
}
Aggregations