This is an automated email from the ASF dual-hosted git repository.

github-merge-queue[bot] pushed a commit to branch 
gh-readonly-queue/main/pr-9049-48356940005191408ed92a718d1f5a694b67417b
in repository https://gitbox.apache.org/repos/asf/texera.git

commit 8cfacf2f062d7855073132cda5134ed564d6b8c7
Author: Meng Wang <[email protected]>
AuthorDate: Fri Nov 6 23:36:36 2026 +0000

    feat(amber): record each result port's output mode and row count (#9049)
    
    ### What changes were proposed in this PR?
    
    Records two facts per result port in `operator_port_executions`, so a
    finished execution's results can be listed without the computing unit
    (#5363):
    
    - `output_mode` (new `output_mode_enum`): whether the port's result is a
    paginated table or a visualization. Today only the engine's physical
    plan knows this, and it lives in the CU. The engine already looks up the
    output port when it creates the port's storage, so
    `OperatorPortResultUriAvailable` now carries the port's declared mode,
    and the row is inserted with it.
    - `result_count`: the number of rows, written with `result_size` in one
    update each time the results are polled and once more when the run ends,
    so it does not depend on an open browser tab. Visualization
    (`SINGLE_SNAPSHOT`) ports keep a null count; they are never paged. Like
    `result_size`, it is recorded only for an operator's first result port
    for now, so the other ports of an operator such as `Split` keep a null
    count.
    
    `result_size` moves with it: it was written from the websocket diff
    handler, which runs once per connected browser and not at all without
    one.
    
    Schema change: `sql/updates/52.sql` (idempotent), `texera_ddl.sql`, and
    a `changelog.xml` entry. Existing rows keep both columns null. Nothing
    reads the columns yet; that is #8995.
    
    ### Any related issues, documentation, discussions?
    
    Closes #8994. Part of #5363, proposed in #8945.
    
    ### How was this PR tested?
    
    - `ExecutionResultServiceSpec`: the mode carried by the event is
    persisted; every output mode maps to the stored value of its name and an
    unrecognized one is rejected; a run that ends with no browser connected
    records its table port's size and count (this fails on the previous
    code), and a `SINGLE_SNAPSHOT` port records no count.
    - `WorkflowExecutionsResourceSpec`: `updateResultSizeAndCount` sets both
    columns on the matching row.
    - Removed the mode and count writes and confirmed exactly the three
    corresponding tests fail.
    - Applied `52.sql` twice to a local database (the second run is a
    no-op), and ran the full `texera_ddl.sql` into a scratch database.
    
    ### Was this PR authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (claude-opus-5-5)
---
 .../architecture/coordinator/ClientEvent.scala     |  4 +-
 .../scheduling/RegionExecutionManager.scala        | 10 +--
 .../user/workflow/WorkflowExecutionsResource.scala | 13 +--
 .../web/service/ExecutionResultService.scala       | 41 ++++++++--
 .../workflow/WorkflowExecutionsResourceSpec.scala  | 12 +--
 .../web/service/ExecutionResultServiceSpec.scala   | 92 +++++++++++++++++++---
 .../org/apache/texera/amber/core/workflow.proto    |  3 +
 sql/changelog.xml                                  |  5 ++
 sql/texera_ddl.sql                                 |  7 ++
 sql/updates/52.sql                                 | 49 ++++++++++++
 10 files changed, 199 insertions(+), 37 deletions(-)

diff --git 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/ClientEvent.scala
 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/ClientEvent.scala
index e9e1e8ee6c..42e5c14af2 100644
--- 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/ClientEvent.scala
+++ 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/ClientEvent.scala
@@ -21,6 +21,7 @@ package 
org.apache.texera.amber.engine.architecture.coordinator
 
 import org.apache.texera.amber.core.virtualidentity.ActorVirtualIdentity
 import org.apache.texera.amber.core.workflow.GlobalPortIdentity
+import org.apache.texera.amber.core.workflow.OutputPort.OutputMode
 import 
