sshiv012 commented on code in PR #9271:
URL: https://github.com/apache/texera/pull/9271#discussion_r4624547125


##########
amber/src/main/scala/org/apache/texera/web/service/ExecutionResultService.scala:
##########
@@ -403,53 +414,48 @@ class ExecutionResultService(
         val allTableStats = mutable.Map[String, Map[String, Map[String, 
Any]]]()
         newState.resultInfo
           .filter(info => {
-            // only update those operators with changing tuple count.
+            // only update those output ports with changing tuple count.
             !oldState.resultInfo
               .contains(info._1) || oldState.resultInfo(info._1).tupleCount != 
info._2.tupleCount
           })
           .foreach {
-            case (opId, info) =>
-              val oldInfo = oldState.resultInfo.getOrElse(opId, 
OperatorResultMetadata())
-              buf(opId.id) = ExecutionResultService.convertWebResultUpdate(
-                workflowIdentity,
-                executionId,
-                physicalPlan.getPhysicalOpsOfLogicalOp(opId),
-                oldInfo.tupleCount,
-                info.tupleCount
-              )
-              // using the first port for now. TODO: support multiple ports
-              val outputPortsMap = physicalPlan
-                .getPhysicalOpsOfLogicalOp(opId)
-                .headOption
-                .map(_.outputPorts)
-                .getOrElse(Map.empty)
-              val hasSingleSnapshot = outputPortsMap.values.exists {
-                case (outputPort, _, _) =>
-                  // SINGLE_SNAPSHOT is used for HTML content
-                  outputPort.mode == OutputMode.SINGLE_SNAPSHOT
+            case (globalPortId, info) =>
+              val opId = globalPortId.opId.logicalOpId
+              val portId = globalPortId.portId
+              val oldInfo = oldState.resultInfo.getOrElse(globalPortId, 
OperatorResultMetadata())
+              val outputMode = 
ExecutionResultService.outputModeOf(physicalPlan, opId, portId)
+              val isFirstPort = portId == PortIdentity()
+              // the result updates are about each operator's first output port
+              if (isFirstPort) {
+                buf(opId.id) = ExecutionResultService.convertWebResultUpdate(
+                  workflowIdentity,
+                  executionId,
+                  opId,
+                  portId,
+                  outputMode,
+                  oldInfo.tupleCount,
+                  info.tupleCount
+                )
               }
 
-              if (!hasSingleSnapshot) {
-                val storageUri = WorkflowExecutionsResource
-                  .getResultUriByLogicalPortId(
-                    executionId,
-                    opId,
-                    PortIdentity()
-                  )
-
-                if (storageUri.nonEmpty) {
-                  val globalPortIdOption = 
VFSURIFactory.decodeURI(storageUri.get).globalPortId
-                  val opStorage = 
DocumentFactory.openDocument(storageUri.get)._1
-
-                  allTableStats(opId.id) = opStorage.getTableStatistics
-                  WorkflowExecutionsResource.updateResultSize(
-                    executionId,
-                    globalPortIdOption.get,
-                    opStorage.getTotalFileSize
-                  )
-                  
WorkflowExecutionsResource.updateRuntimeStatsSize(executionId)
-                  
WorkflowExecutionsResource.updateConsoleMessageSize(executionId, opId)
-                }
+              // SINGLE_SNAPSHOT is used for HTML content, which is not a table
+              if (outputMode != OutputMode.SINGLE_SNAPSHOT) {
+                WorkflowExecutionsResource
+                  .getResultUriByLogicalPortId(executionId, opId, portId)
+                  .foreach { storageUri =>
+                    val opStorage = DocumentFactory.openDocument(storageUri)._1
+                    // the table statistics are the first port's, as the 
result updates are
+                    if (isFirstPort) {
+                      allTableStats(opId.id) = opStorage.getTableStatistics
+                    }
+                    WorkflowExecutionsResource.updateResultSize(

Review Comment:
   Done in 60f03c782. The port-0 branch is gone, and #9272 is folded in. Both 
`updates` and `tableStats` are keyed by operator id, then by port index, for 
every port including 0. Port 1 now gets its own table statistics.



##########
amber/src/main/scala/org/apache/texera/web/service/ExecutionResultService.scala:
##########
@@ -403,53 +414,48 @@ class ExecutionResultService(
         val allTableStats = mutable.Map[String, Map[String, Map[String, 
Any]]]()
         newState.resultInfo
           .filter(info => {
-            // only update those operators with changing tuple count.
+            // only update those output ports with changing tuple count.
             !oldState.resultInfo
               .contains(info._1) || oldState.resultInfo(info._1).tupleCount != 
info._2.tupleCount
           })
           .foreach {
-            case (opId, info) =>
-              val oldInfo = oldState.resultInfo.getOrElse(opId, 
OperatorResultMetadata())
-              buf(opId.id) = ExecutionResultService.convertWebResultUpdate(
-                workflowIdentity,
-                executionId,
-                physicalPlan.getPhysicalOpsOfLogicalOp(opId),
-                oldInfo.tupleCount,
-                info.tupleCount
-              )
-              // using the first port for now. TODO: support multiple ports
-              val outputPortsMap = physicalPlan
-                .getPhysicalOpsOfLogicalOp(opId)
-                .headOption
-                .map(_.outputPorts)
-                .getOrElse(Map.empty)
-              val hasSingleSnapshot = outputPortsMap.values.exists {
-                case (outputPort, _, _) =>
-                  // SINGLE_SNAPSHOT is used for HTML content
-                  outputPort.mode == OutputMode.SINGLE_SNAPSHOT
+            case (globalPortId, info) =>
+              val opId = globalPortId.opId.logicalOpId
+              val portId = globalPortId.portId
+              val oldInfo = oldState.resultInfo.getOrElse(globalPortId, 
OperatorResultMetadata())
+              val outputMode = 
ExecutionResultService.outputModeOf(physicalPlan, opId, portId)
+              val isFirstPort = portId == PortIdentity()
+              // the result updates are about each operator's first output port
+              if (isFirstPort) {
+                buf(opId.id) = ExecutionResultService.convertWebResultUpdate(
+                  workflowIdentity,
+                  executionId,
+                  opId,
+                  portId,
+                  outputMode,
+                  oldInfo.tupleCount,
+                  info.tupleCount
+                )
               }
 
-              if (!hasSingleSnapshot) {
-                val storageUri = WorkflowExecutionsResource
-                  .getResultUriByLogicalPortId(
-                    executionId,
-                    opId,
-                    PortIdentity()
-                  )
-
-                if (storageUri.nonEmpty) {
-                  val globalPortIdOption = 
VFSURIFactory.decodeURI(storageUri.get).globalPortId
-                  val opStorage = 
DocumentFactory.openDocument(storageUri.get)._1
-
-                  allTableStats(opId.id) = opStorage.getTableStatistics
-                  WorkflowExecutionsResource.updateResultSize(
-                    executionId,
-                    globalPortIdOption.get,
-                    opStorage.getTotalFileSize
-                  )
-                  
WorkflowExecutionsResource.updateRuntimeStatsSize(executionId)
-                  
WorkflowExecutionsResource.updateConsoleMessageSize(executionId, opId)
-                }
+              // SINGLE_SNAPSHOT is used for HTML content, which is not a table
+              if (outputMode != OutputMode.SINGLE_SNAPSHOT) {
+                WorkflowExecutionsResource
+                  .getResultUriByLogicalPortId(executionId, opId, portId)
+                  .foreach { storageUri =>
+                    val opStorage = DocumentFactory.openDocument(storageUri)._1

Review Comment:
   Done in 1ca187700. The diff handler now looks up and opens each changed 
port's document once, and passes it to `convertWebResultUpdate`, which no 
longer opens it itself. The size update no longer reads the document here: as 
of #9049, `onResultUpdate` records each port's size and row count.



##########
amber/src/main/scala/org/apache/texera/web/service/ExecutionResultService.scala:
##########
@@ -403,53 +414,48 @@ class ExecutionResultService(
         val allTableStats = mutable.Map[String, Map[String, Map[String, 
Any]]]()
         newState.resultInfo
           .filter(info => {
-            // only update those operators with changing tuple count.
+            // only update those output ports with changing tuple count.
             !oldState.resultInfo
               .contains(info._1) || oldState.resultInfo(info._1).tupleCount != 
info._2.tupleCount
           })
           .foreach {
-            case (opId, info) =>
-              val oldInfo = oldState.resultInfo.getOrElse(opId, 
OperatorResultMetadata())
-              buf(opId.id) = ExecutionResultService.convertWebResultUpdate(
-                workflowIdentity,
-                executionId,
-                physicalPlan.getPhysicalOpsOfLogicalOp(opId),
-                oldInfo.tupleCount,
-                info.tupleCount
-              )
-              // using the first port for now. TODO: support multiple ports
-              val outputPortsMap = physicalPlan
-                .getPhysicalOpsOfLogicalOp(opId)
-                .headOption
-                .map(_.outputPorts)
-                .getOrElse(Map.empty)
-              val hasSingleSnapshot = outputPortsMap.values.exists {
-                case (outputPort, _, _) =>
-                  // SINGLE_SNAPSHOT is used for HTML content
-                  outputPort.mode == OutputMode.SINGLE_SNAPSHOT
+            case (globalPortId, info) =>
+              val opId = globalPortId.opId.logicalOpId
+              val portId = globalPortId.portId
+              val oldInfo = oldState.resultInfo.getOrElse(globalPortId, 
OperatorResultMetadata())
+              val outputMode = 
ExecutionResultService.outputModeOf(physicalPlan, opId, portId)
+              val isFirstPort = portId == PortIdentity()
+              // the result updates are about each operator's first output port
+              if (isFirstPort) {
+                buf(opId.id) = ExecutionResultService.convertWebResultUpdate(
+                  workflowIdentity,
+                  executionId,
+                  opId,
+                  portId,
+                  outputMode,
+                  oldInfo.tupleCount,
+                  info.tupleCount
+                )
               }
 
-              if (!hasSingleSnapshot) {
-                val storageUri = WorkflowExecutionsResource
-                  .getResultUriByLogicalPortId(
-                    executionId,
-                    opId,
-                    PortIdentity()
-                  )
-
-                if (storageUri.nonEmpty) {
-                  val globalPortIdOption = 
VFSURIFactory.decodeURI(storageUri.get).globalPortId
-                  val opStorage = 
DocumentFactory.openDocument(storageUri.get)._1
-
-                  allTableStats(opId.id) = opStorage.getTableStatistics
-                  WorkflowExecutionsResource.updateResultSize(
-                    executionId,
-                    globalPortIdOption.get,
-                    opStorage.getTotalFileSize
-                  )
-                  
WorkflowExecutionsResource.updateRuntimeStatsSize(executionId)
-                  
WorkflowExecutionsResource.updateConsoleMessageSize(executionId, opId)
-                }
+              // SINGLE_SNAPSHOT is used for HTML content, which is not a table
+              if (outputMode != OutputMode.SINGLE_SNAPSHOT) {
+                WorkflowExecutionsResource
+                  .getResultUriByLogicalPortId(executionId, opId, portId)
+                  .foreach { storageUri =>
+                    val opStorage = DocumentFactory.openDocument(storageUri)._1
+                    // the table statistics are the first port's, as the 
result updates are
+                    if (isFirstPort) {
+                      allTableStats(opId.id) = opStorage.getTableStatistics
+                    }
+                    WorkflowExecutionsResource.updateResultSize(
+                      executionId,
+                      VFSURIFactory.decodeURI(storageUri).globalPortId.get,
+                      opStorage.getTotalFileSize
+                    )
+                    
WorkflowExecutionsResource.updateRuntimeStatsSize(executionId)
+                    
WorkflowExecutionsResource.updateConsoleMessageSize(executionId, opId)
+                  }

Review Comment:
   Done. The URI decoding is gone, because size and count are now recorded in 
`onResultUpdate` from the `globalPortId` it already has. In 1ca187700, 
`updateRuntimeStatsSize` runs once per poll, and `updateConsoleMessageSize` 
once per operator with a changed table port.



##########
amber/src/test/scala/org/apache/texera/web/service/ExecutionResultServiceSpec.scala:
##########
@@ -1262,30 +1529,61 @@ class ExecutionResultServiceSpec
 
       polling.cancelCount shouldBe 1
       val resultInfo = 
fixture.workflowStateStore.resultStore.getState.resultInfo
-      resultInfo.keySet.map(_.id) shouldBe Set("erss-final-snapshot", 
"erss-final-delta")
+      resultInfo.keySet shouldBe Set(
+        globalPortIdOf("erss-final-snapshot"),
+        globalPortIdOf("erss-final-delta")
+      )
       // Counts come from the documents themselves, so the two operators must 
not
       // be reported with the same count.
-      resultInfo(OperatorIdentity("erss-final-snapshot")).tupleCount shouldBe 3
-      resultInfo(OperatorIdentity("erss-final-delta")).tupleCount shouldBe 2
+      resultInfo(globalPortIdOf("erss-final-snapshot")).tupleCount shouldBe 3
+      resultInfo(globalPortIdOf("erss-final-delta")).tupleCount shouldBe 2
       // A SET_SNAPSHOT result is replaced wholesale, so its content can change
       // without its count changing; the random change detector is what makes 
the
       // frontend re-read it. A delta is append-only and needs no such nudge.
-      resultInfo(OperatorIdentity("erss-final-snapshot")).changeDetector 
should not be empty
-      resultInfo(OperatorIdentity("erss-final-delta")).changeDetector shouldBe 
""
+      resultInfo(globalPortIdOf("erss-final-snapshot")).changeDetector should 
not be empty
+      resultInfo(globalPortIdOf("erss-final-delta")).changeDetector shouldBe ""

Review Comment:
   Fixed the comment in 1ca187700. It now says the random detector makes the 
diff handler run, but the handler still sends only the ports whose row count 
changed.



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