You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@kyuubi.apache.org by GitBox <gi...@apache.org> on 2023/01/07 12:29:35 UTC

[GitHub] [kyuubi] iodone opened a new pull request, #4121: [KYUUBI #3936] Parse trino http request header

iodone opened a new pull request, #4121:
URL: https://github.com/apache/kyuubi/pull/4121

   <!--
   Thanks for sending a pull request!
   
   Here are some tips for you:
     1. If this is your first time, please read our contributor guidelines: https://kyuubi.readthedocs.io/en/latest/community/CONTRIBUTING.html
     2. If the PR is related to an issue in https://github.com/apache/kyuubi/issues, add '[KYUUBI #XXXX]' in your PR title, e.g., '[KYUUBI #XXXX] Your PR title ...'.
     3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][KYUUBI #XXXX] Your PR title ...'.
   -->
   close #3936 
   ### _Why are the changes needed?_
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you add a feature, you can talk about the use case of it.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   
   
   ### _How was this patch tested?_
   - [x] Add some test cases that check the changes thoroughly including negative and positive cases if possible
   
   - [ ] Add screenshots for manual tests if appropriate
   
   - [x] [Run test](https://kyuubi.apache.org/docs/latest/develop_tools/testing.html#running-tests) locally before make a pull request
   


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


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#discussion_r1068838073


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+import io.trino.client.QueryResults
+
+// TODO: Request and Respone context, to be enriched
+/**
+ * The description and functionality of trino request
+ * and response's context
+ *
+ * @param user Specifies the session user, must be supplied with every query
+ * @param timeZone  The timezone for query processing
+ * @param clientCapabilities Exclusive for trino server
+ * @param source This supplies the name of the software that submitted the query,
+ *               e.g. `trino-jdbc` or `trino-cli` by default
+ * @param catalog The catalog context for query processing, will be set response
+ * @param schema The schema context for query processing
+ * @param language The language to use when processing the query and formatting results,
+ *               formatted as a Java Locale string, e.g., en-US for US English
+ * @param traceToken Trace token for correlating requests across systems
+ * @param clientInfo Extra information about the client
+ * @param clientTags Client tags for selecting resource groups. Example: abc,xyz
+ * @param preparedStatement `preparedStatement` are kv pairs, where the names
+ *                          are names of previously prepared SQL statements,
+ *                          and the values are keys that identify the
+ *                          executable form of the named prepared statements
+ */
+case class TrinoContext(
+    user: String,
+    timeZone: Option[String] = None,
+    clientCapabilities: Option[String] = None,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    language: Option[String] = None,
+    traceToken: Option[String] = None,
+    clientInfo: Option[String] = None,
+    clientTags: Set[String] = Set.empty,
+    session: Map[String, String] = Map.empty,
+    preparedStatement: Map[String, String] = Map.empty) {}
+
+object TrinoContext {
+
+  def apply(headers: HttpHeaders): TrinoContext = {
+    apply(headers.getRequestHeaders.asScala.toMap.map {
+      case (k, v) => (k, v.asScala.toList)
+    })
+  }
+
+  def apply(headers: Map[String, List[String]]): TrinoContext = {
+    val requestCtx = TrinoContext("")
+    val kvPattern = """(.+)=(.+)""".r
+    headers.foldLeft(requestCtx) { case (context, (k, v)) =>
+      k match {
+        case k if TRINO_HEADERS.requestUser.equalsIgnoreCase(k) && v.nonEmpty =>
+          context.copy(user = v.head)
+        case k if TRINO_HEADERS.requestTimeZone.equalsIgnoreCase(k) =>
+          context.copy(timeZone = v.headOption)
+        case k
+            if TRINO_HEADERS.requestTransactionId.equalsIgnoreCase(k)
+              && v.headOption.exists(_ != "NONE") =>
+          throw new UnsupportedOperationException(s"$k is not currently supported")

Review Comment:
   can we move all unsupported header to the end of match-case ? just for better readable



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


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#discussion_r1068838073


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+import io.trino.client.QueryResults
+
+// TODO: Request and Respone context, to be enriched
+/**
+ * The description and functionality of trino request
+ * and response's context
+ *
+ * @param user Specifies the session user, must be supplied with every query
+ * @param timeZone  The timezone for query processing
+ * @param clientCapabilities Exclusive for trino server
+ * @param source This supplies the name of the software that submitted the query,
+ *               e.g. `trino-jdbc` or `trino-cli` by default
+ * @param catalog The catalog context for query processing, will be set response
+ * @param schema The schema context for query processing
+ * @param language The language to use when processing the query and formatting results,
+ *               formatted as a Java Locale string, e.g., en-US for US English
+ * @param traceToken Trace token for correlating requests across systems
+ * @param clientInfo Extra information about the client
+ * @param clientTags Client tags for selecting resource groups. Example: abc,xyz
+ * @param preparedStatement `preparedStatement` are kv pairs, where the names
+ *                          are names of previously prepared SQL statements,
+ *                          and the values are keys that identify the
+ *                          executable form of the named prepared statements
+ */
+case class TrinoContext(
+    user: String,
+    timeZone: Option[String] = None,
+    clientCapabilities: Option[String] = None,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    language: Option[String] = None,
+    traceToken: Option[String] = None,
+    clientInfo: Option[String] = None,
+    clientTags: Set[String] = Set.empty,
+    session: Map[String, String] = Map.empty,
+    preparedStatement: Map[String, String] = Map.empty) {}
+
+object TrinoContext {
+
+  def apply(headers: HttpHeaders): TrinoContext = {
+    apply(headers.getRequestHeaders.asScala.toMap.map {
+      case (k, v) => (k, v.asScala.toList)
+    })
+  }
+
+  def apply(headers: Map[String, List[String]]): TrinoContext = {
+    val requestCtx = TrinoContext("")
+    val kvPattern = """(.+)=(.+)""".r
+    headers.foldLeft(requestCtx) { case (context, (k, v)) =>
+      k match {
+        case k if TRINO_HEADERS.requestUser.equalsIgnoreCase(k) && v.nonEmpty =>
+          context.copy(user = v.head)
+        case k if TRINO_HEADERS.requestTimeZone.equalsIgnoreCase(k) =>
+          context.copy(timeZone = v.headOption)
+        case k
+            if TRINO_HEADERS.requestTransactionId.equalsIgnoreCase(k)
+              && v.headOption.exists(_ != "NONE") =>
+          throw new UnsupportedOperationException(s"$k is not currently supported")

Review Comment:
   can we move all unsupported head to the end of match-case ?



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+import io.trino.client.QueryResults
+
+// TODO: Request and Respone context, to be enriched
+/**
+ * The description and functionality of trino request
+ * and response's context
+ *
+ * @param user Specifies the session user, must be supplied with every query
+ * @param timeZone  The timezone for query processing
+ * @param clientCapabilities Exclusive for trino server
+ * @param source This supplies the name of the software that submitted the query,
+ *               e.g. `trino-jdbc` or `trino-cli` by default
+ * @param catalog The catalog context for query processing, will be set response
+ * @param schema The schema context for query processing
+ * @param language The language to use when processing the query and formatting results,
+ *               formatted as a Java Locale string, e.g., en-US for US English
+ * @param traceToken Trace token for correlating requests across systems
+ * @param clientInfo Extra information about the client
+ * @param clientTags Client tags for selecting resource groups. Example: abc,xyz
+ * @param preparedStatement `preparedStatement` are kv pairs, where the names
+ *                          are names of previously prepared SQL statements,
+ *                          and the values are keys that identify the
+ *                          executable form of the named prepared statements
+ */
+case class TrinoContext(
+    user: String,
+    timeZone: Option[String] = None,
+    clientCapabilities: Option[String] = None,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    language: Option[String] = None,
+    traceToken: Option[String] = None,
+    clientInfo: Option[String] = None,
+    clientTags: Set[String] = Set.empty,
+    session: Map[String, String] = Map.empty,
+    preparedStatement: Map[String, String] = Map.empty) {}
+
+object TrinoContext {
+
+  def apply(headers: HttpHeaders): TrinoContext = {
+    apply(headers.getRequestHeaders.asScala.toMap.map {
+      case (k, v) => (k, v.asScala.toList)
+    })
+  }
+
+  def apply(headers: Map[String, List[String]]): TrinoContext = {
+    val requestCtx = TrinoContext("")
+    val kvPattern = """(.+)=(.+)""".r
+    headers.foldLeft(requestCtx) { case (context, (k, v)) =>
+      k match {
+        case k if TRINO_HEADERS.requestUser.equalsIgnoreCase(k) && v.nonEmpty =>
+          context.copy(user = v.head)
+        case k if TRINO_HEADERS.requestTimeZone.equalsIgnoreCase(k) =>
+          context.copy(timeZone = v.headOption)
+        case k
+            if TRINO_HEADERS.requestTransactionId.equalsIgnoreCase(k)
+              && v.headOption.exists(_ != "NONE") =>
+          throw new UnsupportedOperationException(s"$k is not currently supported")

Review Comment:
   can we move all unsupported head to the end of match-case ? just for better readable



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


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#discussion_r1064259580


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientSelectedRole, QueryResults}
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+
+// TODO: Request and Respone context, to be enriched
+case class TrinoContext(
+    user: String,
+    timeZone: String,
+    transactionId: String,
+    clientCapabilities: String,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    path: Option[String] = None,
+    language: Option[String] = None,
+    traceToken: Option[String] = None,
+    clientInfo: Option[String] = None,
+    clientTags: Set[String] = Set.empty,
+    session: Map[String, String] = Map.empty,
+    role: Map[String, ClientSelectedRole] = Map.empty,
+    preparedStatement: Map[String, String] = Map.empty,
+    resourceEstimate: Map[String, String] = Map.empty,

Review Comment:
   ditto



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientSelectedRole, QueryResults}
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+
+// TODO: Request and Respone context, to be enriched
+case class TrinoContext(
+    user: String,
+    timeZone: String,
+    transactionId: String,
+    clientCapabilities: String,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    path: Option[String] = None,
+    language: Option[String] = None,
+    traceToken: Option[String] = None,
+    clientInfo: Option[String] = None,
+    clientTags: Set[String] = Set.empty,
+    session: Map[String, String] = Map.empty,
+    role: Map[String, ClientSelectedRole] = Map.empty,
+    preparedStatement: Map[String, String] = Map.empty,
+    resourceEstimate: Map[String, String] = Map.empty,
+    extraCredentials: Map[String, String] = Map.empty) {}
+
+object TrinoContext {
+
+  def apply(headers: HttpHeaders): TrinoContext = {
+    apply(headers.getRequestHeaders.asScala.toMap.map {
+      case (k, v) => (k, v.asScala.toList)
+    })
+  }
+
+  def apply(headers: Map[String, List[String]]): TrinoContext = {
+    val requestCtx = TrinoContext("", "", "", "")
+    val kvPattern = """(.+)=(.+)""".r
+    headers.foldLeft(requestCtx) { case (acc, (k, v)) =>
+      k match {
+        case k if TRINO_HEADERS.requestUser.equalsIgnoreCase(k) && !v.forall(_ == "") =>

Review Comment:
   Seems we do not need to check if the value is empty ?
   ```scala
   k match {
     case TRINO_HEADERS.requestUser => context.copy(user = v)
     ...
   }
   ```



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientSelectedRole, QueryResults}
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+
+// TODO: Request and Respone context, to be enriched
+case class TrinoContext(
+    user: String,
+    timeZone: String,
+    transactionId: String,
+    clientCapabilities: String,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    path: Option[String] = None,
+    language: Option[String] = None,
+    traceToken: Option[String] = None,
+    clientInfo: Option[String] = None,
+    clientTags: Set[String] = Set.empty,
+    session: Map[String, String] = Map.empty,
+    role: Map[String, ClientSelectedRole] = Map.empty,

Review Comment:
   ditto



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientSelectedRole, QueryResults}
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+
+// TODO: Request and Respone context, to be enriched
+case class TrinoContext(

Review Comment:
   Better to add docs to explain all parameters. For example `source`:
   ````
   @source  the request where comes from, e.g. `trino-jdbc` or `trino-cli` by default.
   Can be arbitrary string if client specifies, e.g. In Trino JDBC url `jdbc:trino://host:port/;source=$source`
   ```



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientSelectedRole, QueryResults}
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+
+// TODO: Request and Respone context, to be enriched
+case class TrinoContext(
+    user: String,
+    timeZone: String,
+    transactionId: String,
+    clientCapabilities: String,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    path: Option[String] = None,

Review Comment:
   ditto



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientSelectedRole, QueryResults}
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+
+// TODO: Request and Respone context, to be enriched
+case class TrinoContext(
+    user: String,
+    timeZone: String,
+    transactionId: String,

Review Comment:
   We do not support transaction, should throw exception if it's defined in header.



##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala:
##########
@@ -0,0 +1,167 @@
+/*
+ * 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.io.UnsupportedEncodingException
+import java.net.{URLDecoder, URLEncoder}
+import javax.ws.rs.core.{HttpHeaders, Response}
+
+import scala.collection.JavaConverters._
+
+import io.trino.client.{ClientSelectedRole, QueryResults}
+import io.trino.client.ProtocolHeaders.TRINO_HEADERS
+
+// TODO: Request and Respone context, to be enriched
+case class TrinoContext(
+    user: String,
+    timeZone: String,
+    transactionId: String,
+    clientCapabilities: String,
+    source: Option[String] = None,
+    catalog: Option[String] = None,
+    schema: Option[String] = None,
+    path: Option[String] = None,
+    language: Option[String] = None,
+    traceToken: Option[String] = None,
+    clientInfo: Option[String] = None,
+    clientTags: Set[String] = Set.empty,
+    session: Map[String, String] = Map.empty,
+    role: Map[String, ClientSelectedRole] = Map.empty,
+    preparedStatement: Map[String, String] = Map.empty,
+    resourceEstimate: Map[String, String] = Map.empty,
+    extraCredentials: Map[String, String] = Map.empty) {}

Review Comment:
   ditto



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


[GitHub] [kyuubi] ulysses-you closed pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you closed pull request #4121: [KYUUBI #3936] Parse trino http request header
URL: https://github.com/apache/kyuubi/pull/4121


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


[GitHub] [kyuubi] iodone commented on a diff in pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
iodone commented on code in PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#discussion_r1068850088


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/api.scala:
##########
@@ -35,6 +35,8 @@ private[api] trait ApiRequestContext {
   @Context
   protected var httpRequest: HttpServletRequest = _
 
+  protected var trinoContext: TrinoContext = _

Review Comment:
   I plan to address this in the next issue. In the next issue(#3935) , there can be a complete request-response process, which will be more helpful for the design and implementation of `session`. WDYT?



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


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#discussion_r1068836459


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/v1/StatementResource.scala:
##########
@@ -54,8 +55,21 @@ private[v1] class StatementResource extends ApiRequestContext with Logging {
   @GET
   @Path("/")
   @Consumes(Array(MediaType.TEXT_PLAIN))
-  def query(statement: String, @Context headers: HttpHeaders): QueryResults = {
-    throw new UnsupportedOperationException
+  def query(statement: String, @Context headers: HttpHeaders): Response = {
+    trinoContext = TrinoContext(headers)
+    val qr = new QueryResults(
+      "id",
+      URI.create("info"),
+      URI.create("cancel"),
+      URI.create("next"),
+      null,
+      null,
+      null,
+      null,
+      null,
+      "update_type",
+      0)
+    TrinoContext.buildTrinoResponse(qr, trinoContext)

Review Comment:
    it still can not work after this pr. I think keeping throw a exception is better



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


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#discussion_r1068851467


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/api.scala:
##########
@@ -35,6 +35,8 @@ private[api] trait ApiRequestContext {
   @Context
   protected var httpRequest: HttpServletRequest = _
 
+  protected var trinoContext: TrinoContext = _

Review Comment:
   That's ok. but we should remove this code in this pr. It's no used and just make reviewer confused



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


[GitHub] [kyuubi] ulysses-you commented on a diff in pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on code in PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#discussion_r1068835607


##########
kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/api.scala:
##########
@@ -35,6 +35,8 @@ private[api] trait ApiRequestContext {
   @Context
   protected var httpRequest: HttpServletRequest = _
 
+  protected var trinoContext: TrinoContext = _

Review Comment:
   we should hold a `Map[id, TrinoContext]`, each request/session has it's own `TrinoContext`



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


[GitHub] [kyuubi] ulysses-you commented on pull request #4121: [KYUUBI #3936] Parse trino http request header

Posted by GitBox <gi...@apache.org>.
ulysses-you commented on PR #4121:
URL: https://github.com/apache/kyuubi/pull/4121#issuecomment-1381278465

   thanks, merging to master


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