Search in sources :

Example 1 with StatementType

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()));
}
Also used : StatementType(io.crate.planner.Plan.StatementType) Classification(io.crate.planner.operators.StatementClassifier.Classification) ArrayList(java.util.ArrayList) MetricsView(io.crate.metadata.sys.MetricsView) Test(org.junit.Test)

Example 2 with StatementType

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;
}
Also used : HashMap(java.util.HashMap) StatementType(io.crate.planner.Plan.StatementType) MetricsView(io.crate.metadata.sys.MetricsView)

Aggregations

MetricsView (io.crate.metadata.sys.MetricsView)2 StatementType (io.crate.planner.Plan.StatementType)2 Classification (io.crate.planner.operators.StatementClassifier.Classification)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Test (org.junit.Test)1