Skip to content

Commit 6798e44

Browse files
committed
include env var info in generated docs
1 parent 3b3a0d6 commit 6798e44

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

common/src/main/scala/org/apache/comet/CometConf.scala

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,19 @@ private class TypedConfigBuilder[T](
879879
*/
880880
def createWithEnvVarOrDefault(envVar: String, default: T): ConfigEntry[T] = {
881881
val defaultValue = sys.env.get(envVar).map(converter).getOrElse(default)
882-
createWithDefault(defaultValue)
882+
val transformedDefault = converter(stringConverter(defaultValue))
883+
val conf = new ConfigEntryWithDefault[T](
884+
parent.key,
885+
transformedDefault,
886+
converter,
887+
stringConverter,
888+
parent._doc,
889+
parent._category,
890+
parent._public,
891+
parent._version,
892+
Some(envVar))
893+
CometConf.register(conf)
894+
conf
883895
}
884896
}
885897

@@ -908,6 +920,11 @@ private[comet] abstract class ConfigEntry[T](
908920

909921
def defaultValueString: String
910922

923+
/**
924+
* The environment variable name that can override this config's default value, if applicable.
925+
*/
926+
def envVar: Option[String] = None
927+
911928
override def toString: String = {
912929
s"ConfigEntry(key=$key, defaultValue=$defaultValueString, doc=$doc, " +
913930
s"public=$isPublic, version=$version)"
@@ -922,12 +939,15 @@ private[comet] class ConfigEntryWithDefault[T](
922939
doc: String,
923940
category: String,
924941
isPublic: Boolean,
925-
version: String)
942+
version: String,
943+
_envVar: Option[String] = None)
926944
extends ConfigEntry(key, valueConverter, stringConverter, doc, category, isPublic, version) {
927945
override def defaultValue: Option[T] = Some(_defaultValue)
928946

929947
override def defaultValueString: String = stringConverter(_defaultValue)
930948

949+
override def envVar: Option[String] = _envVar
950+
931951
def get(conf: SQLConf): T = {
932952
val tmp = conf.getConfString(key, null)
933953
if (tmp == null) {

spark/src/main/scala/org/apache/comet/GenerateDocs.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,22 @@ object GenerateDocs {
7474
// convert links to Markdown
7575
val doc =
7676
urlPattern.replaceAllIn(conf.doc.trim, m => s"[Comet ${m.group(1)} Guide](")
77+
// append env var info if present
78+
val docWithEnvVar = conf.envVar match {
79+
case Some(envVarName) =>
80+
s"$doc Can be overridden by environment variable `$envVarName`."
81+
case None => doc
82+
}
7783
if (conf.defaultValue.isEmpty) {
78-
w.write(s"| `${conf.key}` | $doc | |\n".getBytes)
84+
w.write(s"| `${conf.key}` | $docWithEnvVar | |\n".getBytes)
7985
} else {
8086
val isBytesConf = conf.key == COMET_ONHEAP_MEMORY_OVERHEAD.key
8187
if (isBytesConf) {
8288
val bytes = conf.defaultValue.get.asInstanceOf[Long]
83-
w.write(s"| `${conf.key}` | $doc | $bytes MiB |\n".getBytes)
89+
w.write(s"| `${conf.key}` | $docWithEnvVar | $bytes MiB |\n".getBytes)
8490
} else {
85-
w.write(s"| `${conf.key}` | $doc | ${conf.defaultValueString} |\n".getBytes)
91+
val defaultVal = conf.defaultValueString
92+
w.write(s"| `${conf.key}` | $docWithEnvVar | $defaultVal |\n".getBytes)
8693
}
8794
}
8895
}

0 commit comments

Comments
 (0)