如何在运行时修改Typesafe Config中Parquet路径的日期参数?
Let's break down what went wrong here and fix it step by step.
First, here's your original config for context:
project { inputs { baseFile { paths = ["project/src/test/resources/inputs/parquet1/date=2020-11-01/"] type = parquet applyConversions = false } } }
Your error stems from using incorrect syntax to target the list element in the Config path. Typesafe Config uses [index] notation to access elements in a list, not Scala-style parentheses (0). When you wrote "project.inputs.baseFile.paths"(0), you were accidentally calling the apply method on the string itself, which resulted in an invalid truncated path (hence the error about adjacent periods).
The Correct Approach
To modify the first element in the paths list, use the proper path syntax with [0] to target the index, then create your new Config instance like this:
val newConfig = config.withValue( "project.inputs.baseFile.paths[0]", ConfigValueFactory.fromAnyRef("project/src/test/resources/inputs/parquet1/date=2020-10-01/") )
Why This Works
- The path
"project.inputs.baseFile.paths[0]"correctly points to the first element (index 0) of thepathslist in your config. - Since Config objects are immutable,
withValuereturns a brand new Config instance with your updated value, leaving the original config untouched.
If you ever need to replace the entire paths list instead of a single element, you can also pass a new list directly using fromIterable:
val updatedPaths = List("project/src/test/resources/inputs/parquet1/date=2020-10-01/") val newConfig = config.withValue( "project.inputs.baseFile.paths", ConfigValueFactory.fromIterable(updatedPaths) )
内容的提问来源于stack exchange,提问作者l3rn1ngData

