gortiz commented on code in PR #18458:
URL: https://github.com/apache/pinot/pull/18458#discussion_r3268042901


##########
pinot-query-runtime/src/main/java/org/apache/pinot/query/runtime/plan/MultiStageStatsTreeDecoder.java:
##########
@@ -0,0 +1,134 @@
+/**
+ * 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.pinot.query.runtime.plan;
+
+import com.google.protobuf.ByteString;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.pinot.common.datatable.StatMap;
+import org.apache.pinot.common.proto.Worker;
+import org.apache.pinot.query.runtime.operator.OperatorTypeDescriptor;
+import org.apache.pinot.query.runtime.operator.OperatorTypeRegistry;
+
+
+/**
+ * Broker-side decoder turning {@link Worker.MultiStageStatsTree} payloads 
into {@link StageStatsTreeNode} instances
+ * the broker accumulates by stage id (and merges across worker reports for 
the same stage).
+ *
+ * <p>Pairs with {@link MultiStageStatsTreeEncoder} on the server side.
+ */
+public final class MultiStageStatsTreeDecoder {
+  private MultiStageStatsTreeDecoder() {
+  }
+
+  /**
+   * Thrown when a payload cannot be decoded — usually because the operator 
type id is unknown to this broker
+   * (newer-server / older-broker case). The broker logs and marks the stage 
{@code mergeFailed}; the query continues.
+   */
+  public static class DecodeFailedException extends Exception {
+    public DecodeFailedException(String message) {
+      super(message);
+    }
+
+    public DecodeFailedException(String message, Throwable cause) {
+      super(message, cause);
+    }
+  }
+
+  /**
+   * Decodes a single {@link Worker.StageStatsNode} (recursive). Used directly 
when the caller already has a node and
+   * a known stage id.
+   */
+  public static StageStatsTreeNode decodeNode(Worker.StageStatsNode node)
+      throws DecodeFailedException {
+    OperatorTypeDescriptor type = 
OperatorTypeRegistry.fromId(node.getOperatorTypeId());
+    if (type == null) {
+      throw new DecodeFailedException("Unknown operator type id: " + 
node.getOperatorTypeId());
+    }
+    StatMap<?> statMap;
+    try {
+      statMap = deserializeStatMap(node.getStatMap(), type);
+    } catch (IOException e) {
+      throw new DecodeFailedException("Failed to deserialize StatMap for 
operator type " + type.name(), e);
+    }
+    List<StageStatsTreeNode> children = new 
ArrayList<>(node.getChildrenCount());

Review Comment:
   1. I don't remember if I added a limit, but there would be other problems in 
case we find queries that deep.
   2. That is a valid concern, but the only difference is that now we multiply 
that by the number of servers. Using the normal stats mode we still keep the 
same info (not grouping by server) on single servers (and eventually on the 
broker when it is received). The advantage of grouping by server as well is 
that we will be able to provide stats per server, which is super useful. I 
guess we can create two submodes in the future: One that groups by server and 
one that does not. For now, given this feature is disabled by default, I think 
the current behavior is fine



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to