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

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

yehere commented on code in PR #4182:
URL: https://github.com/apache/kyuubi/pull/4182#discussion_r1093185071


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -166,4 +175,176 @@ 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 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]] = {
+    val dataResult = new util.LinkedList[util.List[Object]]
+
+    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 (dataResult.isEmpty) {
+          (1 to tColumn.getBoolVal.getValuesSize).foreach(_ =>
+            dataResult.add(new util.LinkedList[Object]()))
+        }
+
+        tColumn.getBoolVal.getValues.asScala.zipWithIndex.foreach {
+          case (_, rowIdx) if nulls.get(rowIdx) =>
+            dataResult.get(rowIdx).add(None)

Review Comment:
   I've added some types testing 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: 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