You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by GitBox <gi...@apache.org> on 2018/08/17 14:28:08 UTC

[GitHub] vdiravka closed pull request #1436: DRILL-6696: IOBE in Operator Metric Registry

vdiravka closed pull request #1436: DRILL-6696: IOBE in Operator Metric Registry
URL: https://github.com/apache/drill/pull/1436
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

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 dcb944512cf..ac867020de1 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.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 @@
 
   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 @@ private static void register(final int operatorType, final Class<? extends Metri
    * @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 00000000000..9dd5f4c440b
--- /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));
+  }
+
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services