Skip to content

Commit c42f31e

Browse files
simon824yaooqinn
authored andcommitted
[KYUUBI #1620] Implement api: /${version}/operations/${operation_identifier}/log
### _Why are the changes needed?_ closes #1620 Implement api: /${version}/operations/${operation_identifier}/log ### _How was this patch tested?_ - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible - [ ] Add screenshots for manual tests if appropriate - [ ] [Run test](https://kyuubi.readthedocs.io/en/latest/develop_tools/testing.html#running-tests) locally before make a pull request Closes #1621 from simon824/1223. Closes #1620 5f21147 [simon] rm f6d0ce7 [simon] fix 346df79 [simon] operationLog c60d344 [simon] init Authored-by: simon <zhangshiming@cvte.com> Signed-off-by: Kent Yao <yao@apache.org>
1 parent fbccba9 commit c42f31e

File tree

4 files changed

+54
-4
lines changed

4 files changed

+54
-4
lines changed

kyuubi-common/src/test/scala/org/apache/kyuubi/operation/NoopOperationManager.scala

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package org.apache.kyuubi.operation
1919

20-
import org.apache.hive.service.rpc.thrift.TRowSet
20+
import java.nio.ByteBuffer
21+
import java.util
22+
23+
import org.apache.hive.service.rpc.thrift.{TColumn, TRow, TRowSet, TStringColumn}
2124

2225
import org.apache.kyuubi.operation.FetchOrientation.FetchOrientation
2326
import org.apache.kyuubi.session.Session
24-
import org.apache.kyuubi.util.ThriftUtils
2527

2628
class NoopOperationManager extends OperationManager("noop") {
2729
private val invalid = "invalid"
@@ -91,5 +93,12 @@ class NoopOperationManager extends OperationManager("noop") {
9193
override def getOperationLogRowSet(
9294
opHandle: OperationHandle,
9395
order: FetchOrientation,
94-
maxRows: Int): TRowSet = ThriftUtils.EMPTY_ROW_SET
96+
maxRows: Int): TRowSet = {
97+
val logs = new util.ArrayList[String]()
98+
logs.add("test")
99+
val tColumn = TColumn.stringVal(new TStringColumn(logs, ByteBuffer.allocate(0)))
100+
val tRow = new TRowSet(0, new util.ArrayList[TRow](logs.size()))
101+
tRow.addToColumns(tColumn)
102+
tRow
103+
}
95104
}

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/OperationsResource.scala

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import org.apache.hive.service.rpc.thrift.TTypeQualifierValue
3030

3131
import org.apache.kyuubi.KyuubiSQLException
3232
import org.apache.kyuubi.events.KyuubiOperationEvent
33-
import org.apache.kyuubi.operation.KyuubiOperation
33+
import org.apache.kyuubi.operation.{FetchOrientation, KyuubiOperation}
3434
import org.apache.kyuubi.operation.OperationHandle.parseOperationHandle
3535
import org.apache.kyuubi.server.api.ApiRequestContext
3636

@@ -121,4 +121,29 @@ private[v1] class OperationsResource extends ApiRequestContext {
121121
s"Error getting result set metadata for operation handle $operationHandleStr")
122122
}
123123
}
124+
125+
@ApiResponse(
126+
responseCode = "200",
127+
content = Array(new Content(
128+
mediaType = MediaType.APPLICATION_JSON)),
129+
description =
130+
"get operation log")
131+
@GET
132+
@Path("{operationHandle}/log")
133+
def getOperationLog(
134+
@PathParam("operationHandle") operationHandleStr: String,
135+
@QueryParam("maxrows") maxRows: Int): OperationLog = {
136+
try {
137+
val rowSet = backendService.sessionManager.operationManager.getOperationLogRowSet(
138+
parseOperationHandle(operationHandleStr),
139+
FetchOrientation.FETCH_NEXT,
140+
maxRows)
141+
val logRowSet = rowSet.getColumns.get(0).getStringVal.getValues.asScala
142+
OperationLog(logRowSet, logRowSet.size)
143+
} catch {
144+
case NonFatal(_) =>
145+
throw new NotFoundException(
146+
s"Error getting operation log for operation handle $operationHandleStr")
147+
}
148+
}
124149
}

kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/dto.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,5 @@ case class ColumnDesc(
7979
precision: Int,
8080
scale: Int,
8181
comment: String)
82+
83+
case class OperationLog(logRowSet: Seq[String], rowCount: Int)

kyuubi-server/src/test/scala/org/apache/kyuubi/server/api/v1/OperationsResourceSuite.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,20 @@ class OperationsResourceSuite extends KyuubiFunSuite with RestFrontendTestHelper
9292
}
9393
}
9494

95+
test("test get operation log") {
96+
withKyuubiRestServer { (fe, _, _, webTarget: WebTarget) =>
97+
val opHandleStr = getOpHandleStr(fe, OperationType.EXECUTE_STATEMENT)
98+
val response = webTarget.path(
99+
s"api/v1/operations/$opHandleStr/log")
100+
.queryParam("maxrows", "10")
101+
.request(MediaType.APPLICATION_JSON).get()
102+
assert(200 == response.getStatus)
103+
val logRowSet = response.readEntity(classOf[OperationLog])
104+
assert(logRowSet.logRowSet.head.equals("test"))
105+
assert(logRowSet.rowCount == 1)
106+
}
107+
}
108+
95109
def getOpHandleStr(fe: KyuubiRestFrontendService, typ: OperationType): String = {
96110
val sessionManager = fe.be.sessionManager
97111
val sessionHandle = sessionManager.openSession(

0 commit comments

Comments
 (0)