ankitsinghal commented on a change in pull request #722: HBASE-23065 [hbtop] 
Top-N heavy hitter user and client drill downs
URL: https://github.com/apache/hbase/pull/722#discussion_r338413219
 
 

 ##########
 File path: 
hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/mode/ModeStrategyUtils.java
 ##########
 @@ -0,0 +1,94 @@
+/**
+ * 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.hadoop.hbase.hbtop.mode;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import org.apache.hadoop.hbase.hbtop.Record;
+import org.apache.hadoop.hbase.hbtop.RecordFilter;
+import org.apache.hadoop.hbase.hbtop.field.Field;
+import org.apache.hadoop.hbase.hbtop.field.FieldInfo;
+import org.apache.hadoop.hbase.hbtop.field.FieldValue;
+import org.apache.hadoop.hbase.hbtop.field.FieldValueType;
+
+import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
+
+public final class ModeStrategyUtils {
+  private ModeStrategyUtils() {
+
+  }
+
+  /**
+   * Filter records as per the supplied filters,
+   * @param records records to be processed
+   * @param filters List of filters
+   * @return filtered records
+   */
+  public static List<Record> applyFilterAndGet(List<Record> records,
+      List<RecordFilter> filters) {
+    if (filters != null && !filters.isEmpty()) {
+      return records.stream().filter(r -> filters.stream().allMatch(f -> 
f.execute(r)))
+          .collect(Collectors.toList());
+    }
+    return records;
+  }
+
+  /**
+   * Form new record list with records formed by only fields provided through 
fieldInfo and
+   * add a count field for each record with value 1
+   *
+   * We are doing two operation of selecting and adding new field
+   * because of saving some CPU cycles on rebuilding the record again
+   *
+   * @param fieldInfos List of FieldInfos required in the record
+   * @param records List of records which needs to be processed
+   * @param countField Field which needs to be added with value 1 for each 
record
+   * @return records after selecting required fields and adding count field
+   */
+  public static List<Record> selectModeFieldsAndAddCountField(List<FieldInfo> 
fieldInfos,
 
 Review comment:
   Yeah, Let me see if I can make it more readable.

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


With regards,
Apache Git Services

Reply via email to