[ 
https://issues.apache.org/jira/browse/HIVE-25165?focusedWorklogId=605851&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-605851
 ]

ASF GitHub Bot logged work on HIVE-25165:
-----------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Jun/21 11:30
            Start Date: 03/Jun/21 11:30
    Worklog Time Spent: 10m 
      Work Description: aasha commented on a change in pull request #2321:
URL: https://github.com/apache/hive/pull/2321#discussion_r644714176



##########
File path: ql/src/java/org/apache/hadoop/hive/ql/exec/repl/ReplStatsTracker.java
##########
@@ -0,0 +1,132 @@
+/*
+ * 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.hive.ql.exec.repl;
+
+import org.apache.commons.collections4.map.ListOrderedMap;
+import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tracks the replication statistics per event type.
+ */
+public class ReplStatsTracker {
+
+  // Maintains the descriptive statistics per event type.
+  private HashMap<String, DescriptiveStatistics> descMap;
+
+  // Maintains the top K costliest eventId's
+  private HashMap<String, ListOrderedMap<Long, Long>> topKEvents;
+  // Number of top events to maintain.
+  private final int k;
+
+  public ReplStatsTracker(int k) {
+    this.k = k;
+    descMap = new HashMap<>();
+    topKEvents = new HashMap<>();
+  }
+
+  /**
+   * Adds an entry for tracking.
+   * @param eventType the type of event.
+   * @param eventId the event id.
+   * @param timeTaken time taken to process the event.
+   */
+  public void addEntry(String eventType, String eventId, long timeTaken) {
+    // Update the entry in the descriptive statistics.
+    DescriptiveStatistics descStatistics = descMap.get(eventType);
+    if (descStatistics == null) {
+      descStatistics = new DescriptiveStatistics();
+      descStatistics.addValue(timeTaken);
+      descMap.put(eventType, descStatistics);
+    } else {
+      descStatistics.addValue(timeTaken);
+    }
+
+    // Tracking for top K events, Maintain the list in descending order.
+    ListOrderedMap<Long, Long> topKEntries = topKEvents.get(eventType);
+    if (topKEntries == null) {
+      topKEntries = new ListOrderedMap<>();
+      topKEntries.put(Long.parseLong(eventId), timeTaken);
+      topKEvents.put(eventType, topKEntries);
+    } else {
+      // Get the index of insertion, by descending order.
+      int index = Collections.binarySearch(new 
ArrayList(topKEntries.values()), timeTaken, Collections.reverseOrder());

Review comment:
       where are you sorting this?




-- 
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:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 605851)
    Time Spent: 0.5h  (was: 20m)

> Generate & track statistics per event type for incremental load in 
> replication metrics
> --------------------------------------------------------------------------------------
>
>                 Key: HIVE-25165
>                 URL: https://issues.apache.org/jira/browse/HIVE-25165
>             Project: Hive
>          Issue Type: Improvement
>            Reporter: Ayush Saxena
>            Assignee: Ayush Saxena
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Generate and track statistics like mean, median. standard deviation, variance 
> etc per event type during incremental load and store them in replication 
> statisticsĀ 



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to