org.apache.texera.amber.engine.architecture.rpc.controlreturns.WorkflowAggregatedState
 import 
org.apache.texera.amber.engine.common.ambermessage.WorkflowFIFOMessagePayload
 import 
org.apache.texera.amber.engine.common.executionruntimestate.OperatorMetrics
@@ -33,7 +34,8 @@ case class ExecutionStateUpdate(state: 
WorkflowAggregatedState) extends ClientEv
 
 case class OperatorPortResultUriAvailable(
     globalPortId: GlobalPortIdentity,
-    uri: URI
+    uri: URI,
+    mode: OutputMode
 ) extends ClientEvent
 
 case class ExecutionStatsUpdate(operatorMetrics: Map[String, OperatorMetrics]) 
extends ClientEvent
diff --git 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/scheduling/RegionExecutionManager.scala
 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/scheduling/RegionExecutionManager.scala
index e884a6ba30..51910a5041 100644
--- 
a/amber/src/main/scala/org/apache/texera/amber/engine/architecture/scheduling/RegionExecutionManager.scala
+++ 
b/amber/src/main/scala/org/apache/texera/amber/engine/architecture/scheduling/RegionExecutionManager.scala
@@ -687,19 +687,15 @@ class RegionExecutionManager(
         // (The inner LoopEnd of a nested loop additionally drops its output
         // once per outer iteration on the Python worker side in
         // MainLoop._process_state_frame, which is orthogonal to this.)
-        val reuseStorage =
-          region
-            .getOperator(outputPortId.opId)
-            .outputPorts(outputPortId.portId)
-            ._1
-            .reuseStorage
+        val outputPort = 
region.getOperator(outputPortId.opId).outputPorts(outputPortId.portId)._1
+        val reuseStorage = outputPort.reuseStorage
         Seq((resultURI, schema), (stateURI, State.schema)).foreach {
           case (uri, sch) =>
             DocumentFactory.createOrReuseDocument(uri, sch, reuseStorage)
         }
         if (!isRestart) {
           asyncRPCClient.sendToClient(
-            OperatorPortResultUriAvailable(outputPortId, resultURI)
+            OperatorPortResultUriAvailable(outputPortId, resultURI, 
outputPort.mode)
           )
         }
     }
diff --git 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala
 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala
index 1cc3692ae8..febca649a9 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResource.scala
@@ -408,20 +408,23 @@ object WorkflowExecutionsResource {
   }
 
   /**
-    * Updates the result size of the corresponding Iceberg document in the 
database.
+    * Updates the size and row count stored for this port's result in 
operator_port_executions.
     *
     * @param eid          Execution ID associated with the result.
     * @param globalPortId Global port identifier for the operator output.
     * @param size         Size of the result in bytes.
+    * @param count        Number of rows in the result.
     */
