PG1204 commented on code in PR #8552:
URL: https://github.com/apache/texera/pull/8552#discussion_r4049959205


##########
frontend/src/app/workspace/service/heatmap/runtime-statistics-mapper.ts:
##########
@@ -0,0 +1,80 @@
+/**
+ * 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.
+ */
+
+import { OperatorRuntimeStatus, OperatorState } from 
"../../types/execute-workflow.interface";
+import { WorkflowRuntimeStatistics } from 
"../../../dashboard/type/workflow-runtime-statistics";
+
+/**
+ * Maps a persisted per-operator status code back to an OperatorState.
+ *
+ * The engine persists the codes written by Utils.maptoStatusCode: 0 =
+ * Uninitialized/Ready, 1 = Running, 2 = Paused, 3 = Completed. Codes 4
+ * (Failed), 5 (Killed) and -1 (other) have no OperatorState member, so they
+ * fall back to the neutral Uninitialized rather than a wrong state.
+ */
+export function operatorStateFromStatusCode(code: number): OperatorState {
+  switch (code) {
+    case 0:
+      return OperatorState.Uninitialized;
+    case 1:
+      return OperatorState.Running;
+    case 2:
+      return OperatorState.Paused;
+    case 3:
+      return OperatorState.Completed;
+    default:
+      return OperatorState.Uninitialized;
+  }
+}
+
+/**
+ * Reduces a persisted runtime-statistics time series to the latest snapshot
+ * per operator (by timestamp; the later row wins a tie, matching write
+ * order), mapped to the wire shape WorkflowStatusService ingests.
+ *
+ * Port-level metrics are not persisted historically, so the port maps are
+ * empty — restored port labels read 0, like a resetStatus snapshot.
+ */
+export function toOperatorRuntimeStatusMap(rows: WorkflowRuntimeStatistics[]): 
Record<string, OperatorRuntimeStatus> {
+  const latestByOperator: Record<string, WorkflowRuntimeStatistics> = {};
+  for (const row of rows) {
+    const seen = latestByOperator[row.operatorId];
+    if (seen === undefined || row.timestamp >= seen.timestamp) {
+      latestByOperator[row.operatorId] = row;
+    }
+  }
+
+  const result: Record<string, OperatorRuntimeStatus> = {};
+  for (const [operatorId, row] of Object.entries(latestByOperator)) {
+    result[operatorId] = {
+      operatorState: operatorStateFromStatusCode(row.status),
+      aggregatedInputRowCount: row.inputTupleCount,
+      aggregatedInputSize: row.inputTupleSize,
+      inputPortMetrics: {},

Review Comment:
   Fixed. Confirmed the chain, including that it sticks via 
getCurrentStatistics() on operator-add.
   
   {} couldn't just be replaced, since resetStatus already uses it to mean 
"every port measured zero". So the port maps are now optional: the mapper omits 
them, and changeOperatorStatistics skips the port loops when they're absent.
   
   Added specs for both sides.



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

Reply via email to