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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to