You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by vi...@apache.org on 2018/08/17 14:28:10 UTC
[drill] branch master updated: DRILL-6696: IOBE in Operator Metric
Registry
This is an automated email from the ASF dual-hosted git repository.
vitalii pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/drill.git
The following commit(s) were added to refs/heads/master by this push:
new 5dc59fb DRILL-6696: IOBE in Operator Metric Registry
5dc59fb is described below
commit 5dc59fb88fefcb32fc38a0a2b017833088bddc8a
Author: Vitalii Diravka <vi...@gmail.com>
AuthorDate: Fri Aug 17 15:23:30 2018 +0300
DRILL-6696: IOBE in Operator Metric Registry
---
.../drill/exec/ops/OperatorMetricRegistry.java | 23 +++++-----
.../java/org/apache/drill/TestOperatorMetrics.java | 51 ++++++++++++++++++++++
2 files changed, 64 insertions(+), 10 deletions(-)
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorMetricRegistry.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorMetricRegistry.java
index dcb9445..ac86702 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorMetricRegistry.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/OperatorMetricRegistry.java
@@ -32,14 +32,18 @@ import org.apache.drill.exec.proto.UserBitShared.CoreOperatorType;
import org.apache.drill.exec.record.AbstractBinaryRecordBatch;
import org.apache.drill.exec.store.parquet.columnreaders.ParquetRecordReader;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
/**
* Registry of operator metrics.
*/
public class OperatorMetricRegistry {
// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(OperatorMetricRegistry.class);
- // Mapping: operator type --> metric id --> metric name
- private static final String[][] OPERATOR_METRICS = new String[CoreOperatorType.values().length][];
+ // Mapping: key : operator type, value : metric id --> metric name
+ private static final Map<Integer, String[]> OPERATOR_METRICS = new HashMap<>();
static {
register(CoreOperatorType.SCREEN_VALUE, ScreenCreator.ScreenRoot.Metric.class);
@@ -61,13 +65,12 @@ public class OperatorMetricRegistry {
private static void register(final int operatorType, final Class<? extends MetricDef> metricDef) {
// Currently registers a metric def that has enum constants
- final MetricDef[] enumConstants = metricDef.getEnumConstants();
+ MetricDef[] enumConstants = metricDef.getEnumConstants();
if (enumConstants != null) {
- final String[] names = new String[enumConstants.length];
- for (int i = 0; i < enumConstants.length; i++) {
- names[i] = enumConstants[i].name();
- }
- OPERATOR_METRICS[operatorType] = names;
+ String[] names = Arrays.stream(enumConstants)
+ .map(MetricDef::name)
+ .toArray((String[]::new));
+ OPERATOR_METRICS.put(operatorType, names);
}
}
@@ -77,8 +80,8 @@ public class OperatorMetricRegistry {
* @param operatorType the operator type
* @return metric names if operator was registered, null otherwise
*/
- public static String[] getMetricNames(final int operatorType) {
- return OPERATOR_METRICS[operatorType];
+ public static String[] getMetricNames(int operatorType) {
+ return OPERATOR_METRICS.get(operatorType);
}
// to prevent instantiation
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestOperatorMetrics.java b/exec/java-exec/src/test/java/org/apache/drill/TestOperatorMetrics.java
new file mode 100644
index 0000000..9dd5f4c
--- /dev/null
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestOperatorMetrics.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill;
+
+import org.apache.drill.categories.OperatorTest;
+import org.apache.drill.exec.ops.OperatorMetricRegistry;
+import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.test.BaseTestQuery;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+@Category(OperatorTest.class)
+public class TestOperatorMetrics extends BaseTestQuery {
+
+ @Test
+ public void testMetricNames() {
+ assertEquals(new String[]{"BYTES_SENT"},
+ OperatorMetricRegistry.getMetricNames(UserBitShared.CoreOperatorType.SCREEN_VALUE));
+
+ assertEquals(new String[]{"SPILL_COUNT", "RETIRED1", "PEAK_BATCHES_IN_MEMORY", "MERGE_COUNT", "MIN_BUFFER",
+ "INPUT_BATCHES"},
+ OperatorMetricRegistry.getMetricNames(UserBitShared.CoreOperatorType.EXTERNAL_SORT_VALUE));
+ }
+
+ @Test
+ public void testNonExistentMetricNames() {
+ assertNull(OperatorMetricRegistry.getMetricNames(UserBitShared.CoreOperatorType.NESTED_LOOP_JOIN_VALUE));
+
+ assertNull(OperatorMetricRegistry.getMetricNames(202));
+ }
+
+}