-  def updateResultSize(
+  def updateResultSizeAndCount(
       eid: ExecutionIdentity,
       globalPortId: GlobalPortIdentity,
-      size: Long
+      size: Long,
+      count: Long
   ): Unit = {
     context
       .update(OPERATOR_PORT_EXECUTIONS)
       .set(OPERATOR_PORT_EXECUTIONS.RESULT_SIZE, java.lang.Long.valueOf(size))
+      .set(OPERATOR_PORT_EXECUTIONS.RESULT_COUNT, 
java.lang.Long.valueOf(count))
       .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(eid.id.toInt))
       
.and(OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID.eq(globalPortId.serializeAsString))
       .execute()
@@ -449,7 +452,7 @@ object WorkflowExecutionsResource {
   }
 
   /**
-    * Stores an already-measured runtime statistics size, mirroring 
updateResultSize.
+    * Stores an already-measured runtime statistics size, mirroring 
updateResultSizeAndCount.
     *
     * @param eid  Execution ID associated with the runtime statistics document.
     * @param size Size of the runtime statistics in bytes.
@@ -487,7 +490,7 @@ object WorkflowExecutionsResource {
   }
 
   /**
-    * Stores an already-measured console message size, mirroring 
updateResultSize.
+    * Stores an already-measured console message size, mirroring 
updateResultSizeAndCount.
     *
     * @param eid  Execution ID associated with the console message.
     * @param opId Operator ID of the corresponding operator.
diff --git 
a/amber/src/main/scala/org/apache/texera/web/service/ExecutionResultService.scala
 
b/amber/src/main/scala/org/apache/texera/web/service/ExecutionResultService.scala
index 4e3efc5fdb..b29d6dce27 100644
--- 
a/amber/src/main/scala/org/apache/texera/web/service/ExecutionResultService.scala
+++ 
b/amber/src/main/scala/org/apache/texera/web/service/ExecutionResultService.scala
@@ -36,6 +36,7 @@ import org.apache.texera.amber.core.storage.result._
 import org.apache.texera.amber.core.tuple.Tuple
 import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde.SerdeOps
 import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.enums.OutputModeEnum
 import 
org.apache.texera.dao.jooq.generated.tables.daos.OperatorPortExecutionsDao
 import org.apache.texera.dao.jooq.generated.tables.pojos.OperatorPortExecutions
 import org.apache.texera.amber.core.virtualidentity.{
@@ -96,11 +97,26 @@ object ExecutionResultService {
     pojo.setWorkflowExecutionId(executionId.id.toInt)
     pojo.setGlobalPortId(evt.globalPortId.serializeAsString)
     pojo.setResultUri(evt.uri.toString)
+    pojo.setOutputMode(toOutputModeEnum(evt.mode))
     new OperatorPortExecutionsDao(
       SqlServer.getInstance().createDSLContext().configuration()
     ).insert(pojo)
   }
 
+  /**
+    * The stored form of a port's output mode. Recorded with the URI so that a 
finished
+    * execution's results can be listed without the engine's physical plan 
(#8994).
+    * output_mode_enum in sql/texera_ddl.sql mirrors OutputMode.
+    */
+  private[service] def toOutputModeEnum(mode: OutputMode): OutputModeEnum =
+    mode match {
+      case OutputMode.SET_SNAPSHOT    => OutputModeEnum.SET_SNAPSHOT
+      case OutputMode.SET_DELTA       => OutputModeEnum.SET_DELTA
+      case OutputMode.SINGLE_SNAPSHOT => OutputModeEnum.SINGLE_SNAPSHOT
+      case OutputMode.Unrecognized(_) =>
+        throw new RuntimeException(s"Unrecognized output mode: $mode")
+    }
+
   private val defaultPageSize: Int = 5
 
   /**
@@ -361,15 +377,9 @@ class ExecutionResultService(
                   )
 
                 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)
                 }
@@ -460,7 +470,8 @@ class ExecutionResultService(
             VFSURIFactory.decodeURI(uri).globalPortId.exists(_.portId == 
PortIdentity())
           )
           .map(uri => {
-            val count = DocumentFactory.openDocument(uri)._1.getCount.toInt
+            val document = DocumentFactory.openDocument(uri)._1
+            val count = document.getCount
 
             val globalPortIdOption = VFSURIFactory.decodeURI(uri).globalPortId
 
@@ -471,11 +482,25 @@ class ExecutionResultService(
               .map(_._1.mode)
               .head
 
+            // Recorded here, on every poll and once more when the run ends, 
rather than in the
+            // diff handler, which runs once per connected browser and not at 
all without one.
+            if (mode != OutputMode.SINGLE_SNAPSHOT) {
+              WorkflowExecutionsResource.updateResultSizeAndCount(
+                executionId,
+                globalPortIdOption.get,
+                document.getTotalFileSize,
+                count
+              )
+            }
+
             val changeDetector =
               if (mode == OutputMode.SET_SNAPSHOT) {
                 UUID.randomUUID.toString
               } else ""
-            (globalPortIdOption.get.opId.logicalOpId, 
OperatorResultMetadata(count, changeDetector))
+            (
+              globalPortIdOption.get.opId.logicalOpId,
+              OperatorResultMetadata(count.toInt, changeDetector)
+            )
           })
           .toMap
       }
diff --git 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
index 428a011e3a..30e0acc185 100644
--- 
a/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/web/resource/dashboard/user/workflow/WorkflowExecutionsResourceSpec.scala
@@ -34,6 +34,7 @@ import 
org.apache.texera.amber.core.workflow.{GlobalPortIdentity, PortIdentity}
 import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde.SerdeOps
 import org.apache.texera.auth.{JwtAuth, SessionUser}
 import org.apache.texera.dao.MockTexeraDB
+import org.apache.texera.amber.core.workflow.OutputPort.OutputMode
 import org.apache.texera.dao.jooq.generated.enums.UserWarehouseFlavorEnum
 import org.apache.texera.dao.jooq.generated.Tables._
 import org.apache.texera.dao.jooq.generated.enums.{
@@ -358,7 +359,7 @@ class WorkflowExecutionsResourceSpec
   ): Unit =
     ExecutionResultService.persistOperatorPortResultUri(
       eid,
-      OperatorPortResultUriAvailable(globalPortId, uri)
+      OperatorPortResultUriAvailable(globalPortId, uri, 
OutputMode.SET_SNAPSHOT)
     )
 
   // ─── existing tests (preserved) ───────────────────────────────────────────
@@ -703,9 +704,9 @@ class WorkflowExecutionsResourceSpec
     }
   }
 
-  // ─── new: updateResultSize ────────────────────────────────────────────────
+  // ─── new: updateResultSizeAndCount ────────────────────────────────────────
 
-  "updateResultSize" should "set RESULT_SIZE on the matching (eid, 
globalPortId) row" in {
+  "updateResultSizeAndCount" should "set RESULT_SIZE and RESULT_COUNT on the 
matching (eid, globalPortId) row" in {
     val execution = insertExecution()
     val eid = ExecutionIdentity(execution.getEid.longValue())
     val globalPortId = GlobalPortIdentity(
@@ -719,7 +720,7 @@ class WorkflowExecutionsResourceSpec
       URI.create("vfs:///r")
     )
 
-    WorkflowExecutionsResource.updateResultSize(eid, globalPortId, 4096L)
+    WorkflowExecutionsResource.updateResultSizeAndCount(eid, globalPortId, 
4096L, 25L)
 
     val row = getDSLContext
       .selectFrom(OPERATOR_PORT_EXECUTIONS)
@@ -727,6 +728,7 @@ class WorkflowExecutionsResourceSpec
       
.and(OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID.eq(globalPortId.serializeAsString))
       .fetchOne()
     assert(row.getResultSize == 4096)
+    assert(row.getResultCount == 25L)
   }
 
   it should "store a >2GiB size without truncation (#6978)" in {
@@ -741,7 +743,7 @@ class WorkflowExecutionsResourceSpec
 
     // 3 GiB exceeds Int.MaxValue; a Long->Int narrowing would wrap it 
negative.
     val threeGiB = 3L * 1024 * 1024 * 1024
-    WorkflowExecutionsResource.updateResultSize(eid, globalPortId, threeGiB)
+    WorkflowExecutionsResource.updateResultSizeAndCount(eid, globalPortId, 
threeGiB, 0L)
 
     val row = getDSLContext
       .selectFrom(OPERATOR_PORT_EXECUTIONS)
diff --git 
a/amber/src/test/scala/org/apache/texera/web/service/ExecutionResultServiceSpec.scala
 
b/amber/src/test/scala/org/apache/texera/web/service/ExecutionResultServiceSpec.scala
index 6bd7f93411..7842fb2096 100644
--- 
a/amber/src/test/scala/org/apache/texera/web/service/ExecutionResultServiceSpec.scala
+++ 
b/amber/src/test/scala/org/apache/texera/web/service/ExecutionResultServiceSpec.scala
@@ -65,7 +65,7 @@ import org.apache.texera.dao.jooq.generated.Tables.{
   WORKFLOW_EXECUTIONS,
   WORKFLOW_VERSION
 }
-import org.apache.texera.dao.jooq.generated.enums.WorkflowComputingUnitTypeEnum
+import org.apache.texera.dao.jooq.generated.enums.{OutputModeEnum, 
WorkflowComputingUnitTypeEnum}
 import org.apache.texera.dao.jooq.generated.tables.daos.{
   UserDao,
   WorkflowComputingUnitDao,
@@ -234,7 +234,7 @@ class ExecutionResultServiceSpec
 
     ExecutionResultService.persistOperatorPortResultUri(
       eid,
-      OperatorPortResultUriAvailable(globalPortId, uri)
+      OperatorPortResultUriAvailable(globalPortId, uri, 
OutputMode.SINGLE_SNAPSHOT)
     )
 
     val rows = getDSLContext
@@ -244,6 +244,21 @@ class ExecutionResultServiceSpec
       .fetch()
     rows.size() shouldBe 1
     rows.get(0).getResultUri shouldBe uri.toString
+    // The mode is recorded with the URI, so a finished execution's results 
can be
+    // listed without the engine's physical plan (#8994).
+    rows.get(0).getOutputMode shouldBe OutputModeEnum.SINGLE_SNAPSHOT
+  }
+
+  "toOutputModeEnum" should "map every declared output mode to the stored 
value of its name" in {
+    // Walks the proto's values, so a new mode missing from the match fails 
here, not at runtime.
+    OutputMode.values.foreach { mode =>
+      ExecutionResultService.toOutputModeEnum(mode).getLiteral shouldBe 
mode.name
+    }
+  }
+
+  it should "reject an unrecognized mode" in {
+    a[RuntimeException] should be thrownBy
+      ExecutionResultService.toOutputModeEnum(OutputMode.Unrecognized(99))
   }
 
   // The WebOutputMode / WebResultUpdate ADTs are serialized to the frontend 
over
@@ -553,12 +568,12 @@ class ExecutionResultServiceSpec
     }
   }
 
-  it should "record the size and per-column statistics of a table-mode result" 
in {
+  it should "send the per-column statistics of a table-mode result" in {
     val executionId = newExecution()
     val schema = new Schema(
       List(new Attribute("id", AttributeType.INTEGER), new Attribute("name", 
AttributeType.STRING))
     )
-    val uri = storeResult(
+    storeResult(
       executionId,
       "erss-snapshot-stats",
       schema,
@@ -580,16 +595,56 @@ class ExecutionResultServiceSpec
 
       events.updates.head.tableStats.keySet shouldBe Set("erss-snapshot-stats")
       events.updates.head.tableStats("erss-snapshot-stats").keySet shouldBe 
Set("id", "name")
+    }
+  }
+
+  it should "record the size and row count of a table-mode result with no 
browser connected" in {
+    val executionId = newExecution()
+    val schema = new Schema(List(new Attribute("id", AttributeType.INTEGER)))
+    val uri = storeResult(
+      executionId,
+      "erss-snapshot-count",
+      schema,
+      (1 to 3).map(i => Tuple.builder(schema).add("id", AttributeType.INTEGER, 
i).build())
+    )
+    val plan = planOf(
+      physicalOp(executionId, "erss-snapshot-count", PortIdentity() -> 
OutputMode.SET_SNAPSHOT)
+    )
 
-      // The persisted size must be the document's own file size, not some 
other
-      // measure of the result (a row count, or a hard-coded zero).
-      // The persisted size must be the document's own file size, not some 
other
-      // measure of the result (a row count, or a hard-coded zero). Nothing is 
closed
-      // afterwards because VirtualDocument exposes no close(); its only 
teardown is
+    withAttached(plan, executionId) { fixture =>
+      // No ResultEvents: the run finishes after its browser tab has closed 
(#8994).
+      setPollingCancellable(fixture.service, new RecordingCancellable)
+      
fixture.client.fire(ExecutionStateUpdate(WorkflowAggregatedState.COMPLETED))
+
+      storedResultCount(executionId, "erss-snapshot-count") shouldBe 3L
+      // The document's own file size, not some other measure of the result. 
Nothing is
+      // closed afterwards because VirtualDocument exposes no close(); its 
only teardown is
       // clear(), which deletes the data rather than releasing a handle.
       val expectedSize = DocumentFactory.openDocument(uri)._1.getTotalFileSize
       expectedSize should not be 0L
-      storedResultSize(executionId, "erss-snapshot-stats") shouldBe 
expectedSize
+      storedResultSize(executionId, "erss-snapshot-count") shouldBe 
expectedSize
+    }
+  }
+
+  it should "record no row count for a SINGLE_SNAPSHOT port" in {
+    val executionId = newExecution()
+    val schema = new Schema(List(new Attribute("html", AttributeType.STRING)))
+    storeResult(
+      executionId,
+      "erss-single-count",
+      schema,
+      List(Tuple.builder(schema).add("html", AttributeType.STRING, 
"<p/>").build())
+    )
+    val plan = planOf(
+      physicalOp(executionId, "erss-single-count", PortIdentity() -> 
OutputMode.SINGLE_SNAPSHOT)
+    )
+
+    withAttached(plan, executionId) { fixture =>
+      setPollingCancellable(fixture.service, new RecordingCancellable)
+      
fixture.client.fire(ExecutionStateUpdate(WorkflowAggregatedState.COMPLETED))
+
+      // A visualization is shown whole, never paged, so it has no count to 
record.
+      storedResultCount(executionId, "erss-single-count") shouldBe null
     }
   }
 
@@ -736,7 +791,9 @@ class ExecutionResultServiceSpec
       val globalPortId = globalPortIdOf("erss-callback")
       val uri = resultUriOf(executionId, "erss-callback")
 
-      fixture.client.fire(OperatorPortResultUriAvailable(globalPortId, uri))
+      fixture.client.fire(
+        OperatorPortResultUriAvailable(globalPortId, uri, 
OutputMode.SET_SNAPSHOT)
+      )
 
       val rows = getDSLContext
         .selectFrom(OPERATOR_PORT_EXECUTIONS)
@@ -1090,6 +1147,19 @@ class ExecutionResultServiceSpec
     uri
   }
 
+  private def storedResultCount(
+      executionId: ExecutionIdentity,
+      operatorId: String
+  ): java.lang.Long =
+    getDSLContext
+      .select(OPERATOR_PORT_EXECUTIONS.RESULT_COUNT)
+      .from(OPERATOR_PORT_EXECUTIONS)
+      
.where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(executionId.id.toInt))
+      .and(
+        
OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID.eq(globalPortIdOf(operatorId).serializeAsString)
+      )
+      .fetchOne(OPERATOR_PORT_EXECUTIONS.RESULT_COUNT)
+
   private def storedResultSize(executionId: ExecutionIdentity, operatorId: 
String): Long =
     getDSLContext
       .select(OPERATOR_PORT_EXECUTIONS.RESULT_SIZE)
diff --git 
a/common/workflow-core/src/main/protobuf/org/apache/texera/amber/core/workflow.proto
 
b/common/workflow-core/src/main/protobuf/org/apache/texera/amber/core/workflow.proto
index b3b72ed924..410157c222 100644
--- 
a/common/workflow-core/src/main/protobuf/org/apache/texera/amber/core/workflow.proto
+++ 
b/common/workflow-core/src/main/protobuf/org/apache/texera/amber/core/workflow.proto
@@ -48,6 +48,9 @@ message InputPort {
 
 
 message OutputPort {
+  // Mirrored by output_mode_enum in sql/texera_ddl.sql, which records each 
result port's
+  // mode: a new mode needs a value there too.
+
   enum OutputMode {
     // outputs complete result set snapshot for each update
     SET_SNAPSHOT = 0;
diff --git a/sql/changelog.xml b/sql/changelog.xml
index 97724697c6..62dfe42d52 100644
--- a/sql/changelog.xml
+++ b/sql/changelog.xml
@@ -169,6 +169,11 @@
         <sqlFile path="sql/updates/51.sql"/>
     </changeSet>
 
+    <!-- Record each result port's output mode and row count -->
+    <changeSet id="52" author="mengw15">
+        <sqlFile path="sql/updates/52.sql"/>
+    </changeSet>
+
     <!-- example changeSet
     <changeSet id="1" author="author">
         <sqlFile path="sql/updates/1.sql"/>
diff --git a/sql/texera_ddl.sql b/sql/texera_ddl.sql
index dde189976a..e7575b4405 100644
--- a/sql/texera_ddl.sql
+++ b/sql/texera_ddl.sql
@@ -102,6 +102,9 @@ CREATE TYPE workflow_computing_unit_termination_reason_enum 
AS ENUM ('USER_REQUE
 CREATE TYPE provider_type_enum AS ENUM ('LOCAL', 'GOOGLE', 'ORCID', 'APPLE');
 CREATE TYPE user_warehouse_flavor_enum AS ENUM ('local', 'aws');
 CREATE TYPE default_view_enum AS ENUM ('CANVAS', 'FORM');
+-- Mirrors OutputPort.OutputMode in workflow.proto: a new mode needs a value 
here, a migration,
+-- and a case in ExecutionResultService.toOutputModeEnum.
+CREATE TYPE output_mode_enum AS ENUM ('SET_SNAPSHOT', 'SET_DELTA', 
'SINGLE_SNAPSHOT');
 
 -- ============================================
 -- 5. Create tables
@@ -551,6 +554,10 @@ CREATE TABLE operator_port_executions
     global_port_id        VARCHAR(200) NOT NULL,
     result_uri            TEXT,
     result_size           BIGINT DEFAULT 0,
+    -- The port's declared output mode and row count, so a finished 
execution's results
+    -- can be listed without the engine's physical plan or opening each table 
(#8994).
+    output_mode           output_mode_enum,
+    result_count          BIGINT,
     PRIMARY KEY (workflow_execution_id, global_port_id),
     FOREIGN KEY (workflow_execution_id) REFERENCES workflow_executions(eid) ON 
DELETE CASCADE
 );
diff --git a/sql/updates/52.sql b/sql/updates/52.sql
new file mode 100644
index 0000000000..5b36a49117
--- /dev/null
+++ b/sql/updates/52.sql
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+-- Names are schema-qualified because the two runners disagree about the 
search path: the
+-- liquibase runner in sql/docker-compose.yml strips `SET search_path` out of 
these files before
+-- applying them, while bin/local-dev.sh keeps it.
+
+\c texera_db
+
+SET search_path TO texera_db;
+
+BEGIN;
+
+DO $$
+BEGIN
+    IF NOT EXISTS (
+        SELECT 1
+        FROM pg_type t
+        JOIN pg_namespace n ON n.oid = t.typnamespace
+        WHERE t.typname = 'output_mode_enum' AND n.nspname = 'texera_db'
+    ) THEN
+        CREATE TYPE texera_db.output_mode_enum AS ENUM ('SET_SNAPSHOT', 
'SET_DELTA', 'SINGLE_SNAPSHOT');
+    END IF;
+END $$;
+
+-- The port's declared output mode and row count, so a finished execution's 
results
+-- can be listed without the engine's physical plan or opening each table 
(#8994).
+-- Rows written before this change keep both columns null.
+ALTER TABLE texera_db.operator_port_executions
+    ADD COLUMN IF NOT EXISTS output_mode texera_db.output_mode_enum DEFAULT 
NULL,
+    ADD COLUMN IF NOT EXISTS result_count BIGINT DEFAULT NULL;
+
+COMMIT;

Reply via email to