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

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

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


##########
kyuubi-server/src/test/scala/org/apache/kyuubi/server/trino/api/v1/KyuubiTrinoQueryResultAdaptSuite.scala:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.kyuubi.server.trino.api.v1
+
+import java.net.URI
+import javax.ws.rs.core.MediaType
+
+import scala.collection.JavaConverters._
+
+import org.apache.hive.service.rpc.thrift.TProtocolVersion.HIVE_CLI_SERVICE_PROTOCOL_V9
+import org.scalatest.concurrent.PatienceConfiguration.Timeout
+import org.scalatest.time.SpanSugar.convertIntToGrainOfTime
+
+import org.apache.kyuubi.{KyuubiFunSuite, RestFrontendTestHelper}
+import org.apache.kyuubi.events.KyuubiOperationEvent
+import org.apache.kyuubi.operation.{FetchOrientation, OperationHandle}
+import org.apache.kyuubi.operation.OperationState.{FINISHED, OperationState}
+import org.apache.kyuubi.server.trino.api.KyuubiTrinoQueryResultAdapt
+
+class KyuubiTrinoQueryResultAdaptSuite extends KyuubiFunSuite with RestFrontendTestHelper {
+
+  test("test convert") {
+    val opHandle = getOpHandle("select 1")
+    val opHandleStr = opHandle.identifier.toString
+    checkOpState(opHandleStr, FINISHED)
+
+    val metadataResp = fe.be.getResultSetMetadata(opHandle)
+    val tRowSet = fe.be.fetchResults(opHandle, FetchOrientation.FETCH_NEXT, 1000, false)
+    val status = fe.be.getOperationStatus(opHandle)
+
+    val uri = new URI("sfdsfsdfdsf")
+    val results = KyuubiTrinoQueryResultAdapt
+      .createQueryResults("/xdfd/xdf", uri, uri, status, Option(metadataResp), Option(tRowSet))
+
+    print(results.toString)

Review Comment:
   remove



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/KyuubiTrinoQueryResultAdapt.scala:
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.kyuubi.server.trino.api
+
+import java.net.URI
+import java.util
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientTypeSignature, Column, QueryError, QueryResults, StatementStats, Warning}
+import org.apache.hive.service.rpc.thrift.{TGetResultSetMetadataResp, TRowSet}
+
+import org.apache.kyuubi.operation.OperationStatus
+
+object KyuubiTrinoQueryResultAdapt {
+  private val defaultWarning: util.List[Warning] = new util.ArrayList[Warning]()
+  private val GENERIC_INTERNAL_ERROR_CODE = 65536
+  private val GENERIC_INTERNAL_ERROR_NAME = "GENERIC_INTERNAL_ERROR_NAME"
+  private val GENERIC_INTERNAL_ERROR_TYPE = "INTERNAL_ERROR"
+
+  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()
+
+    new QueryResults(
+      queryId,
+      queryHtmlUri,
+      nextUri,
+      nextUri,
+      convertTColumn(columns),
+      convertTRowSet(data),
+      StatementStats.builder.setState(queryStatus.state.name()).build(),
+      toQueryError(queryStatus),
+      defaultWarning,
+      null,
+      0L)
+  }
+
+  def convertTColumn(columns: Option[TGetResultSetMetadataResp]): util.List[Column] = {
+    if (columns.isEmpty) {
+      return null
+    }
+
+    columns.get.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(data: Option[TRowSet]): util.List[util.List[Object]] = {

Review Comment:
   ditto



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/KyuubiTrinoQueryResultAdapt.scala:
##########
@@ -0,0 +1,249 @@
+/*
+ * 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.kyuubi.server.trino.api
+
+import java.net.URI
+import java.util
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientTypeSignature, Column, QueryError, QueryResults, StatementStats, Warning}
+import org.apache.hive.service.rpc.thrift.{TGetResultSetMetadataResp, TRowSet}
+
+import org.apache.kyuubi.operation.OperationStatus
+
+object KyuubiTrinoQueryResultAdapt {
+  private val defaultWarning: util.List[Warning] = new util.ArrayList[Warning]()
+  private val GENERIC_INTERNAL_ERROR_CODE = 65536
+  private val GENERIC_INTERNAL_ERROR_NAME = "GENERIC_INTERNAL_ERROR_NAME"
+  private val GENERIC_INTERNAL_ERROR_TYPE = "INTERNAL_ERROR"
+
+  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()
+
+    new QueryResults(
+      queryId,
+      queryHtmlUri,
+      nextUri,
+      nextUri,
+      convertTColumn(columns),
+      convertTRowSet(data),
+      StatementStats.builder.setState(queryStatus.state.name()).build(),
+      toQueryError(queryStatus),
+      defaultWarning,
+      null,
+      0L)
+  }
+
+  def convertTColumn(columns: Option[TGetResultSetMetadataResp]): util.List[Column] = {

Review Comment:
   I suggest to remove Option from the function parameters here and handle whether columns is empty in the outer layer



-- 
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