Jackie-Jiang commented on a change in pull request #6845:
URL: https://github.com/apache/incubator-pinot/pull/6845#discussion_r631367102



##########
File path: 
pinot-spi/src/main/java/org/apache/pinot/spi/data/readers/GenericRow.java
##########
@@ -120,6 +126,49 @@ public boolean hasNullValues() {
     return !_nullValueFields.isEmpty();
   }
 
+  /**
+   * @return a deep copy of the generic row
+   */
+  public GenericRow copy() {
+    GenericRow copy = new GenericRow();
+    copy.init(this);
+    for (Map.Entry<String, Object> entry : new 
HashSet<>(copy._fieldToValueMap.entrySet())) {
+      copy.putValue(entry.getKey(), copy(entry.getValue()));
+    }
+    return copy;
+  }
+
+  /**
+   * @return a deep copy of the object.
+   */
+  private Object copy(Object value) {
+    if (value == null) {
+      return null;
+    } else if (value instanceof Map) {
+      Map<String, Object> map = new HashMap<>();
+      for (String key : ((Map<String, Object>) value).keySet()) {
+        map.put(key, copy(((Map<String, Object>) value).get(key)));
+      }

Review comment:
       This will be more efficient because creating a map from another map is 
faster than adding each individual key-value pairs. After that we don't have 
extra map lookups




-- 
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



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org
For additional commands, e-mail: commits-h...@pinot.apache.org

Reply via email to