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


##########
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:
   Added a guard



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