use of org.jooq.SelectField in project zipkin by openzipkin.
the class MySQLSpanStore method toTraceIdQuery.
SelectOffsetStep<? extends Record> toTraceIdQuery(DSLContext context, QueryRequest request) {
long endTs = (request.endTs > 0 && request.endTs != Long.MAX_VALUE) ? request.endTs * 1000 : System.currentTimeMillis() * 1000;
TableOnConditionStep<?> table = ZIPKIN_SPANS.join(ZIPKIN_ANNOTATIONS).on(schema.joinCondition(ZIPKIN_ANNOTATIONS));
int i = 0;
for (String key : request.annotations) {
ZipkinAnnotations aTable = ZIPKIN_ANNOTATIONS.as("a" + i++);
table = maybeOnService(table.join(aTable).on(schema.joinCondition(aTable)).and(aTable.A_TYPE.eq(-1)).and(aTable.A_KEY.eq(key)), aTable, request.serviceName);
}
for (Map.Entry<String, String> kv : request.binaryAnnotations.entrySet()) {
ZipkinAnnotations aTable = ZIPKIN_ANNOTATIONS.as("a" + i++);
table = maybeOnService(table.join(aTable).on(schema.joinCondition(aTable)).and(aTable.A_TYPE.eq(STRING.value)).and(aTable.A_KEY.eq(kv.getKey())).and(aTable.A_VALUE.eq(kv.getValue().getBytes(UTF_8))), aTable, request.serviceName);
}
List<SelectField<?>> distinctFields = new ArrayList<>(schema.spanIdFields);
distinctFields.add(ZIPKIN_SPANS.START_TS.max());
SelectConditionStep<Record> dsl = context.selectDistinct(distinctFields).from(table).where(ZIPKIN_SPANS.START_TS.between(endTs - request.lookback * 1000, endTs));
if (request.serviceName != null) {
dsl.and(ZIPKIN_ANNOTATIONS.ENDPOINT_SERVICE_NAME.eq(request.serviceName));
}
if (request.spanName != null) {
dsl.and(ZIPKIN_SPANS.NAME.eq(request.spanName));
}
if (request.minDuration != null && request.maxDuration != null) {
dsl.and(ZIPKIN_SPANS.DURATION.between(request.minDuration, request.maxDuration));
} else if (request.minDuration != null) {
dsl.and(ZIPKIN_SPANS.DURATION.greaterOrEqual(request.minDuration));
}
return dsl.groupBy(schema.spanIdFields).orderBy(ZIPKIN_SPANS.START_TS.max().desc()).limit(request.limit);
}
Aggregations