-
Notifications
You must be signed in to change notification settings - Fork 867
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HIVE_CLI_SERVICE_PROTOCOL_V11 (#235)
* HIVE_CLI_SERVICE_PROTOCOL_V11 * pom * style * tests * travis * code cover
- Loading branch information
Showing
158 changed files
with
69,105 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
kyuubi-common/src/main/scala/org/apache/kyuubi/config/ConfigBuilder.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* | ||
* 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.config | ||
|
||
private[kyuubi] case class ConfigBuilder(key: String) { | ||
|
||
private[config] var _doc = "" | ||
private[config] var _version = "" | ||
|
||
def doc(s: String): ConfigBuilder = { | ||
_doc = s | ||
this | ||
} | ||
|
||
def version(s: String): ConfigBuilder = { | ||
_version = s | ||
this | ||
} | ||
|
||
private def toNumber[T](s: String, converter: String => T, configType: String): T = { | ||
try { | ||
converter(s.trim) | ||
} catch { | ||
case _: NumberFormatException => | ||
throw new IllegalArgumentException(s"$key should be $configType, but was $s") | ||
} | ||
} | ||
|
||
def intConf: TypedConfigBuilder[Int] = { | ||
new TypedConfigBuilder(this, toNumber(_, _.toInt, "int")) | ||
} | ||
|
||
def longConf: TypedConfigBuilder[Long] = { | ||
new TypedConfigBuilder(this, toNumber(_, _.toLong, "long")) | ||
} | ||
|
||
def doubleConf: TypedConfigBuilder[Double] = { | ||
new TypedConfigBuilder(this, toNumber(_, _.toDouble, "double")) | ||
} | ||
|
||
def booleanConf: TypedConfigBuilder[Boolean] = { | ||
def toBoolean(s: String) = try { | ||
s.trim.toBoolean | ||
} catch { | ||
case e: IllegalArgumentException => | ||
throw new IllegalArgumentException(s"$key should be boolean, but was $s", e) | ||
} | ||
new TypedConfigBuilder(this, toBoolean) | ||
} | ||
|
||
def stringConf: TypedConfigBuilder[String] = { | ||
new TypedConfigBuilder(this, identity) | ||
} | ||
} | ||
|
||
private[kyuubi] case class TypedConfigBuilder[T]( | ||
parent: ConfigBuilder, | ||
fromStr: String => T, | ||
toStr: T => String) { | ||
|
||
import ConfigHelpers._ | ||
|
||
def this(parent: ConfigBuilder, fromStr: String => T) = | ||
this(parent, fromStr, Option[T](_).map(_.toString).orNull) | ||
|
||
def transform(fn: T => T): TypedConfigBuilder[T] = this.copy(fromStr = s => fn(fromStr(s))) | ||
|
||
/** Checks if the user-provided value for the config matches the validator. */ | ||
def checkValue(validator: T => Boolean, errMsg: String): TypedConfigBuilder[T] = { | ||
transform { v => | ||
if (!validator(v)) throw new IllegalArgumentException(errMsg) | ||
v | ||
} | ||
} | ||
|
||
/** Check that user-provided values for the config match a pre-defined set. */ | ||
def checkValues(validValues: Set[T]): TypedConfigBuilder[T] = { | ||
transform { v => | ||
if (!validValues.contains(v)) { | ||
throw new IllegalArgumentException( | ||
s"The value of ${parent.key} should be one of ${validValues.mkString(", ")}, but was $v") | ||
} | ||
v | ||
} | ||
} | ||
|
||
/** Turns the config entry into a sequence of values of the underlying type. */ | ||
def toSequence: TypedConfigBuilder[Seq[T]] = { | ||
TypedConfigBuilder(parent, strToSeq(_, fromStr), seqToStr(_, toStr)) | ||
} | ||
|
||
def createOptional: OptionalConfigEntry[T] = OptionalConfigEntry( | ||
parent.key, fromStr, toStr, parent._doc, parent._version) | ||
|
||
def createWithDefault(default: T): ConfigEntry[T] = default match { | ||
case d: String => createWithDefaultString(d) | ||
case _ => | ||
val d = fromStr(toStr(default)) | ||
ConfigEntryWithDefault(parent.key, d, fromStr, toStr, parent._doc, parent._version) | ||
} | ||
|
||
def createWithDefaultString(default: String): ConfigEntryWithDefaultString[T] = { | ||
ConfigEntryWithDefaultString(parent.key, default, fromStr, toStr, parent._doc, parent._version) | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
kyuubi-common/src/main/scala/org/apache/kyuubi/config/ConfigEntry.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* 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.config | ||
|
||
trait ConfigEntry[T] { | ||
def key: String | ||
def valueConverter: String => T | ||
def strConverter: T => String | ||
def doc: String | ||
def version: String | ||
|
||
def defaultValStr: String | ||
def defaultVal: Option[T] = None | ||
|
||
final override def toString: String = { | ||
s"ConfigEntry(key=$key, defaultValue=$defaultValStr, doc=$doc, version=$version)" | ||
} | ||
|
||
final protected def readString(provider: ConfigProvider): Option[String] = { | ||
provider.get(key) | ||
} | ||
|
||
def readFrom(conf: ConfigProvider): T | ||
|
||
ConfigEntry.registerEntry(this) | ||
} | ||
|
||
case class OptionalConfigEntry[T]( | ||
key: String, | ||
rawValueConverter: String => T, | ||
rawStrConverter: T => String, | ||
doc: String, | ||
version: String) extends ConfigEntry[Option[T]] { | ||
override def valueConverter: String => Option[T] = s => Option(rawValueConverter(s)) | ||
|
||
override def strConverter: Option[T] => String = v => v.map(rawStrConverter).orNull | ||
|
||
override def defaultValStr: String = ConfigEntry.UNDEFINED | ||
|
||
override def readFrom(conf: ConfigProvider): Option[T] = { | ||
readString(conf).map(rawValueConverter) | ||
} | ||
} | ||
|
||
case class ConfigEntryWithDefault[T]( | ||
key: String, | ||
_defaultVal: T, | ||
valueConverter: String => T, | ||
strConverter: T => String, | ||
doc: String, | ||
version: String) extends ConfigEntry[T] { | ||
override def defaultValStr: String = strConverter(_defaultVal) | ||
|
||
override def defaultVal: Option[T] = Option(_defaultVal) | ||
|
||
override def readFrom(conf: ConfigProvider): T = { | ||
readString(conf).map(valueConverter).getOrElse(_defaultVal) | ||
} | ||
} | ||
|
||
case class ConfigEntryWithDefaultString[T]( | ||
key: String, | ||
_defaultVal: String, | ||
valueConverter: String => T, | ||
strConverter: T => String, | ||
doc: String, | ||
version: String) extends ConfigEntry[T] { | ||
override def defaultValStr: String = _defaultVal | ||
|
||
override def defaultVal: Option[T] = Some(valueConverter(_defaultVal)) | ||
|
||
override def readFrom(conf: ConfigProvider): T = { | ||
val value = readString(conf).getOrElse(_defaultVal) | ||
valueConverter(value) | ||
} | ||
} | ||
|
||
object ConfigEntry { | ||
val UNDEFINED = "<undefined>" | ||
|
||
private val knownConfigs = new java.util.concurrent.ConcurrentHashMap[String, ConfigEntry[_]]() | ||
|
||
def registerEntry(entry: ConfigEntry[_]): Unit = { | ||
val existing = knownConfigs.putIfAbsent(entry.key, entry) | ||
require(existing == null, s"Config entry ${entry.key} already registered!") | ||
} | ||
|
||
def findEntry(key: String): ConfigEntry[_] = knownConfigs.get(key) | ||
} |
40 changes: 40 additions & 0 deletions
40
kyuubi-common/src/main/scala/org/apache/kyuubi/config/ConfigHelpers.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* 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.config | ||
|
||
import org.apache.kyuubi.Utils | ||
|
||
object ConfigHelpers { | ||
|
||
def strToSeq[T](str: String, converter: String => T): Seq[T] = { | ||
Utils.strToSeq(str).map(converter) | ||
} | ||
|
||
def seqToStr[T](v: Seq[T], stringConverter: T => String): String = { | ||
v.map(stringConverter).mkString(",") | ||
} | ||
|
||
def toNumber[T](s: String, converter: String => T, key: String, configType: String): T = { | ||
try { | ||
converter(s.trim) | ||
} catch { | ||
case _: NumberFormatException => | ||
throw new IllegalArgumentException(s"$key should be $configType, but was $s") | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
kyuubi-common/src/main/scala/org/apache/kyuubi/config/ConfigProvider.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* 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.config | ||
|
||
private[kyuubi] class ConfigProvider(conf: java.util.Map[String, String]) { | ||
|
||
def get(key: String): Option[String] = { | ||
if (key.startsWith(KYUUBI_PREFIX)) { | ||
Option(conf.get(key)) | ||
} else { | ||
None | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.