kunwp1 commented on code in PR #9519:
URL: https://github.com/apache/texera/pull/9519#discussion_r4648555592


##########
amber/src/main/scala/org/apache/texera/amber/engine/architecture/coordinator/CoordinatorTimerService.scala:
##########
@@ -65,10 +65,9 @@ class CoordinatorTimerService(
   private def disableTimer(handleOpt: Option[Cancellable]): 
Option[Cancellable] = {
     if (handleOpt.nonEmpty) {
       handleOpt.get.cancel()
-      Option.empty
-    } else {
-      handleOpt
+      ()
     }
+    None

Review Comment:
   This always returns `None` now, so the `if`, the `.get` and the bare `()` 
can collapse to:
   
   ```scala
       handleOpt.foreach(_.cancel())
       None
   ```



##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/result/iceberg/IcebergDocument.scala:
##########
@@ -191,10 +191,10 @@ private[storage] class IcebergDocument[T >: Null <: 
AnyRef](
         private var lastSnapshotId: Option[Long] = None
 
         // Counter for how many records have been skipped
-        private var numOfSkippedRecords = 0
+        private var numOfSkippedRecords: Int = _
 
         // Counter for how many records have been returned
-        private var numOfReturnedRecords = 0
+        private var numOfReturnedRecords: Int = _

Review Comment:
   `= 0` said the same thing more plainly, and `= _` is deprecated in Scala 3. 
The same goes for `filenameIdx` in `IcebergTableWriter`. I'd keep `= 0` in all 
three.



##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/ComputingUnitManagingResource.scala:
##########
@@ -727,22 +725,32 @@ class ComputingUnitManagingResource(
         case _ => "{}"
       }
 
+      val creationTime = new Timestamp(System.currentTimeMillis())
+      val uri =
+        if (cuType == WorkflowComputingUnitTypeEnum.local) param.uri.get
+        else "" // placeholder for kubernetes
+      val cuid = ctx
+        .insertInto(WORKFLOW_COMPUTING_UNIT)
+        .set(WORKFLOW_COMPUTING_UNIT.UID, user.getUid)
+        .set(WORKFLOW_COMPUTING_UNIT.NAME, param.name)
+        .set(WORKFLOW_COMPUTING_UNIT.CREATION_TIME, creationTime)
+        .set(WORKFLOW_COMPUTING_UNIT.TYPE, cuType)
+        .set(WORKFLOW_COMPUTING_UNIT.RESOURCE, resourceJson)
+        .set(WORKFLOW_COMPUTING_UNIT.URI, uri)
+        .returningResult(WORKFLOW_COMPUTING_UNIT.CUID)
+        .fetchOne()
+        .value1()
+        .intValue()
+
       val computingUnit = new WorkflowComputingUnit()
       val userToken = JwtAuth.jwtToken(jwtClaims(user.user))
+      computingUnit.setCuid(cuid)
       computingUnit.setUid(user.getUid)
       computingUnit.setName(param.name)
-      computingUnit.setCreationTime(new Timestamp(System.currentTimeMillis()))
-      
computingUnit.setType(WorkflowComputingUnitTypeEnum.lookupLiteral(param.unitType))
+      computingUnit.setCreationTime(creationTime)
+      computingUnit.setType(cuType)
       computingUnit.setResource(resourceJson)
-
-      // Set URI during initial insert for local only
-      if (cuType == WorkflowComputingUnitTypeEnum.local) {
-        computingUnit.setUri(param.uri.get)
-      } else {
-        computingUnit.setUri("") // placeholder for kubernetes
-      }
-
-      wcDao.insert(computingUnit)
+      computingUnit.setUri(uri)

Review Comment:
   Every column now goes into the insert and again into the POJO, and the 
Kubernetes branch sets `uri` and `resource` on both the POJO and a hand-written 
UPDATE, so a new column has to be added in two places. `Dao.insert` already 
writes the generated `cuid` back into the POJO; 
`WorkflowResource.insertWorkflow` relies on that with `workflow.getWid`. So one 
object can drive both the row and the response, still without `lastID()` or the 
re-fetch:
   
   ```scala
         val computingUnit = new WorkflowComputingUnit()
         // ... the same setters as before ...
         wcDao.insert(computingUnit)
         val cuid: Int = computingUnit.getCuid
         ...
           computingUnit.setUri(podUri)
           computingUnit.setResource(Json.stringify(updatedResource))
           wcDao.update(computingUnit)
   ```
   
   Further down, the `case t: Throwable => throw t` after `createPod` is the 
same identity rethrow the PR removes elsewhere.



##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/result/iceberg/IcebergDocument.scala:
##########
@@ -576,12 +557,12 @@ private[storage] class IcebergDocument[T >: Null <: 
AnyRef](
     * @return An InputStream that streams the contents of the Iceberg table as 
a ZIP archive.
     */
   override def asInputStream(): InputStream = {
-    val fileScanTasks: Seq[FileScanTask] = {
-      val table = 
this.catalog.loadTable(TableIdentifier.of(this.tableNamespace, this.tableName))
-      table.refresh()
-      Using.resource(table.newScan().planFiles()) { tasks =>
-        tasks.iterator().asScala.toSeq
-      }
+    val planningCatalog = catalog
+    val identifier = TableIdentifier.of(tableNamespace, tableName)
+    val table = planningCatalog.loadTable(identifier)

Review Comment:
   `planningCatalog` is used once, so `catalog.loadTable(identifier)` reads the 
same. Further down, `String.format("part-%05d.parquet", Int.box(i))` can be 
`f"part-$i%05d.parquet"`.
   
   The description says this reuses one identifier, but `getParquetFileStream` 
still calls `catalog.loadTable` for every part, and that is the costly part. If 
it is deliberate because of #7290, a one-line comment there would say so.



##########
computing-unit-managing-service/src/main/scala/org/apache/texera/service/resource/CuratedImageResource.scala:
##########
@@ -199,18 +200,25 @@ object CuratedImageResource extends LazyLogging {
     else if (status != Status.Ready) None
     else pinnedRefOf(sourceRef, sourceDigest)
 
-  def readyImageFor(iid: Int): Option[String] = {
+  def readyImageFor(iid: Int): Option[String] =
+    readyImageWithNameFor(iid).map(_._2)
+
+  def readyImageWithNameFor(iid: Int): Option[(Option[String], String)] = {

Review Comment:
   After this, `readyImageFor` and `nameOf` (line 225) have no callers left. 
Since `readyImageWithNameFor` replaces both, I'd keep the original name, delete 
`nameOf`, and return a small case class instead of `(Option[String], String)`, 
so the caller reads `.ref` and `.name` rather than `_._2` and `_._1`:
   
   ```scala
     final case class ReadyImage(ref: String, name: Option[String])
   
     def readyImageFor(iid: Int): Option[ReadyImage] = {
       ...
         ).map(ReadyImage(_, Option(r.get(NAME))))
     }
   ```



##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/result/iceberg/IcebergDocument.scala:
##########
@@ -78,19 +78,19 @@ private[storage] class IcebergDocument[T >: Null <: AnyRef](
   // (not a lazy val) also means a replaced/rebuilt catalog is picked up 
immediately.
   def catalog: Catalog = IcebergCatalogInstance.getInstance(warehouse)
 
+  private def requireTable(): Table =
+    IcebergUtil
+      .loadTableMetadata(catalog, tableNamespace, tableName)
+      .getOrElse(
+        throw new NoSuchTableException(f"table ${tableNamespace}.${tableName} 
doesn't exist")
+      )

Review Comment:
   `OnIceberg.expireSnapshots`, which this class mixes in, does the same 
load-or-`NoSuchTableException`. Putting `requireTable` on the trait as a 
`protected def` lets both share it, and `expireSnapshots` becomes 
`requireTable().expireSnapshots()...`.



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