You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by "dd-willgan (via GitHub)" <gi...@apache.org> on 2023/05/22 17:03:55 UTC

[GitHub] [pinot] dd-willgan commented on a diff in pull request #10785: Allow env var substibution for Pinot configs

dd-willgan commented on code in PR #10785:
URL: https://github.com/apache/pinot/pull/10785#discussion_r1200790730


##########
pinot-spi/src/main/java/org/apache/pinot/spi/env/CommonsConfigurationUtils.java:
##########
@@ -119,8 +120,56 @@ public static Map<String, Object> toMap(Configuration configuration) {
   }
 
   private static Object mapValue(String key, Configuration configuration) {
-    return Optional.of(configuration.getStringArray(key)).filter(values -> values.length > 1).<Object>map(
-        values -> Arrays.stream(values).collect(Collectors.joining(",")))
-        .orElseGet(() -> configuration.getProperty(key));
+    // For multi-value config, convert it to a single comma connected string value.
+    // For single-value config, return its raw property, unless it needs interpolation.
+    return Optional.of(configuration.getStringArray(key)).filter(values -> values.length > 1)
+        .<Object>map(values -> Arrays.stream(values).collect(Collectors.joining(","))).orElseGet(() -> {
+          Object rawProperty = configuration.getProperty(key);
+          if (!needInterpolate(rawProperty)) {
+            return rawProperty;
+          }
+          // The string value is converted to the requested type when accessing it via PinotConfiguration.
+          return configuration.getString(key);
+        });
+  }
+
+  public static boolean needInterpolate(Object rawProperty) {
+    if (rawProperty instanceof String) {
+      String strProperty = (String) rawProperty;
+      // e.g. if config value is '${sys:ENV_VAR_FOO}', it's replaced by value of env var ENV_VAR_FOO.

Review Comment:
   `${env:ENV_VAR_FOO}` would be replaced by env var ENV_VAR_FOO?



-- 
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: commits-unsubscribe@pinot.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org