You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/29 18:54:09 UTC

[GitHub] [arrow-datafusion] mrob95 opened a new pull request, #2812: Allow setting of config options via environment variables

mrob95 opened a new pull request, #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #2776 .
   
    # Rationale for this change
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   During `ConfigOptions::new`, scan the environment for datafusion config options and try to cast them to the appropriate type.
   
   I'm unsure exactly what the behaviour should be if someone passes an uncastable value in an env var. At the moment we just use the default value and silently ignore the env var, but this could be confusing for people. Would it be better to just panic?
   
   # Are there any user-facing changes?
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] mrob95 commented on a diff in pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
mrob95 commented on code in PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#discussion_r911083161


##########
datafusion/core/src/config.rs:
##########
@@ -179,7 +189,18 @@ impl ConfigOptions {
         let mut options = HashMap::new();
         let built_in = BuiltInConfigs::new();
         for config_def in &built_in.config_definitions {
-            options.insert(config_def.key.clone(), config_def.default_value.clone());
+            let config_value = {
+                let mut env_key = config_def.key.replace('.', "_");
+                env_key.make_ascii_uppercase();
+                match env::var(env_key) {
+                    Ok(value) => match scalar_from_string(value, &config_def.data_type) {
+                        Ok(value) => value,
+                        Err(_) => config_def.default_value.clone(),

Review Comment:
   Added a warning here



##########
datafusion/core/src/config.rs:
##########
@@ -260,4 +281,24 @@ mod test {
         assert!(config.get(invalid_key).is_none());
         assert!(!config.get_bool(invalid_key));
     }
+
+    #[test]
+    fn get_from_env() {

Review Comment:
   Done



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#discussion_r910502407


##########
datafusion/core/src/config.rs:
##########
@@ -179,7 +189,18 @@ impl ConfigOptions {
         let mut options = HashMap::new();
         let built_in = BuiltInConfigs::new();
         for config_def in &built_in.config_definitions {
-            options.insert(config_def.key.clone(), config_def.default_value.clone());
+            let config_value = {
+                let mut env_key = config_def.key.replace('.', "_");
+                env_key.make_ascii_uppercase();
+                match env::var(env_key) {
+                    Ok(value) => match scalar_from_string(value, &config_def.data_type) {
+                        Ok(value) => value,
+                        Err(_) => config_def.default_value.clone(),

Review Comment:
   I suggest telling the user about this via something like `warn!` or `eprintln!("WARNING: ignoring unparsable value...."`?



##########
datafusion/core/src/config.rs:
##########
@@ -260,4 +281,24 @@ mod test {
         assert!(config.get(invalid_key).is_none());
         assert!(!config.get_bool(invalid_key));
     }
+
+    #[test]
+    fn get_from_env() {

Review Comment:
   I agree changing the environment from this test is likely to be problematic as it would cause non deterministic behavior 
   
   I suggest creating a specific rust "integration test" (aka a file in https://github.com/apache/arrow-datafusion/tree/master/datafusion/core/tests) that tests the environment parsing
   
   One alternate I can think of is to use a subprocess / fork so that the environment of the calling process isn't modified. I think this may be a bit unsafe for various reasons, so I suggest the dedicated test instead
   
   



##########
datafusion/core/src/config.rs:
##########
@@ -161,6 +163,14 @@ impl BuiltInConfigs {
     }
 }
 
+fn scalar_from_string(value: String, target_type: &DataType) -> Result<ScalarValue> {
+    let value = ScalarValue::Utf8(Some(value));
+    let cast_options = cast::CastOptions { safe: false };

Review Comment:
   This is clever -- it may be worth putting directly in `ScalarValue` perhaps, perhaps something like
   
   ```rust
   impl ScalarValue {
     // ..
     fn try_new_string(value: String, target_type: &DataType) -> Result<Self> {
       ...
     }
   }
   ```



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#discussion_r912231041


##########
datafusion/common/src/scalar.rs:
##########
@@ -1433,6 +1433,14 @@ impl ScalarValue {
         })
     }
 
+    /// Try to parse `value` into a ScalarValue of type `target_type`
+    pub fn try_from_string(value: String, target_type: &DataType) -> Result<Self> {

Review Comment:
   ❀️ 



##########
datafusion-cli/src/main.rs:
##########
@@ -92,7 +92,7 @@ pub async fn main() -> Result<()> {
         env::set_current_dir(&p).unwrap();
     };
 
-    let mut session_config = SessionConfig::new().with_information_schema(true);
+    let mut session_config = SessionConfig::from_env().with_information_schema(true);

Review Comment:
   πŸ‘ 



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] avantgardnerio commented on pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
avantgardnerio commented on PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#issuecomment-1171362040

   I think the intention was to allow servers built on DataFusion (i.e. Ballista) to follow the commonly accepted 12 factor paradigm making them easy to administer via container environments like Kubernetes. As long as there is a single call like `ConfigOptions::from_env()` that the runtime environment can invoke, I think that requirement is satisfied.


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] mrob95 commented on pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
mrob95 commented on PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#issuecomment-1171441384

   πŸ‘ I've added `from_env` to `ConfigOptions` and `SessionConfig`


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] andygrove commented on pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#issuecomment-1170472411

   Thanks @mrob95 I will review this soon. @avantgardnerio suggested this feature so would be good to get his feedback as well.


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] mrob95 commented on a diff in pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
mrob95 commented on code in PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#discussion_r912168516


##########
datafusion/core/src/execution/context.rs:
##########
@@ -1041,6 +1041,22 @@ impl SessionConfig {
         Default::default()
     }
 
+    /// Create an execution config with config options read from the environment
+    pub fn from_env() -> Self {
+        Self {
+            target_partitions: num_cpus::get(),
+            default_catalog: DEFAULT_CATALOG.to_owned(),
+            default_schema: DEFAULT_SCHEMA.to_owned(),
+            create_default_catalog_and_schema: true,
+            information_schema: false,
+            repartition_joins: true,
+            repartition_aggregations: true,
+            repartition_windows: true,
+            parquet_pruning: true,
+            config_options: ConfigOptions::from_env(),
+        }

Review Comment:
   Ah yeah I meant to mention the copy-paste in the PR. The thinking behind leaving it this way was that most of these options will (I presume) go away soon as part of #2756. Your suggestion is cleaner though and building the hash table twice isn't a big deal πŸ‘ 



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] andygrove commented on a diff in pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
andygrove commented on code in PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#discussion_r912165234


##########
datafusion/core/src/execution/context.rs:
##########
@@ -1041,6 +1041,22 @@ impl SessionConfig {
         Default::default()
     }
 
+    /// Create an execution config with config options read from the environment
+    pub fn from_env() -> Self {
+        Self {
+            target_partitions: num_cpus::get(),
+            default_catalog: DEFAULT_CATALOG.to_owned(),
+            default_schema: DEFAULT_SCHEMA.to_owned(),
+            create_default_catalog_and_schema: true,
+            information_schema: false,
+            repartition_joins: true,
+            repartition_aggregations: true,
+            repartition_windows: true,
+            parquet_pruning: true,
+            config_options: ConfigOptions::from_env(),
+        }

Review Comment:
   Rather than copy and paste code from the `default` method here, perhaps it would be better to do something like this?
   
   ```suggestion
           let mut config = Self::default();
           config.config_options = ConfigOptions::from_env();
           config
   ```



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] mrob95 commented on pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
mrob95 commented on PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#issuecomment-1171062961

   > Since DataFusion can be used in various contexts inside other systems, I would like to be able to disable the "take configs from the environment" behavior to allow people to turn off potential "back doors" -- for example, I do not want to allow users of IOx, my project, to override internal datafusion settings via the environment.
   > So perhaps we could add a ConfigOptions::from_env() function rather than parsing environment from new()
   
   Good point. Is the intention of this feature to mainly be used for `datafusion-cli` and similar programs where the user doesn't have direct access to the session?
   
   If so I think your suggestion (or maybe a flag passed to `new`?) would work fine - `datafusion-cli` could use the env version and everyone else could use the normal version.


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] andygrove commented on pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
andygrove commented on PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#issuecomment-1171352809

   > > Since DataFusion can be used in various contexts inside other systems, I would like to be able to disable the "take configs from the environment" behavior to allow people to turn off potential "back doors" -- for example, I do not want to allow users of IOx, my project, to override internal datafusion settings via the environment.
   > > So perhaps we could add a ConfigOptions::from_env() function rather than parsing environment from new()
   > 
   > Good point. @avantgardnerio Is the intention of this feature to mainly be used for `datafusion-cli` and similar programs where the user doesn't have direct access to the session?
   > 
   > If so I think your suggestion would work fine - `datafusion-cli` could use the env version and everyone else could use the normal version.
   
   I also like having two different methods of constructing configs - one that allows env var overrides and one that does not. I can imagine that Ballista executors would want to use the env var version to allow for easier configuration in k8s through config maps for example. Also makes sense for the CLI, IMO.


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] codecov-commenter commented on pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#issuecomment-1170407680

   # [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2812?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#2812](https://codecov.io/gh/apache/arrow-datafusion/pull/2812?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (6bd068a) into [master](https://codecov.io/gh/apache/arrow-datafusion/commit/839a61896f0fc3f617a79da1dd4018b2aa6af283?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (839a618) will **increase** coverage by `0.00%`.
   > The diff coverage is `100.00%`.
   
   > :exclamation: Current head 6bd068a differs from pull request most recent head f8da096. Consider uploading reports for the commit f8da096 to get more accurate results
   
   ```diff
   @@           Coverage Diff           @@
   ##           master    #2812   +/-   ##
   =======================================
     Coverage   85.20%   85.21%           
   =======================================
     Files         274      274           
     Lines       48666    48695   +29     
   =======================================
   + Hits        41468    41497   +29     
     Misses       7198     7198           
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/arrow-datafusion/pull/2812?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Ξ” | |
   |---|---|---|
   | [datafusion/core/src/config.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2812/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9jb25maWcucnM=) | `93.61% <100.00%> (+2.84%)` | :arrow_up: |
   | [datafusion/core/src/physical\_plan/metrics/value.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2812/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb3JlL3NyYy9waHlzaWNhbF9wbGFuL21ldHJpY3MvdmFsdWUucnM=) | `86.93% <0.00%> (-0.51%)` | :arrow_down: |
   | [datafusion/common/src/scalar.rs](https://codecov.io/gh/apache/arrow-datafusion/pull/2812/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-ZGF0YWZ1c2lvbi9jb21tb24vc3JjL3NjYWxhci5ycw==) | `74.94% <0.00%> (+0.11%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2812?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Ξ” = absolute <relative> (impact)`, `ΓΈ = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/arrow-datafusion/pull/2812?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [839a618...f8da096](https://codecov.io/gh/apache/arrow-datafusion/pull/2812?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] mrob95 commented on a diff in pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
mrob95 commented on code in PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#discussion_r911084393


##########
datafusion/core/src/config.rs:
##########
@@ -161,6 +163,14 @@ impl BuiltInConfigs {
     }
 }
 
+fn scalar_from_string(value: String, target_type: &DataType) -> Result<ScalarValue> {
+    let value = ScalarValue::Utf8(Some(value));
+    let cast_options = cast::CastOptions { safe: false };

Review Comment:
   Added `try_from_string` to `ScalarValue` to match `try_from_array` πŸ‘ 



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] mrob95 commented on a diff in pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
mrob95 commented on code in PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812#discussion_r912190166


##########
datafusion/core/src/execution/context.rs:
##########
@@ -1041,6 +1041,22 @@ impl SessionConfig {
         Default::default()
     }
 
+    /// Create an execution config with config options read from the environment
+    pub fn from_env() -> Self {
+        Self {
+            target_partitions: num_cpus::get(),
+            default_catalog: DEFAULT_CATALOG.to_owned(),
+            default_schema: DEFAULT_SCHEMA.to_owned(),
+            create_default_catalog_and_schema: true,
+            information_schema: false,
+            repartition_joins: true,
+            repartition_aggregations: true,
+            repartition_windows: true,
+            parquet_pruning: true,
+            config_options: ConfigOptions::from_env(),
+        }

Review Comment:
   clippy found a better solution!



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb merged pull request #2812: Allow setting of config options via environment variables

Posted by GitBox <gi...@apache.org>.
alamb merged PR #2812:
URL: https://github.com/apache/arrow-datafusion/pull/2812


-- 
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: github-unsubscribe@arrow.apache.org

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