You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by "ulysses-you (via GitHub)" <gi...@apache.org> on 2023/01/30 02:02:02 UTC

[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4182: [KYUUBI #3934] Compatiable with Trino rest dto

ulysses-you commented on code in PR #4182:
URL: https://github.com/apache/kyuubi/pull/4182#discussion_r1090115493


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -166,4 +175,219 @@ object TrinoContext {
         throw new AssertionError(e)
     }
 
+  def createQueryResults(
+      queryId: String,
+      nextUri: URI,
+      queryHtmlUri: URI,
+      queryStatus: OperationStatus,
+      columns: Option[TGetResultSetMetadataResp] = None,
+      data: Option[TRowSet] = None): QueryResults = {
+
+    //    val queryHtmlUri = uriInfo.getRequestUriBuilder
+    //      .replacePath("ui/query.html").replaceQuery(queryId).build()
+
+    val columnList = columns match {
+      case Some(value) => convertTColumn(value)
+      case None => null
+    }
+    val rowList = data match {
+      case Some(value) => convertTRowSet(value)
+      case None => null
+    }
+
+    new QueryResults(
+      queryId,
+      queryHtmlUri,
+      nextUri,
+      nextUri,
+      columnList,
+      rowList,
+      StatementStats.builder.setState(queryStatus.state.name()).build(),
+      toQueryError(queryStatus),
+      defaultWarning,
+      null,
+      0L)
+  }
+
+  def convertTColumn(columns: TGetResultSetMetadataResp): util.List[Column] = {
+    columns.getSchema.getColumns.asScala.map(c => {
+      val tp = c.getTypeDesc.getTypes.get(0).getPrimitiveEntry.getType.name()
+      new Column(c.getColumnName, tp, new ClientTypeSignature(tp))
+    }).toList.asJava
+  }
+
+  def convertTRowSet(rowSet: TRowSet): util.List[util.List[Object]] = {
+    var dataSet: Array[scala.List[Object]] = Array()
+
+    if (rowSet.getColumns == null) {
+      return rowSet.getRows.asScala
+        .map(t => t.getColVals.asScala.map(v => v.getFieldValue.asInstanceOf[Object]).asJava)
+        .asJava
+    }
+
+    rowSet.getColumns.asScala.foreach {
+      case tColumn if tColumn.isSetBoolVal =>
+        val nulls = util.BitSet.valueOf(tColumn.getBoolVal.getNulls)
+        if (dataSet.isEmpty) {

Review Comment:
   shall we do initialize at beginning ?
   `val resultDataSet = new java.util.ArrayList[java.util.ArrayList](rowSet.getRowsSize)`



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -166,4 +175,219 @@ object TrinoContext {
         throw new AssertionError(e)
     }
 
+  def createQueryResults(
+      queryId: String,
+      nextUri: URI,
+      queryHtmlUri: URI,
+      queryStatus: OperationStatus,
+      columns: Option[TGetResultSetMetadataResp] = None,
+      data: Option[TRowSet] = None): QueryResults = {
+
+    //    val queryHtmlUri = uriInfo.getRequestUriBuilder
+    //      .replacePath("ui/query.html").replaceQuery(queryId).build()

Review Comment:
   please cleanup unused code



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

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


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@kyuubi.apache.org
For additional commands, e-mail: notifications-help@kyuubi.apache.org