You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by GitBox <gi...@apache.org> on 2021/12/22 06:44:34 UTC

[GitHub] [incubator-kyuubi] ulysses-you commented on a change in pull request #1576: [KYUUBI #1575] Implement api: /${version}/operations/${operation_identifier}/resultsetmetadata

ulysses-you commented on a change in pull request #1576:
URL: https://github.com/apache/incubator-kyuubi/pull/1576#discussion_r773637383



##########
File path: kyuubi-server/src/main/scala/org/apache/kyuubi/server/api/v1/OperationsResource.scala
##########
@@ -81,4 +83,42 @@ private[v1] class OperationsResource extends ApiRequestContext {
           s"for operation handle $operationHandleStr")
     }
   }
+
+  @ApiResponse(
+    responseCode = "200",
+    content = Array(new Content(
+      mediaType = MediaType.APPLICATION_JSON)),
+    description =
+      "get result set metadata")
+  @GET
+  @Path("{operationHandle}/resultsetmetadata")
+  def getResultSetMetadata(
+      @PathParam("operationHandle") operationHandleStr: String): ResultSetMetaData = {
+    try {
+      val operationHandle = parseOperationHandle(operationHandleStr)
+      ResultSetMetaData(
+        backendService.getResultSetMetadata(operationHandle).getColumns.asScala.map(c => {
+          val tPrimitiveTypeEntry = c.getTypeDesc.getTypes.get(0).getPrimitiveEntry
+          var precision = 0
+          var scale = 0
+          if (tPrimitiveTypeEntry.getTypeQualifiers != null) {
+            val qualifiers = tPrimitiveTypeEntry.getTypeQualifiers.getQualifiers
+            val defaultValue = TTypeQualifierValue.i32Value(0);
+            precision = qualifiers.getOrDefault("precision", defaultValue).getI32Value
+            scale = qualifiers.getOrDefault("scale", defaultValue).getI32Value
+          }
+          ColumnDesc(
+            c.getColumnName,
+            tPrimitiveTypeEntry.getType.toString,
+            c.getPosition,
+            precision,
+            scale,
+            c.getComment)
+        }))
+    } catch {
+      case NonFatal(_) =>
+        throw new NotFoundException(
+          s"Error getting result set metadata for operation handle $operationHandleStr")

Review comment:
       can we also add a unit test for negative case ?




-- 
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: commits-unsubscribe@kyuubi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org