in kyuubi-server/src/main/scala/org/apache/kyuubi/server/trino/api/TrinoContext.scala [88:142]
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.requestClientCapabilities.equalsIgnoreCase(k) =>
context.copy(clientCapabilities = v.headOption)
case k if TRINO_HEADERS.requestSource.equalsIgnoreCase(k) =>
context.copy(source = v.headOption)
case k if TRINO_HEADERS.requestCatalog.equalsIgnoreCase(k) =>
context.copy(catalog = v.headOption)
case k if TRINO_HEADERS.requestSchema.equalsIgnoreCase(k) =>
context.copy(schema = v.headOption)
case k if TRINO_HEADERS.requestLanguage.equalsIgnoreCase(k) =>
context.copy(language = v.headOption)
case k if TRINO_HEADERS.requestTraceToken.equalsIgnoreCase(k) =>
context.copy(traceToken = v.headOption)
case k if TRINO_HEADERS.requestClientInfo.equalsIgnoreCase(k) =>
context.copy(clientInfo = v.headOption)
case k if TRINO_HEADERS.requestClientTags.equalsIgnoreCase(k) && v.nonEmpty =>
context.copy(clientTags = v.head.split(",").toSet)
case k if TRINO_HEADERS.requestSession.equalsIgnoreCase(k) =>
val session = v.collect {
case kvPattern(key, value) => (key, urlDecode(value))
}.toMap
context.copy(session = session)
case k if TRINO_HEADERS.requestPreparedStatement.equalsIgnoreCase(k) =>
val preparedStatement = v.collect {
case kvPattern(key, value) => (key, urlDecode(value))
}.toMap
context.copy(preparedStatement = preparedStatement)
case k
if TRINO_HEADERS.requestTransactionId.equalsIgnoreCase(k)
&& v.headOption.exists(_ != "NONE") =>
throw new UnsupportedOperationException(s"$k is not currently supported")
case k if TRINO_HEADERS.requestPath.equalsIgnoreCase(k) =>
throw new UnsupportedOperationException(s"$k is not currently supported")
case k if TRINO_HEADERS.requestRole.equalsIgnoreCase(k) =>
throw new UnsupportedOperationException(s"$k is not currently supported")
case k if TRINO_HEADERS.requestResourceEstimate.equalsIgnoreCase(k) =>
throw new UnsupportedOperationException(s"$k is not currently supported")
case k if TRINO_HEADERS.requestExtraCredential.equalsIgnoreCase(k) =>
throw new UnsupportedOperationException(s"$k is not currently supported")
case k if TRINO_HEADERS.requestRole.equalsIgnoreCase(k) =>
throw new UnsupportedOperationException(s"$k is not currently supported")
case _ =>
context
}
}
}