use of io.crate.planner.Plan.StatementType in project crate by crate.
the class QueryStatsTest method testTrackedStatementTypes.
@Test
public void testTrackedStatementTypes() {
List<MetricsView> oneMetricForEachStatementType = new ArrayList<>();
for (StatementType type : StatementType.values()) {
if (type.equals(StatementType.UNDEFINED)) {
continue;
}
oneMetricForEachStatementType.add(createMetric(new Classification(type), 1));
}
Map<StatementType, QueryStats.Metric> metricsByCommand = createMetricsMap(oneMetricForEachStatementType);
assertThat(metricsByCommand.size(), is(7));
assertThat(metricsByCommand.get(StatementType.SELECT), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.UPDATE), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.INSERT), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.DELETE), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.DDL), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.MANAGEMENT), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.COPY), is(notNullValue()));
assertThat(metricsByCommand.get(StatementType.UNDEFINED), is(nullValue()));
}
use of io.crate.planner.Plan.StatementType in project crate by crate.
the class QueryStats method createMetricsMap.
static Map<StatementType, Metric> createMetricsMap(Iterable<MetricsView> metrics) {
Map<StatementType, Metric> metricsByStmtType = new HashMap<>();
for (MetricsView classifiedMetrics : metrics) {
long sumOfDurations = classifiedMetrics.sumOfDurations();
long failedCount = classifiedMetrics.failedCount();
metricsByStmtType.compute(classificationType(classifiedMetrics.classification()), (key, oldMetric) -> {
if (oldMetric == null) {
return new Metric(sumOfDurations, classifiedMetrics.totalCount(), failedCount);
}
oldMetric.inc(sumOfDurations, classifiedMetrics.totalCount(), failedCount);
return oldMetric;
});
}
return metricsByStmtType;
}
Aggregations