jackylee-ch commented on code in PR #8328: URL: https://github.com/apache/incubator-gluten/pull/8328#discussion_r1897030688
########## shims/common/src/main/scala/org/apache/gluten/config/ConfigBuilder.scala: ########## @@ -0,0 +1,262 @@ +/* + * 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.gluten.config + +import org.apache.spark.network.util.ByteUnit +import org.apache.spark.network.util.JavaUtils + +import java.util.Locale +import java.util.concurrent.TimeUnit +import java.util.regex.Pattern; + +object BackendType extends Enumeration { + type BackendType = Value + val COMMON, VELOX, CLICKHOUSE = Value +} + +private[gluten] case class ConfigBuilder(key: String) { + import ConfigHelpers._ + + private[config] var _doc = "" + private[config] var _version = "" + private[config] var _backend = BackendType.COMMON + private[config] var _public = true + private[config] var _alternatives = List.empty[String] + private[config] var _onCreate: Option[ConfigEntry[_] => Unit] = None + + def doc(s: String): ConfigBuilder = { + _doc = s + this + } + + def version(s: String): ConfigBuilder = { + _version = s + this + } + + def backend(backend: BackendType.BackendType): ConfigBuilder = { + _backend = backend + this + } + + def internal(): ConfigBuilder = { + _public = false + this + } + + def onCreate(callback: ConfigEntry[_] => Unit): ConfigBuilder = { + _onCreate = Option(callback) + this + } + + def withAlternative(key: String): ConfigBuilder = { + _alternatives = _alternatives :+ key + this + } + + def intConf: TypedConfigBuilder[Int] = { + new TypedConfigBuilder(this, toNumber(_, _.toInt, key, "int")) + } + + def longConf: TypedConfigBuilder[Long] = { + new TypedConfigBuilder(this, toNumber(_, _.toLong, key, "long")) + } + + def doubleConf: TypedConfigBuilder[Double] = { + new TypedConfigBuilder(this, toNumber(_, _.toDouble, key, "double")) + } + + def booleanConf: TypedConfigBuilder[Boolean] = { + new TypedConfigBuilder(this, toBoolean(_, key)) + } + + def stringConf: TypedConfigBuilder[String] = { + new TypedConfigBuilder(this, identity) + } + + def timeConf(unit: TimeUnit): TypedConfigBuilder[Long] = { + new TypedConfigBuilder(this, timeFromString(_, unit), timeToString(_, unit)) + } + + def bytesConf(unit: ByteUnit): TypedConfigBuilder[Long] = { + new TypedConfigBuilder(this, byteFromString(_, unit), byteToString(_, unit)) + } + + def fallbackConf[T](fallback: ConfigEntry[T]): ConfigEntry[T] = { + val entry = + new ConfigEntryFallback[T](key, _doc, _version, _backend, _public, _alternatives, fallback) + _onCreate.foreach(_(entry)) + entry + } +} + +private object ConfigHelpers { + 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") + } + } + + def toBoolean(s: String, key: String): Boolean = { + try { + s.trim.toBoolean + } catch { + case _: IllegalArgumentException => + throw new IllegalArgumentException(s"$key should be boolean, but was $s") + } + } + + private val TIME_STRING_PATTERN = Pattern.compile("(-?[0-9]+)([a-z]+)?") + + def timeFromString(str: String, unit: TimeUnit): Long = { + val lower = str.toLowerCase(Locale.ROOT).trim Review Comment: Can we just use `JavaUtils.timeStringAs`? ########## shims/common/src/main/scala/org/apache/gluten/config/ConfigBuilder.scala: ########## @@ -0,0 +1,262 @@ +/* + * 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.gluten.config + +import org.apache.spark.network.util.ByteUnit +import org.apache.spark.network.util.JavaUtils + +import java.util.Locale +import java.util.concurrent.TimeUnit +import java.util.regex.Pattern; + +object BackendType extends Enumeration { + type BackendType = Value + val COMMON, VELOX, CLICKHOUSE = Value +} + +private[gluten] case class ConfigBuilder(key: String) { + import ConfigHelpers._ + + private[config] var _doc = "" + private[config] var _version = "" + private[config] var _backend = BackendType.COMMON + private[config] var _public = true + private[config] var _alternatives = List.empty[String] + private[config] var _onCreate: Option[ConfigEntry[_] => Unit] = None + + def doc(s: String): ConfigBuilder = { + _doc = s + this + } + + def version(s: String): ConfigBuilder = { + _version = s + this + } + + def backend(backend: BackendType.BackendType): ConfigBuilder = { + _backend = backend + this + } + + def internal(): ConfigBuilder = { + _public = false + this + } + + def onCreate(callback: ConfigEntry[_] => Unit): ConfigBuilder = { + _onCreate = Option(callback) + this + } + + def withAlternative(key: String): ConfigBuilder = { + _alternatives = _alternatives :+ key + this + } + + def intConf: TypedConfigBuilder[Int] = { + new TypedConfigBuilder(this, toNumber(_, _.toInt, key, "int")) + } + + def longConf: TypedConfigBuilder[Long] = { + new TypedConfigBuilder(this, toNumber(_, _.toLong, key, "long")) + } + + def doubleConf: TypedConfigBuilder[Double] = { + new TypedConfigBuilder(this, toNumber(_, _.toDouble, key, "double")) + } + + def booleanConf: TypedConfigBuilder[Boolean] = { + new TypedConfigBuilder(this, toBoolean(_, key)) + } + + def stringConf: TypedConfigBuilder[String] = { + new TypedConfigBuilder(this, identity) + } + + def timeConf(unit: TimeUnit): TypedConfigBuilder[Long] = { + new TypedConfigBuilder(this, timeFromString(_, unit), timeToString(_, unit)) + } + + def bytesConf(unit: ByteUnit): TypedConfigBuilder[Long] = { + new TypedConfigBuilder(this, byteFromString(_, unit), byteToString(_, unit)) + } + + def fallbackConf[T](fallback: ConfigEntry[T]): ConfigEntry[T] = { Review Comment: any different between `withAlternatives` and `fallbackConf`? maybe only use one of them? ########## shims/common/src/main/scala/org/apache/gluten/config/GlutenConfig.scala: ########## @@ -37,97 +38,90 @@ case class GlutenNumaBindingInfo( class GlutenConfig(conf: SQLConf) extends Logging { import GlutenConfig._ - def enableAnsiMode: Boolean = conf.ansiEnabled + def enableAnsiMode: Boolean = conf.getConf(ANSI_ENABLED) - def enableGluten: Boolean = conf.getConf(GLUTEN_ENABLED) + def enableGluten: Boolean = getConf(GLUTEN_ENABLED) // FIXME the option currently controls both JVM and native validation against a Substrait plan. - def enableNativeValidation: Boolean = conf.getConf(NATIVE_VALIDATION_ENABLED) + def enableNativeValidation: Boolean = getConf(NATIVE_VALIDATION_ENABLED) - def enableColumnarBatchScan: Boolean = conf.getConf(COLUMNAR_BATCHSCAN_ENABLED) + def enableColumnarBatchScan: Boolean = getConf(COLUMNAR_BATCHSCAN_ENABLED) - def enableColumnarFileScan: Boolean = conf.getConf(COLUMNAR_FILESCAN_ENABLED) + def enableColumnarFileScan: Boolean = getConf(COLUMNAR_FILESCAN_ENABLED) - def enableColumnarHiveTableScan: Boolean = conf.getConf(COLUMNAR_HIVETABLESCAN_ENABLED) + def enableColumnarHiveTableScan: Boolean = getConf(COLUMNAR_HIVETABLESCAN_ENABLED) def enableColumnarHiveTableScanNestedColumnPruning: Boolean = - conf.getConf(COLUMNAR_HIVETABLESCAN_NESTED_COLUMN_PRUNING_ENABLED) + getConf(COLUMNAR_HIVETABLESCAN_NESTED_COLUMN_PRUNING_ENABLED) - def enableVanillaVectorizedReaders: Boolean = conf.getConf(VANILLA_VECTORIZED_READERS_ENABLED) + def enableVanillaVectorizedReaders: Boolean = getConf(VANILLA_VECTORIZED_READERS_ENABLED) - def enableColumnarHashAgg: Boolean = conf.getConf(COLUMNAR_HASHAGG_ENABLED) + def enableColumnarHashAgg: Boolean = getConf(COLUMNAR_HASHAGG_ENABLED) - def forceToUseHashAgg: Boolean = conf.getConf(COLUMNAR_FORCE_HASHAGG_ENABLED) + def forceToUseHashAgg: Boolean = getConf(COLUMNAR_FORCE_HASHAGG_ENABLED) - def mergeTwoPhasesAggEnabled: Boolean = conf.getConf(MERGE_TWO_PHASES_ENABLED) + def mergeTwoPhasesAggEnabled: Boolean = getConf(MERGE_TWO_PHASES_ENABLED) - def enableColumnarProject: Boolean = conf.getConf(COLUMNAR_PROJECT_ENABLED) + def enableColumnarProject: Boolean = getConf(COLUMNAR_PROJECT_ENABLED) - def enableColumnarFilter: Boolean = conf.getConf(COLUMNAR_FILTER_ENABLED) + def enableColumnarFilter: Boolean = getConf(COLUMNAR_FILTER_ENABLED) - def enableColumnarSort: Boolean = conf.getConf(COLUMNAR_SORT_ENABLED) + def enableColumnarSort: Boolean = getConf(COLUMNAR_SORT_ENABLED) - def enableColumnarWindow: Boolean = conf.getConf(COLUMNAR_WINDOW_ENABLED) + def enableColumnarWindow: Boolean = getConf(COLUMNAR_WINDOW_ENABLED) - def enableColumnarWindowGroupLimit: Boolean = conf.getConf(COLUMNAR_WINDOW_GROUP_LIMIT_ENABLED) + def enableColumnarWindowGroupLimit: Boolean = getConf(COLUMNAR_WINDOW_GROUP_LIMIT_ENABLED) - def veloxColumnarWindowType: String = conf.getConfString(COLUMNAR_VELOX_WINDOW_TYPE.key) + def veloxColumnarWindowType: String = getConf(COLUMNAR_VELOX_WINDOW_TYPE) - def enableColumnarShuffledHashJoin: Boolean = conf.getConf(COLUMNAR_SHUFFLED_HASH_JOIN_ENABLED) + def enableColumnarShuffledHashJoin: Boolean = getConf(COLUMNAR_SHUFFLED_HASH_JOIN_ENABLED) def shuffledHashJoinOptimizeBuildSide: Boolean = - conf.getConf(COLUMNAR_SHUFFLED_HASH_JOIN_OPTIMIZE_BUILD_SIDE) + getConf(COLUMNAR_SHUFFLED_HASH_JOIN_OPTIMIZE_BUILD_SIDE) - def enableNativeColumnarToRow: Boolean = conf.getConf(COLUMNAR_COLUMNAR_TO_ROW_ENABLED) Review Comment: ok, we doesn't use this config, we should remove all of them in sperated pr. -- 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]
