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