Copilot commented on code in PR #9356:
URL: https://github.com/apache/texera/pull/9356#discussion_r4532749423
##########
common/workflow-core/src/main/scala/org/apache/texera/amber/core/storage/IcebergCatalogInstance.scala:
##########
@@ -106,7 +101,11 @@ object IcebergCatalogInstance extends LazyLogging {
.build[String, Catalog]()
private val catalogs: Cache[String, Catalog] =
- buildCatalogCache(CatalogCacheMaxSize, CatalogCacheExpireAfterAccess,
Ticker.systemTicker())
+ buildCatalogCache(
+ StorageConfig.icebergCatalogCacheMaxSize,
+
Duration.ofMinutes(StorageConfig.icebergCatalogCacheExpireAfterAccessMinutes),
Review Comment:
With an expiry shorter than a table read or commit, another cache access can
expire and close the catalog while that operation still uses it. Resolving the
catalog once per operation does not renew its idle timer during the operation,
so the new setting can break in-flight work. Track active uses and defer
closing expired catalogs until those operations finish.
##########
result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.texera.service.resource
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.dropwizard.auth.Auth
+import jakarta.annotation.security.RolesAllowed
+import jakarta.ws.rs.core.MediaType
+import jakarta.ws.rs.{
+ BadRequestException,
+ DefaultValue,
+ ForbiddenException,
+ GET,
+ NotFoundException,
+ Path,
+ PathParam,
+ Produces,
+ QueryParam,
+ ServiceUnavailableException
+}
+import org.apache.texera.amber.core.storage.model.VirtualDocument
+import org.apache.texera.amber.core.storage.{
+ DocumentFactory,
+ ExecutionResultUris,
+ WarehouseReadGuard,
+ WarehouseUnavailableException
+}
+import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple,
TupleUtils}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
OperatorIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.auth.util.WorkflowAccess
+import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.Tables.{
+ OPERATOR_PORT_EXECUTIONS,
+ WORKFLOW_EXECUTIONS,
+ WORKFLOW_VERSION
+}
+import org.apache.texera.service.resource.ResultResource._
+import org.jooq.DSLContext
+
+import java.net.URI
+import scala.jdk.CollectionConverters._
+
+object ResultResource {
+ // workflow_executions.status of a run that has ended: COMPLETED, FAILED and
KILLED.
+ private val FinishedStatuses: java.util.List[java.lang.Short] =
+ List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava
+
+ // A page is read into memory in a service everyone shares, so one request
must not be able to
+ // ask for a whole table. This is far above the rows a result panel shows at
once.
+ private val MaxPageSize = 1000
+
+ private def context: DSLContext = SqlServer.getInstance().createDSLContext()
+
+ case class LatestExecution(eid: Integer)
+
+ /** One result of an execution. `outputMode` and `rowCount` are null where
not recorded. */
+ case class PortResult(
+ operatorId: String,
+ portIndex: Int,
+ outputMode: String,
+ rowCount: java.lang.Long
+ )
+
+ case class ResultPage(table: List[ObjectNode], schema: List[Attribute],
rowCount: Long)
+}
+
+/**
+ * Reads the results of an execution, running or finished. Each read loads
the table's current
+ * snapshot, so the pages of a running execution are as fresh as what it has
committed.
+ */
+@Path("/results")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@RolesAllowed(Array("REGULAR", "ADMIN"))
+class ResultResource(
+ openDocument: URI => (VirtualDocument[_], Option[Schema]) =
DocumentFactory.openDocument
+) {
+
+ /**
+ * The caller's own latest finished execution of a workflow. It names only
an execution the
+ * caller started, so it needs no access check of its own.
+ */
+ @GET
+ @Path("/workflows/{wid}/latest-execution")
+ def getLatestExecution(
+ @PathParam("wid") wid: Integer,
+ @Auth user: SessionUser
+ ): LatestExecution = {
+ val eid = context
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_VERSION.WID.eq(wid))
+ .and(WORKFLOW_EXECUTIONS.UID.eq(user.getUid))
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(FinishedStatuses))
Review Comment:
This query has no supporting index on `workflow_executions.uid`/`vid` or
`workflow_version.wid`. A request with no matching finished execution must
search the shared execution history before returning 404, so its work grows
with other users' runs. Add indexes for the user/version/status lookup and
workflow-to-version join in both the base schema and a migration.
##########
result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.texera.service.resource
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.dropwizard.auth.Auth
+import jakarta.annotation.security.RolesAllowed
+import jakarta.ws.rs.core.MediaType
+import jakarta.ws.rs.{
+ BadRequestException,
+ DefaultValue,
+ ForbiddenException,
+ GET,
+ NotFoundException,
+ Path,
+ PathParam,
+ Produces,
+ QueryParam,
+ ServiceUnavailableException
+}
+import org.apache.texera.amber.core.storage.model.VirtualDocument
+import org.apache.texera.amber.core.storage.{
+ DocumentFactory,
+ ExecutionResultUris,
+ WarehouseReadGuard,
+ WarehouseUnavailableException
+}
+import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple,
TupleUtils}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
OperatorIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.auth.util.WorkflowAccess
+import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.Tables.{
+ OPERATOR_PORT_EXECUTIONS,
+ WORKFLOW_EXECUTIONS,
+ WORKFLOW_VERSION
+}
+import org.apache.texera.service.resource.ResultResource._
+import org.jooq.DSLContext
+
+import java.net.URI
+import scala.jdk.CollectionConverters._
+
+object ResultResource {
+ // workflow_executions.status of a run that has ended: COMPLETED, FAILED and
KILLED.
+ private val FinishedStatuses: java.util.List[java.lang.Short] =
+ List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava
+
+ // A page is read into memory in a service everyone shares, so one request
must not be able to
+ // ask for a whole table. This is far above the rows a result panel shows at
once.
+ private val MaxPageSize = 1000
+
+ private def context: DSLContext = SqlServer.getInstance().createDSLContext()
+
+ case class LatestExecution(eid: Integer)
+
+ /** One result of an execution. `outputMode` and `rowCount` are null where
not recorded. */
+ case class PortResult(
+ operatorId: String,
+ portIndex: Int,
+ outputMode: String,
+ rowCount: java.lang.Long
+ )
+
+ case class ResultPage(table: List[ObjectNode], schema: List[Attribute],
rowCount: Long)
+}
+
+/**
+ * Reads the results of an execution, running or finished. Each read loads
the table's current
+ * snapshot, so the pages of a running execution are as fresh as what it has
committed.
+ */
+@Path("/results")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@RolesAllowed(Array("REGULAR", "ADMIN"))
+class ResultResource(
+ openDocument: URI => (VirtualDocument[_], Option[Schema]) =
DocumentFactory.openDocument
+) {
+
+ /**
+ * The caller's own latest finished execution of a workflow. It names only
an execution the
+ * caller started, so it needs no access check of its own.
+ */
+ @GET
+ @Path("/workflows/{wid}/latest-execution")
+ def getLatestExecution(
+ @PathParam("wid") wid: Integer,
+ @Auth user: SessionUser
+ ): LatestExecution = {
+ val eid = context
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_VERSION.WID.eq(wid))
+ .and(WORKFLOW_EXECUTIONS.UID.eq(user.getUid))
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(FinishedStatuses))
+ .orderBy(WORKFLOW_EXECUTIONS.EID.desc())
+ .limit(1)
+ .fetchOneInto(classOf[Integer])
+ if (eid == null) {
+ throw new NotFoundException(s"you have no finished execution of workflow
$wid")
+ }
+ LatestExecution(eid)
+ }
+
+ /** The results of an execution, read from the database alone. */
+ @GET
+ @Path("/executions/{eid}")
+ def getResults(@PathParam("eid") eid: Integer, @Auth user: SessionUser):
List[PortResult] = {
+ requireReadable(eid, user)
+ context
+ .select(
+ OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID,
+ OPERATOR_PORT_EXECUTIONS.OUTPUT_MODE,
+ OPERATOR_PORT_EXECUTIONS.RESULT_COUNT
+ )
+ .from(OPERATOR_PORT_EXECUTIONS)
+ .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(eid))
+ .and(OPERATOR_PORT_EXECUTIONS.RESULT_URI.ne(""))
+ .fetch()
+ .asScala
+ .toList
+ .flatMap { row =>
+ val port = GlobalPortIdentitySerde.deserializeFromString(row.value1())
+ Option.when(!port.portId.internal) {
+ PortResult(
+ port.opId.logicalOpId.id,
+ port.portId.id,
+ Option(row.value2()).map(_.getLiteral).orNull,
+ row.value3()
Review Comment:
`ExecutionResultService.onResultUpdate` only persists `RESULT_COUNT` for
port 0 and skips `SINGLE_SNAPSHOT`, so newly completed executions still return
null counts for secondary and visualization ports. Persist counts for every
external port and output mode before filtering the operator-keyed UI updates,
keeping this listing database-only.
##########
result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.texera.service.resource
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.dropwizard.auth.Auth
+import jakarta.annotation.security.RolesAllowed
+import jakarta.ws.rs.core.MediaType
+import jakarta.ws.rs.{
+ BadRequestException,
+ DefaultValue,
+ ForbiddenException,
+ GET,
+ NotFoundException,
+ Path,
+ PathParam,
+ Produces,
+ QueryParam,
+ ServiceUnavailableException
+}
+import org.apache.texera.amber.core.storage.model.VirtualDocument
+import org.apache.texera.amber.core.storage.{
+ DocumentFactory,
+ ExecutionResultUris,
+ WarehouseReadGuard,
+ WarehouseUnavailableException
+}
+import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple,
TupleUtils}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
OperatorIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.auth.util.WorkflowAccess
+import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.Tables.{
+ OPERATOR_PORT_EXECUTIONS,
+ WORKFLOW_EXECUTIONS,
+ WORKFLOW_VERSION
+}
+import org.apache.texera.service.resource.ResultResource._
+import org.jooq.DSLContext
+
+import java.net.URI
+import scala.jdk.CollectionConverters._
+
+object ResultResource {
+ // workflow_executions.status of a run that has ended: COMPLETED, FAILED and
KILLED.
+ private val FinishedStatuses: java.util.List[java.lang.Short] =
+ List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava
+
+ // A page is read into memory in a service everyone shares, so one request
must not be able to
+ // ask for a whole table. This is far above the rows a result panel shows at
once.
+ private val MaxPageSize = 1000
+
+ private def context: DSLContext = SqlServer.getInstance().createDSLContext()
+
+ case class LatestExecution(eid: Integer)
+
+ /** One result of an execution. `outputMode` and `rowCount` are null where
not recorded. */
+ case class PortResult(
+ operatorId: String,
+ portIndex: Int,
+ outputMode: String,
+ rowCount: java.lang.Long
+ )
+
+ case class ResultPage(table: List[ObjectNode], schema: List[Attribute],
rowCount: Long)
+}
+
+/**
+ * Reads the results of an execution, running or finished. Each read loads
the table's current
+ * snapshot, so the pages of a running execution are as fresh as what it has
committed.
+ */
+@Path("/results")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@RolesAllowed(Array("REGULAR", "ADMIN"))
+class ResultResource(
+ openDocument: URI => (VirtualDocument[_], Option[Schema]) =
DocumentFactory.openDocument
+) {
+
+ /**
+ * The caller's own latest finished execution of a workflow. It names only
an execution the
+ * caller started, so it needs no access check of its own.
+ */
+ @GET
+ @Path("/workflows/{wid}/latest-execution")
+ def getLatestExecution(
+ @PathParam("wid") wid: Integer,
+ @Auth user: SessionUser
+ ): LatestExecution = {
+ val eid = context
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_VERSION.WID.eq(wid))
+ .and(WORKFLOW_EXECUTIONS.UID.eq(user.getUid))
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(FinishedStatuses))
+ .orderBy(WORKFLOW_EXECUTIONS.EID.desc())
+ .limit(1)
+ .fetchOneInto(classOf[Integer])
+ if (eid == null) {
+ throw new NotFoundException(s"you have no finished execution of workflow
$wid")
+ }
+ LatestExecution(eid)
+ }
+
+ /** The results of an execution, read from the database alone. */
+ @GET
+ @Path("/executions/{eid}")
+ def getResults(@PathParam("eid") eid: Integer, @Auth user: SessionUser):
List[PortResult] = {
+ requireReadable(eid, user)
+ context
+ .select(
+ OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID,
+ OPERATOR_PORT_EXECUTIONS.OUTPUT_MODE,
+ OPERATOR_PORT_EXECUTIONS.RESULT_COUNT
+ )
+ .from(OPERATOR_PORT_EXECUTIONS)
+ .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(eid))
+ .and(OPERATOR_PORT_EXECUTIONS.RESULT_URI.ne(""))
+ .fetch()
+ .asScala
+ .toList
+ .flatMap { row =>
+ val port = GlobalPortIdentitySerde.deserializeFromString(row.value1())
+ Option.when(!port.portId.internal) {
+ PortResult(
+ port.opId.logicalOpId.id,
+ port.portId.id,
+ Option(row.value2()).map(_.getLiteral).orNull,
+ row.value3()
+ )
+ }
+ }
+ .sortBy(result => (result.operatorId, result.portIndex))
+ }
+
+ /** One page of an operator's result. `pageIndex` starts from 1. */
+ @GET
+ @Path("/executions/{eid}/operators/{operatorId}/pages")
+ def getPage(
+ @PathParam("eid") eid: Integer,
+ @PathParam("operatorId") operatorId: String,
+ @QueryParam("port") @DefaultValue("0") port: Int,
+ @QueryParam("pageIndex") @DefaultValue("1") pageIndex: Int,
+ @QueryParam("pageSize") @DefaultValue("10") pageSize: Int,
+ @QueryParam("columnOffset") @DefaultValue("0") columnOffset: Int,
+ @QueryParam("columnLimit") @DefaultValue("2147483647") columnLimit: Int,
+ @QueryParam("columnSearch") @DefaultValue("") columnSearch: String,
+ @Auth user: SessionUser
+ ): ResultPage = {
+ requireReadable(eid, user)
+ if (
+ pageIndex < 1 || pageSize < 1 || pageSize > MaxPageSize || columnOffset
< 0 ||
+ columnLimit < 0 || pageIndex.toLong * pageSize > Int.MaxValue
+ ) {
+ throw new BadRequestException("the page or column range is out of
bounds")
+ }
+
+ val (document, schema) = openResult(eid, operatorId, port)
+ val columns = schema.getAttributeNames
+ .filter(_.toLowerCase.contains(columnSearch.toLowerCase))
+ .drop(columnOffset)
+ .take(columnLimit)
+ val from = pageSize * (pageIndex - 1)
+ val rows = document.getRange(from, from + pageSize, Some(columns)).toList
+ ResultPage(
+ TupleUtils.convertTuplesToJson(rows),
Review Comment:
`convertTuplesToJson(rows)` defaults to `isVisualization = false`, which
truncates STRING values after 100 characters. `SINGLE_SNAPSHOT` ports store
visualization HTML in `html-content`, so paging them returns incomplete HTML
that cannot render. Derive the flag from the requested port's persisted output
mode, preserve full visualization strings, and add a regression case longer
than 100 characters.
##########
result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.texera.service.resource
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.dropwizard.auth.Auth
+import jakarta.annotation.security.RolesAllowed
+import jakarta.ws.rs.core.MediaType
+import jakarta.ws.rs.{
+ BadRequestException,
+ DefaultValue,
+ ForbiddenException,
+ GET,
+ NotFoundException,
+ Path,
+ PathParam,
+ Produces,
+ QueryParam,
+ ServiceUnavailableException
+}
+import org.apache.texera.amber.core.storage.model.VirtualDocument
+import org.apache.texera.amber.core.storage.{
+ DocumentFactory,
+ ExecutionResultUris,
+ WarehouseReadGuard,
+ WarehouseUnavailableException
+}
+import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple,
TupleUtils}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
OperatorIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.auth.util.WorkflowAccess
+import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.Tables.{
+ OPERATOR_PORT_EXECUTIONS,
+ WORKFLOW_EXECUTIONS,
+ WORKFLOW_VERSION
+}
+import org.apache.texera.service.resource.ResultResource._
+import org.jooq.DSLContext
+
+import java.net.URI
+import scala.jdk.CollectionConverters._
+
+object ResultResource {
+ // workflow_executions.status of a run that has ended: COMPLETED, FAILED and
KILLED.
+ private val FinishedStatuses: java.util.List[java.lang.Short] =
+ List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava
+
+ // A page is read into memory in a service everyone shares, so one request
must not be able to
+ // ask for a whole table. This is far above the rows a result panel shows at
once.
+ private val MaxPageSize = 1000
+
+ private def context: DSLContext = SqlServer.getInstance().createDSLContext()
+
+ case class LatestExecution(eid: Integer)
+
+ /** One result of an execution. `outputMode` and `rowCount` are null where
not recorded. */
+ case class PortResult(
+ operatorId: String,
+ portIndex: Int,
+ outputMode: String,
+ rowCount: java.lang.Long
+ )
+
+ case class ResultPage(table: List[ObjectNode], schema: List[Attribute],
rowCount: Long)
+}
+
+/**
+ * Reads the results of an execution, running or finished. Each read loads
the table's current
+ * snapshot, so the pages of a running execution are as fresh as what it has
committed.
+ */
+@Path("/results")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@RolesAllowed(Array("REGULAR", "ADMIN"))
+class ResultResource(
+ openDocument: URI => (VirtualDocument[_], Option[Schema]) =
DocumentFactory.openDocument
+) {
+
+ /**
+ * The caller's own latest finished execution of a workflow. It names only
an execution the
+ * caller started, so it needs no access check of its own.
+ */
+ @GET
+ @Path("/workflows/{wid}/latest-execution")
+ def getLatestExecution(
+ @PathParam("wid") wid: Integer,
+ @Auth user: SessionUser
+ ): LatestExecution = {
+ val eid = context
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_VERSION.WID.eq(wid))
+ .and(WORKFLOW_EXECUTIONS.UID.eq(user.getUid))
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(FinishedStatuses))
+ .orderBy(WORKFLOW_EXECUTIONS.EID.desc())
+ .limit(1)
+ .fetchOneInto(classOf[Integer])
+ if (eid == null) {
+ throw new NotFoundException(s"you have no finished execution of workflow
$wid")
+ }
+ LatestExecution(eid)
+ }
+
+ /** The results of an execution, read from the database alone. */
+ @GET
+ @Path("/executions/{eid}")
+ def getResults(@PathParam("eid") eid: Integer, @Auth user: SessionUser):
List[PortResult] = {
+ requireReadable(eid, user)
+ context
+ .select(
+ OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID,
+ OPERATOR_PORT_EXECUTIONS.OUTPUT_MODE,
+ OPERATOR_PORT_EXECUTIONS.RESULT_COUNT
+ )
+ .from(OPERATOR_PORT_EXECUTIONS)
+ .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(eid))
+ .and(OPERATOR_PORT_EXECUTIONS.RESULT_URI.ne(""))
+ .fetch()
+ .asScala
+ .toList
+ .flatMap { row =>
+ val port = GlobalPortIdentitySerde.deserializeFromString(row.value1())
+ Option.when(!port.portId.internal) {
+ PortResult(
+ port.opId.logicalOpId.id,
+ port.portId.id,
+ Option(row.value2()).map(_.getLiteral).orNull,
+ row.value3()
+ )
+ }
+ }
+ .sortBy(result => (result.operatorId, result.portIndex))
+ }
+
+ /** One page of an operator's result. `pageIndex` starts from 1. */
+ @GET
+ @Path("/executions/{eid}/operators/{operatorId}/pages")
+ def getPage(
+ @PathParam("eid") eid: Integer,
+ @PathParam("operatorId") operatorId: String,
+ @QueryParam("port") @DefaultValue("0") port: Int,
+ @QueryParam("pageIndex") @DefaultValue("1") pageIndex: Int,
+ @QueryParam("pageSize") @DefaultValue("10") pageSize: Int,
+ @QueryParam("columnOffset") @DefaultValue("0") columnOffset: Int,
+ @QueryParam("columnLimit") @DefaultValue("2147483647") columnLimit: Int,
+ @QueryParam("columnSearch") @DefaultValue("") columnSearch: String,
+ @Auth user: SessionUser
+ ): ResultPage = {
+ requireReadable(eid, user)
+ if (
+ pageIndex < 1 || pageSize < 1 || pageSize > MaxPageSize || columnOffset
< 0 ||
+ columnLimit < 0 || pageIndex.toLong * pageSize > Int.MaxValue
+ ) {
+ throw new BadRequestException("the page or column range is out of
bounds")
+ }
+
+ val (document, schema) = openResult(eid, operatorId, port)
+ val columns = schema.getAttributeNames
+ .filter(_.toLowerCase.contains(columnSearch.toLowerCase))
+ .drop(columnOffset)
+ .take(columnLimit)
+ val from = pageSize * (pageIndex - 1)
+ val rows = document.getRange(from, from + pageSize, Some(columns)).toList
Review Comment:
The row limit does not bound the memory used here: `toList` retains every
full decoded tuple before string/binary previews are produced, and neither the
number of columns nor the size of an individual value is capped. A valid
1,000-row result with multi-megabyte strings can exhaust the shared service
heap in one request. Convert rows incrementally and enforce a
decoded-byte/column budget (including an oversized-row limit) rather than
relying only on the row count.
##########
result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.texera.service.resource
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.dropwizard.auth.Auth
+import jakarta.annotation.security.RolesAllowed
+import jakarta.ws.rs.core.MediaType
+import jakarta.ws.rs.{
+ BadRequestException,
+ DefaultValue,
+ ForbiddenException,
+ GET,
+ NotFoundException,
+ Path,
+ PathParam,
+ Produces,
+ QueryParam,
+ ServiceUnavailableException
+}
+import org.apache.texera.amber.core.storage.model.VirtualDocument
+import org.apache.texera.amber.core.storage.{
+ DocumentFactory,
+ ExecutionResultUris,
+ WarehouseReadGuard,
+ WarehouseUnavailableException
+}
+import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple,
TupleUtils}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
OperatorIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.auth.util.WorkflowAccess
+import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.Tables.{
+ OPERATOR_PORT_EXECUTIONS,
+ WORKFLOW_EXECUTIONS,
+ WORKFLOW_VERSION
+}
+import org.apache.texera.service.resource.ResultResource._
+import org.jooq.DSLContext
+
+import java.net.URI
+import scala.jdk.CollectionConverters._
+
+object ResultResource {
+ // workflow_executions.status of a run that has ended: COMPLETED, FAILED and
KILLED.
+ private val FinishedStatuses: java.util.List[java.lang.Short] =
+ List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava
+
+ // A page is read into memory in a service everyone shares, so one request
must not be able to
+ // ask for a whole table. This is far above the rows a result panel shows at
once.
+ private val MaxPageSize = 1000
+
+ private def context: DSLContext = SqlServer.getInstance().createDSLContext()
+
+ case class LatestExecution(eid: Integer)
+
+ /** One result of an execution. `outputMode` and `rowCount` are null where
not recorded. */
+ case class PortResult(
+ operatorId: String,
+ portIndex: Int,
+ outputMode: String,
+ rowCount: java.lang.Long
+ )
+
+ case class ResultPage(table: List[ObjectNode], schema: List[Attribute],
rowCount: Long)
+}
+
+/**
+ * Reads the results of an execution, running or finished. Each read loads
the table's current
+ * snapshot, so the pages of a running execution are as fresh as what it has
committed.
+ */
+@Path("/results")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@RolesAllowed(Array("REGULAR", "ADMIN"))
+class ResultResource(
+ openDocument: URI => (VirtualDocument[_], Option[Schema]) =
DocumentFactory.openDocument
+) {
+
+ /**
+ * The caller's own latest finished execution of a workflow. It names only
an execution the
+ * caller started, so it needs no access check of its own.
+ */
+ @GET
+ @Path("/workflows/{wid}/latest-execution")
+ def getLatestExecution(
+ @PathParam("wid") wid: Integer,
+ @Auth user: SessionUser
+ ): LatestExecution = {
+ val eid = context
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_VERSION.WID.eq(wid))
+ .and(WORKFLOW_EXECUTIONS.UID.eq(user.getUid))
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(FinishedStatuses))
+ .orderBy(WORKFLOW_EXECUTIONS.EID.desc())
+ .limit(1)
+ .fetchOneInto(classOf[Integer])
+ if (eid == null) {
+ throw new NotFoundException(s"you have no finished execution of workflow
$wid")
+ }
+ LatestExecution(eid)
+ }
+
+ /** The results of an execution, read from the database alone. */
+ @GET
+ @Path("/executions/{eid}")
+ def getResults(@PathParam("eid") eid: Integer, @Auth user: SessionUser):
List[PortResult] = {
+ requireReadable(eid, user)
+ context
+ .select(
+ OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID,
+ OPERATOR_PORT_EXECUTIONS.OUTPUT_MODE,
+ OPERATOR_PORT_EXECUTIONS.RESULT_COUNT
+ )
+ .from(OPERATOR_PORT_EXECUTIONS)
+ .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(eid))
+ .and(OPERATOR_PORT_EXECUTIONS.RESULT_URI.ne(""))
+ .fetch()
+ .asScala
+ .toList
+ .flatMap { row =>
+ val port = GlobalPortIdentitySerde.deserializeFromString(row.value1())
+ Option.when(!port.portId.internal) {
+ PortResult(
+ port.opId.logicalOpId.id,
+ port.portId.id,
+ Option(row.value2()).map(_.getLiteral).orNull,
+ row.value3()
+ )
+ }
+ }
+ .sortBy(result => (result.operatorId, result.portIndex))
+ }
+
+ /** One page of an operator's result. `pageIndex` starts from 1. */
+ @GET
+ @Path("/executions/{eid}/operators/{operatorId}/pages")
+ def getPage(
+ @PathParam("eid") eid: Integer,
+ @PathParam("operatorId") operatorId: String,
+ @QueryParam("port") @DefaultValue("0") port: Int,
+ @QueryParam("pageIndex") @DefaultValue("1") pageIndex: Int,
+ @QueryParam("pageSize") @DefaultValue("10") pageSize: Int,
+ @QueryParam("columnOffset") @DefaultValue("0") columnOffset: Int,
+ @QueryParam("columnLimit") @DefaultValue("2147483647") columnLimit: Int,
+ @QueryParam("columnSearch") @DefaultValue("") columnSearch: String,
+ @Auth user: SessionUser
+ ): ResultPage = {
+ requireReadable(eid, user)
+ if (
+ pageIndex < 1 || pageSize < 1 || pageSize > MaxPageSize || columnOffset
< 0 ||
+ columnLimit < 0 || pageIndex.toLong * pageSize > Int.MaxValue
+ ) {
+ throw new BadRequestException("the page or column range is out of
bounds")
+ }
+
+ val (document, schema) = openResult(eid, operatorId, port)
+ val columns = schema.getAttributeNames
+ .filter(_.toLowerCase.contains(columnSearch.toLowerCase))
+ .drop(columnOffset)
+ .take(columnLimit)
+ val from = pageSize * (pageIndex - 1)
+ val rows = document.getRange(from, from + pageSize, Some(columns)).toList
Review Comment:
`LARGE_BINARY` columns are passed as logical names (`image`), but
`IcebergDocument.getRange` projects physical names
(`image__texera_large_binary_ptr`), so page data can omit fields advertised in
its schema. `getStatistics` at line 202 has the reverse problem: its keys
retain the physical names. Translate projection names and decode statistics
keys in the shared storage layer, with regression coverage for both endpoints.
##########
result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.texera.service.resource
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.dropwizard.auth.Auth
+import jakarta.annotation.security.RolesAllowed
+import jakarta.ws.rs.core.MediaType
+import jakarta.ws.rs.{
+ BadRequestException,
+ DefaultValue,
+ ForbiddenException,
+ GET,
+ NotFoundException,
+ Path,
+ PathParam,
+ Produces,
+ QueryParam,
+ ServiceUnavailableException
+}
+import org.apache.texera.amber.core.storage.model.VirtualDocument
+import org.apache.texera.amber.core.storage.{
+ DocumentFactory,
+ ExecutionResultUris,
+ WarehouseReadGuard,
+ WarehouseUnavailableException
+}
+import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple,
TupleUtils}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
OperatorIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.auth.util.WorkflowAccess
+import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.Tables.{
+ OPERATOR_PORT_EXECUTIONS,
+ WORKFLOW_EXECUTIONS,
+ WORKFLOW_VERSION
+}
+import org.apache.texera.service.resource.ResultResource._
+import org.jooq.DSLContext
+
+import java.net.URI
+import scala.jdk.CollectionConverters._
+
+object ResultResource {
+ // workflow_executions.status of a run that has ended: COMPLETED, FAILED and
KILLED.
+ private val FinishedStatuses: java.util.List[java.lang.Short] =
+ List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava
+
+ // A page is read into memory in a service everyone shares, so one request
must not be able to
+ // ask for a whole table. This is far above the rows a result panel shows at
once.
+ private val MaxPageSize = 1000
+
+ private def context: DSLContext = SqlServer.getInstance().createDSLContext()
+
+ case class LatestExecution(eid: Integer)
+
+ /** One result of an execution. `outputMode` and `rowCount` are null where
not recorded. */
+ case class PortResult(
+ operatorId: String,
+ portIndex: Int,
+ outputMode: String,
+ rowCount: java.lang.Long
+ )
+
+ case class ResultPage(table: List[ObjectNode], schema: List[Attribute],
rowCount: Long)
+}
+
+/**
+ * Reads the results of an execution, running or finished. Each read loads
the table's current
+ * snapshot, so the pages of a running execution are as fresh as what it has
committed.
+ */
+@Path("/results")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@RolesAllowed(Array("REGULAR", "ADMIN"))
+class ResultResource(
+ openDocument: URI => (VirtualDocument[_], Option[Schema]) =
DocumentFactory.openDocument
+) {
+
+ /**
+ * The caller's own latest finished execution of a workflow. It names only
an execution the
+ * caller started, so it needs no access check of its own.
+ */
+ @GET
+ @Path("/workflows/{wid}/latest-execution")
+ def getLatestExecution(
+ @PathParam("wid") wid: Integer,
+ @Auth user: SessionUser
+ ): LatestExecution = {
+ val eid = context
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_VERSION.WID.eq(wid))
+ .and(WORKFLOW_EXECUTIONS.UID.eq(user.getUid))
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(FinishedStatuses))
+ .orderBy(WORKFLOW_EXECUTIONS.EID.desc())
+ .limit(1)
+ .fetchOneInto(classOf[Integer])
+ if (eid == null) {
+ throw new NotFoundException(s"you have no finished execution of workflow
$wid")
+ }
+ LatestExecution(eid)
+ }
+
+ /** The results of an execution, read from the database alone. */
+ @GET
+ @Path("/executions/{eid}")
+ def getResults(@PathParam("eid") eid: Integer, @Auth user: SessionUser):
List[PortResult] = {
+ requireReadable(eid, user)
+ context
+ .select(
+ OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID,
+ OPERATOR_PORT_EXECUTIONS.OUTPUT_MODE,
+ OPERATOR_PORT_EXECUTIONS.RESULT_COUNT
+ )
+ .from(OPERATOR_PORT_EXECUTIONS)
+ .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(eid))
+ .and(OPERATOR_PORT_EXECUTIONS.RESULT_URI.ne(""))
+ .fetch()
+ .asScala
+ .toList
+ .flatMap { row =>
+ val port = GlobalPortIdentitySerde.deserializeFromString(row.value1())
+ Option.when(!port.portId.internal) {
+ PortResult(
+ port.opId.logicalOpId.id,
+ port.portId.id,
+ Option(row.value2()).map(_.getLiteral).orNull,
+ row.value3()
+ )
+ }
+ }
+ .sortBy(result => (result.operatorId, result.portIndex))
+ }
+
+ /** One page of an operator's result. `pageIndex` starts from 1. */
+ @GET
+ @Path("/executions/{eid}/operators/{operatorId}/pages")
+ def getPage(
+ @PathParam("eid") eid: Integer,
+ @PathParam("operatorId") operatorId: String,
+ @QueryParam("port") @DefaultValue("0") port: Int,
+ @QueryParam("pageIndex") @DefaultValue("1") pageIndex: Int,
+ @QueryParam("pageSize") @DefaultValue("10") pageSize: Int,
+ @QueryParam("columnOffset") @DefaultValue("0") columnOffset: Int,
+ @QueryParam("columnLimit") @DefaultValue("2147483647") columnLimit: Int,
+ @QueryParam("columnSearch") @DefaultValue("") columnSearch: String,
+ @Auth user: SessionUser
+ ): ResultPage = {
+ requireReadable(eid, user)
+ if (
+ pageIndex < 1 || pageSize < 1 || pageSize > MaxPageSize || columnOffset
< 0 ||
+ columnLimit < 0 || pageIndex.toLong * pageSize > Int.MaxValue
+ ) {
+ throw new BadRequestException("the page or column range is out of
bounds")
+ }
+
+ val (document, schema) = openResult(eid, operatorId, port)
+ val columns = schema.getAttributeNames
+ .filter(_.toLowerCase.contains(columnSearch.toLowerCase))
+ .drop(columnOffset)
+ .take(columnLimit)
+ val from = pageSize * (pageIndex - 1)
+ val rows = document.getRange(from, from + pageSize, Some(columns)).toList
+ ResultPage(
+ TupleUtils.convertTuplesToJson(rows),
+ columns.map(schema.getAttribute),
+ document.getCount
+ )
+ }
+
+ /** Per-column statistics of an operator's result, from the table's
manifests. */
+ @GET
+ @Path("/executions/{eid}/operators/{operatorId}/statistics")
+ def getStatistics(
+ @PathParam("eid") eid: Integer,
+ @PathParam("operatorId") operatorId: String,
+ @QueryParam("port") @DefaultValue("0") port: Int,
+ @Auth user: SessionUser
+ ): Map[String, Map[String, Any]] = {
+ requireReadable(eid, user)
+ openResult(eid, operatorId, port)._1.getTableStatistics
Review Comment:
The underlying `IcebergDocument.getTableStatistics` initializes numeric and
timestamp min/max to extreme sentinel values and returns them unchanged when
the table is empty or a column contains only nulls. This endpoint therefore
reports those sentinels as real statistics for newly created or empty results.
Return min/max only when a manifest actually supplies bounds, and cover empty
and all-null columns.
##########
result-service/src/main/scala/org/apache/texera/service/resource/ResultResource.scala:
##########
@@ -0,0 +1,250 @@
+/*
+ * 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.texera.service.resource
+
+import com.fasterxml.jackson.databind.node.ObjectNode
+import io.dropwizard.auth.Auth
+import jakarta.annotation.security.RolesAllowed
+import jakarta.ws.rs.core.MediaType
+import jakarta.ws.rs.{
+ BadRequestException,
+ DefaultValue,
+ ForbiddenException,
+ GET,
+ NotFoundException,
+ Path,
+ PathParam,
+ Produces,
+ QueryParam,
+ ServiceUnavailableException
+}
+import org.apache.texera.amber.core.storage.model.VirtualDocument
+import org.apache.texera.amber.core.storage.{
+ DocumentFactory,
+ ExecutionResultUris,
+ WarehouseReadGuard,
+ WarehouseUnavailableException
+}
+import org.apache.texera.amber.core.tuple.{Attribute, Schema, Tuple,
TupleUtils}
+import org.apache.texera.amber.core.virtualidentity.{ExecutionIdentity,
OperatorIdentity}
+import org.apache.texera.amber.core.workflow.PortIdentity
+import org.apache.texera.amber.util.serde.GlobalPortIdentitySerde
+import org.apache.texera.auth.SessionUser
+import org.apache.texera.auth.util.WorkflowAccess
+import org.apache.texera.dao.SqlServer
+import org.apache.texera.dao.jooq.generated.Tables.{
+ OPERATOR_PORT_EXECUTIONS,
+ WORKFLOW_EXECUTIONS,
+ WORKFLOW_VERSION
+}
+import org.apache.texera.service.resource.ResultResource._
+import org.jooq.DSLContext
+
+import java.net.URI
+import scala.jdk.CollectionConverters._
+
+object ResultResource {
+ // workflow_executions.status of a run that has ended: COMPLETED, FAILED and
KILLED.
+ private val FinishedStatuses: java.util.List[java.lang.Short] =
+ List[java.lang.Short](3.toShort, 4.toShort, 5.toShort).asJava
+
+ // A page is read into memory in a service everyone shares, so one request
must not be able to
+ // ask for a whole table. This is far above the rows a result panel shows at
once.
+ private val MaxPageSize = 1000
+
+ private def context: DSLContext = SqlServer.getInstance().createDSLContext()
+
+ case class LatestExecution(eid: Integer)
+
+ /** One result of an execution. `outputMode` and `rowCount` are null where
not recorded. */
+ case class PortResult(
+ operatorId: String,
+ portIndex: Int,
+ outputMode: String,
+ rowCount: java.lang.Long
+ )
+
+ case class ResultPage(table: List[ObjectNode], schema: List[Attribute],
rowCount: Long)
+}
+
+/**
+ * Reads the results of an execution, running or finished. Each read loads
the table's current
+ * snapshot, so the pages of a running execution are as fresh as what it has
committed.
+ */
+@Path("/results")
+@Produces(Array(MediaType.APPLICATION_JSON))
+@RolesAllowed(Array("REGULAR", "ADMIN"))
+class ResultResource(
+ openDocument: URI => (VirtualDocument[_], Option[Schema]) =
DocumentFactory.openDocument
+) {
+
+ /**
+ * The caller's own latest finished execution of a workflow. It names only
an execution the
+ * caller started, so it needs no access check of its own.
+ */
+ @GET
+ @Path("/workflows/{wid}/latest-execution")
+ def getLatestExecution(
+ @PathParam("wid") wid: Integer,
+ @Auth user: SessionUser
+ ): LatestExecution = {
+ val eid = context
+ .select(WORKFLOW_EXECUTIONS.EID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_VERSION.WID.eq(wid))
+ .and(WORKFLOW_EXECUTIONS.UID.eq(user.getUid))
+ .and(WORKFLOW_EXECUTIONS.STATUS.in(FinishedStatuses))
+ .orderBy(WORKFLOW_EXECUTIONS.EID.desc())
+ .limit(1)
+ .fetchOneInto(classOf[Integer])
+ if (eid == null) {
+ throw new NotFoundException(s"you have no finished execution of workflow
$wid")
+ }
+ LatestExecution(eid)
+ }
+
+ /** The results of an execution, read from the database alone. */
+ @GET
+ @Path("/executions/{eid}")
+ def getResults(@PathParam("eid") eid: Integer, @Auth user: SessionUser):
List[PortResult] = {
+ requireReadable(eid, user)
+ context
+ .select(
+ OPERATOR_PORT_EXECUTIONS.GLOBAL_PORT_ID,
+ OPERATOR_PORT_EXECUTIONS.OUTPUT_MODE,
+ OPERATOR_PORT_EXECUTIONS.RESULT_COUNT
+ )
+ .from(OPERATOR_PORT_EXECUTIONS)
+ .where(OPERATOR_PORT_EXECUTIONS.WORKFLOW_EXECUTION_ID.eq(eid))
+ .and(OPERATOR_PORT_EXECUTIONS.RESULT_URI.ne(""))
+ .fetch()
+ .asScala
+ .toList
+ .flatMap { row =>
+ val port = GlobalPortIdentitySerde.deserializeFromString(row.value1())
+ Option.when(!port.portId.internal) {
+ PortResult(
+ port.opId.logicalOpId.id,
+ port.portId.id,
+ Option(row.value2()).map(_.getLiteral).orNull,
+ row.value3()
+ )
+ }
+ }
+ .sortBy(result => (result.operatorId, result.portIndex))
+ }
+
+ /** One page of an operator's result. `pageIndex` starts from 1. */
+ @GET
+ @Path("/executions/{eid}/operators/{operatorId}/pages")
+ def getPage(
+ @PathParam("eid") eid: Integer,
+ @PathParam("operatorId") operatorId: String,
+ @QueryParam("port") @DefaultValue("0") port: Int,
+ @QueryParam("pageIndex") @DefaultValue("1") pageIndex: Int,
+ @QueryParam("pageSize") @DefaultValue("10") pageSize: Int,
+ @QueryParam("columnOffset") @DefaultValue("0") columnOffset: Int,
+ @QueryParam("columnLimit") @DefaultValue("2147483647") columnLimit: Int,
+ @QueryParam("columnSearch") @DefaultValue("") columnSearch: String,
+ @Auth user: SessionUser
+ ): ResultPage = {
+ requireReadable(eid, user)
+ if (
+ pageIndex < 1 || pageSize < 1 || pageSize > MaxPageSize || columnOffset
< 0 ||
+ columnLimit < 0 || pageIndex.toLong * pageSize > Int.MaxValue
+ ) {
+ throw new BadRequestException("the page or column range is out of
bounds")
+ }
+
+ val (document, schema) = openResult(eid, operatorId, port)
+ val columns = schema.getAttributeNames
+ .filter(_.toLowerCase.contains(columnSearch.toLowerCase))
+ .drop(columnOffset)
+ .take(columnLimit)
+ val from = pageSize * (pageIndex - 1)
+ val rows = document.getRange(from, from + pageSize, Some(columns)).toList
+ ResultPage(
+ TupleUtils.convertTuplesToJson(rows),
+ columns.map(schema.getAttribute),
+ document.getCount
+ )
+ }
+
+ /** Per-column statistics of an operator's result, from the table's
manifests. */
+ @GET
+ @Path("/executions/{eid}/operators/{operatorId}/statistics")
+ def getStatistics(
+ @PathParam("eid") eid: Integer,
+ @PathParam("operatorId") operatorId: String,
+ @QueryParam("port") @DefaultValue("0") port: Int,
+ @Auth user: SessionUser
+ ): Map[String, Map[String, Any]] = {
+ requireReadable(eid, user)
+ openResult(eid, operatorId, port)._1.getTableStatistics
+ }
+
+ /**
+ * The caller may read an execution they started, or any execution of a
workflow they own or
+ * were granted. Being able to see a workflow because it is public is not
enough: a public
+ * workflow shows what its author published, not what an execution of it
read from private
+ * datasets. An execution that does not exist gets the same refusal, so ids
cannot be probed.
+ */
+ private def requireReadable(eid: Integer, user: SessionUser): Unit = {
+ val execution = context
+ .select(WORKFLOW_VERSION.WID, WORKFLOW_EXECUTIONS.UID)
+ .from(WORKFLOW_EXECUTIONS)
+ .join(WORKFLOW_VERSION)
+ .on(WORKFLOW_VERSION.VID.eq(WORKFLOW_EXECUTIONS.VID))
+ .where(WORKFLOW_EXECUTIONS.EID.eq(eid))
+ .fetchOne()
+ val readable = execution != null && (
+ execution.value2() == user.getUid ||
+ WorkflowAccess.hasGrantedAccess(execution.value1(), user.getUid)
+ )
+ if (!readable) {
+ throw new ForbiddenException(s"you cannot read the results of execution
$eid")
+ }
+ }
+
+ private def openResult(
+ eid: Integer,
+ operatorId: String,
+ port: Int
+ ): (VirtualDocument[Tuple], Schema) = {
+ val uri = ExecutionResultUris
+ .getResultUriByLogicalPortId(
+ ExecutionIdentity(eid.longValue()),
+ OperatorIdentity(operatorId),
+ PortIdentity(port)
+ )
+ .getOrElse(throw new NotFoundException(s"no result for operator
$operatorId, port $port"))
+ try {
+ WarehouseReadGuard.assertReadable(uri)
+ val document = openDocument(uri)
+ (document._1.asInstanceOf[VirtualDocument[Tuple]], document._2.get)
+ } catch {
+ case e: WarehouseUnavailableException => throw new
ServiceUnavailableException(e.getMessage)
+ case e: IllegalArgumentException if e.getMessage.contains("No storage is
found") =>
+ throw new NotFoundException(s"the result of operator $operatorId is no
longer stored")
Review Comment:
`IcebergUtil.loadTableMetadata` turns every catalog exception into `None`,
so a Lakekeeper timeout or authorization failure reaches this branch as a false
404. The same swallowing can also produce a successful empty page if the later
`getRange`/`getCount` lookup fails. Preserve non-missing-table errors in the
shared loader and return a server error, reserving 404 for a genuinely missing
table.
--
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]