← Back to Pull requests

refactor: drive `datafusion.runtime.*` config from a `ConfigField` schema #25114

Open
haochunchang opened this pull request with 1239 lines diff across 6 files
View on GitHub
haochunchang haochunchang commented on Sep 09, 2026 13:36 UTC
Author

Which issue does this PR close?

  • Closes #23322.
  • Rationale for this change

    The eight datafusion.runtime. keys were duplicated across 6 places:

  • RuntimeConfigValues and its into_config_entries

  • value derivation in RuntimeEnv::config_entries

  • a hardcoded default table in RuntimeEnvBuilder::entries

  • a hand-written match arm per key in both set_runtime_variable and reset_runtime_variable.
  • A comment asked contributors to keep the two match statements in sync by hand, and the hand-rolled parsing is what caused the panic fixed in #23316.

    #23322 asks whether runtime config can use the same type-checked framework as SessionConfig/ConfigOptions instead of its own SET/RESET path.

    This PR does that for parsing and dispatch:

  • RuntimeOptions is built with the same config_namespace!/config_field! macros that back ConfigOptions, so SET/RESET now go through ConfigField

  • Adding a runtime option is a one-line struct field instead of six edits.
  • RuntimeOptions stays a separate struct rather than joining ConfigOptions:

  • datafusion-execution depends on datafusion-common, never the reverse - ConfigOptions can't hold it.

  • It isn't a ConfigExtension, since extension prefixes may never be datafusion.

  • Fully merging the two option sets is the harder, separate problem the issue itself calls out (runtime config is shared across SessionConfigs and can change mid-execution).
  • This PR only unifies the framework underneath, not the two config sets themselves.

    What changes are included in this PR?

    1. Add datafusion_execution::runtime_options::RuntimeOptions (crate-private) - single source of truth for the eight keys' names, descriptions, defaults, and parsing.
    2. Add RuntimeEnvBuilder::with_config_entry and with_default_config_entry, which take a full datafusion.runtime.
    key and change only that entry.
    - set_runtime_variable/reset_runtime_variable now call these and dispatch through ConfigField::set, replacing the hand-written match arms.
    3. RuntimeEnvBuilder::entries now reads defaults from the same constants the builder itself uses (before: hardcoded strings like "100G").
    a. This removes a silent drift risk between actual and displayed defaults.
    4. RuntimeEnv::config_entries is now a one-line delegate to RuntimeOptions::env_entries, which owns the datafusion.runtime prefix and the unlimited-pool special case.
    5. Three per-key listings now co-located inruntime_options.rs:
    - the schema
    - the from_runtime_env read of live resource objects
    - the apply_key write onto RuntimeEnvBuilder
    - The last two can't merge into the schema: builder setters have per-field signatures, and reported values must come from live resource objects, not from whatever was last requested.
    6. CapacityLimit stores a u64 behind a private field (the temp-directory limit is a disk size), so the only narrowing conversion is a checked usize::try_from.
    - Values print in the largest unit that divides them exactly (1.5G shows as 1536M), and a limit that doesn't fit this platform's usize names the key in the error.
    7. Error wording changed as a side effect:
    - ConfigField::set isn't given the key it's setting, so leaf parsers can't name the key mid-message like the old arms did.
    - Errors now get a consistent "when setting '<key>' "suffix (before: some arms said for '<key>', others when setting '<key>').

    What is the testing strategy for this PR?

  • runtime_options.rs unit tests — parsing (incl. parse_ttl overflow, moved here from datafusion-core), defaults, SET/RESET round-trips for every key: cargo test -p datafusion-execution --lib runtime_options

  • runtime_config.rs integration tests, updated for the new error wording: cargo test -p datafusion --test core_integration runtime_config

  • cargo test --profile=ci --test sqllogictests: Completed 512 test files in 15 seconds.

  • doctest: cargo test --doc

  • docs/source/user-guide/configs.md confirmed unchanged: ran ./dev/update_config_docs.sh and diffed - generated runtime table is byte-identical

  • cargo fmt --all -- --check and cargo clippy --all-targets --all-features (datafusion-execution, datafusion) clean
  • Are there any user-facing changes?

    1. Error-message wording for invalid SET/RESET datafusion.runtime.* values — now a consistent when setting '<key>' suffix.
    2. New public API: RuntimeEnvBuilder::with_config_entry and with_default_config_entry.
    3. A CapacityLimit over 1G that isn't an exact multiple now prints in the next smaller unit (e.g. 1536M).

    🤖 Generated with Claude Code and manually edited by @haochunchang

    Diff: 1239 lines (+776 / -463) across 6 files Reviewer: haochunchang Review duration: 126421m
    All Vouch review confidence checks passed
    Residual risk 0.16 = Change Risk (0.94) × (1 − Review Confidence (0.83)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.94 · 1239 lines diff across 6 files
    0.94
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.94 · 5 substantive comment(s)
    0.94
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    83%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Self Review self_review
    0.140
    Sensitive Paths sensitive_paths
    0.095
    Real PR Conversation Timeline
    17 items
    haochunchang haochunchang commented on code on Sep 09, 2026 15:07 UTC
    Code Review
    datafusion/core/tests/sql/runtime_config.rs:1

    This is probably would affect user-facing with different error messages.

    haochunchang haochunchang commented on code on Sep 10, 2026 11:07 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {
    +        /// Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub memory_limit: Option<CapacityLimit>, default = None
    +
    +        /// Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub max_temp_directory_size: CapacityLimit, default = CapacityLimit(DEFAULT_MAX_TEMP_DIRECTORY_SIZE as usize)
    +
    +        /// Maximum number of spill files opened by one external merge pass. Use 0 for unlimited. Values below 2 still use 2 so a merge can make progress.
    +        pub max_spill_merge_fan_in: NonNegativeCount, default = NonNegativeCount(DEFAULT_MAX_SPILL_MERGE_FAN_IN)
    +
    +        /// The path to the temporary file directory.
    +        pub temp_directory: Option<String>, default = None
    +
    +        /// Maximum memory to use for file metadata cache such as Parquet metadata. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub metadata_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_METADATA_CACHE_LIMIT)
    +
    +        /// Maximum memory to use for list files cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub list_files_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT)
    +
    +        /// TTL (time-to-live) of the entries in the list file cache. Supports units m (minutes), and s (seconds). Example: '2m' for 2 minutes.
    +        pub list_files_cache_ttl: Option<CacheTtl>, default = DEFAULT_LIST_FILES_CACHE_TTL.map(CacheTtl)
    +
    +        /// Maximum memory to use for file statistics cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub file_statistics_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_FILE_STATISTICS_MEMORY_LIMIT)
    +    }
    +}
    +
    +impl RuntimeOptions {
    +    /// Set `key` (without the `datafusion.runtime.` prefix) from its string form.
    +    pub fn set_entry(&mut self, key: &str, value: &str) -> Result<()> {
    +        ConfigField::set(self, key, value).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Restore `key` (without the `datafusion.runtime.` prefix) to its default.
    +    pub fn reset_entry(&mut self, key: &str) -> Result<()> {
    +        ConfigField::reset(self, key).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Every key in this namespace with its current value and description.
    +    pub fn entries(&self) -> Vec<ConfigEntry> {
    +        struct Visitor(Vec<ConfigEntry>);
    +
    +        impl Visit for Visitor {
    +            fn some<V: Display>(
    +                &mut self,
    +                key: &str,
    +                value: V,
    +                description: &'static str,
    +            ) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: Some(value.to_string()),
    +                    description,
    +                })
    +            }
    +
    +            fn none(&mut self, key: &str, description: &'static str) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: None,
    +                    description,
    +                })
    +            }
    +        }
    +
    +        let mut v = Visitor(vec![]);
    +        self.visit(&mut v, RUNTIME_CONFIG_PREFIX, "");
    +        v.0
    +    }
    +
    +    /// The entries to report for `env`, with values read back from its live
    +    /// resource objects rather than from whatever was last requested.
    +    pub fn env_entries(env: &RuntimeEnv) -> Vec<ConfigEntry> {
    +        let mut entries = Self::from_runtime_env(env).entries();
    +
    +        // An unbounded pool is not unset, but has no byte value to report, so
    +        // `memory_limit` cannot carry it.
    +        if matches!(env.memory_pool.memory_limit(), MemoryLimit::Infinite) {
    +            let key = format!("{RUNTIME_CONFIG_PREFIX}.memory_limit");
    +            if let Some(entry) = entries.iter_mut().find(|e| e.key == key) {
    +                entry.value = Some("unlimited".to_string());
    +            }
    +        }
    +
    +        entries
    +    }
    +
    +    /// Read the values currently in effect from the live resource objects.
    +    ///
    +    /// A [`MemoryLimit::Infinite`] pool has no representation here, which is why
    +    /// [`Self::env_entries`] handles it separately.
    +    fn from_runtime_env(env: &RuntimeEnv) -> Self {
    +        let memory_limit = match env.memory_pool.memory_limit() {
    +            MemoryLimit::Finite(size) => Some(CapacityLimit(size)),
    +            MemoryLimit::Infinite | MemoryLimit::Unknown => None,
    +        };
    +
    +        let temp_paths = env.disk_manager.temp_dir_paths();
    +        let temp_directory = (!temp_paths.is_empty()).then(|| {
    +            temp_paths
    +                .iter()
    +                .map(|p| p.display().to_string())
    +                .collect::<Vec<_>>()
    +                .join(",")
    +        });
    +
    +        Self {
    +            memory_limit,
    +            max_temp_directory_size: CapacityLimit(
    +                env.disk_manager.max_temp_directory_size() as usize,
    +            ),
    +            max_spill_merge_fan_in: NonNegativeCount(
    +                env.disk_manager.max_spill_merge_fan_in(),
    +            ),
    +            temp_directory,
    +            metadata_cache_limit: CapacityLimit(
    +                env.cache_manager.get_metadata_cache_limit(),
    +            ),
    +            list_files_cache_limit: CapacityLimit(
    +                env.cache_manager.get_list_files_cache_limit(),
    +            ),
    +            list_files_cache_ttl: env
    +                .cache_manager
    +                .get_list_files_cache_ttl()
    +                .map(CacheTtl),
    +            file_statistics_cache_limit: CapacityLimit(
    +                env.cache_manager.get_file_statistic_cache_limit(),
    +            ),
    +        }
    +    }
    +
    +    /// Write the value of a single `key` onto `builder`.
    +    ///
    +    /// Only the named key is applied: rebuilding every resource on each `SET`
    +    /// would discard the live memory pool and its outstanding reservations.
    +    pub fn apply_key(

    Concern: must sync config_namespace! schema (in runtime_options.rs) and apply_key's match arms. Miss updating second, SET fails silently with "Unknown runtime configuration" even though key parses fine.
    Can be caught at compile+test time for any code path exercising new key (unit test unknown_key_is_a_plan_error pattern would catch a forgotten arm if test suite covers new field).

    haochunchang haochunchang commented on code on Sep 10, 2026 11:21 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {
    +        /// Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub memory_limit: Option<CapacityLimit>, default = None
    +
    +        /// Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub max_temp_directory_size: CapacityLimit, default = CapacityLimit(DEFAULT_MAX_TEMP_DIRECTORY_SIZE as usize)
    +
    +        /// Maximum number of spill files opened by one external merge pass. Use 0 for unlimited. Values below 2 still use 2 so a merge can make progress.
    +        pub max_spill_merge_fan_in: NonNegativeCount, default = NonNegativeCount(DEFAULT_MAX_SPILL_MERGE_FAN_IN)
    +
    +        /// The path to the temporary file directory.
    +        pub temp_directory: Option<String>, default = None
    +
    +        /// Maximum memory to use for file metadata cache such as Parquet metadata. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub metadata_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_METADATA_CACHE_LIMIT)
    +
    +        /// Maximum memory to use for list files cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub list_files_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT)
    +
    +        /// TTL (time-to-live) of the entries in the list file cache. Supports units m (minutes), and s (seconds). Example: '2m' for 2 minutes.
    +        pub list_files_cache_ttl: Option<CacheTtl>, default = DEFAULT_LIST_FILES_CACHE_TTL.map(CacheTtl)
    +
    +        /// Maximum memory to use for file statistics cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub file_statistics_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_FILE_STATISTICS_MEMORY_LIMIT)
    +    }
    +}
    +
    +impl RuntimeOptions {
    +    /// Set `key` (without the `datafusion.runtime.` prefix) from its string form.
    +    pub fn set_entry(&mut self, key: &str, value: &str) -> Result<()> {
    +        ConfigField::set(self, key, value).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Restore `key` (without the `datafusion.runtime.` prefix) to its default.
    +    pub fn reset_entry(&mut self, key: &str) -> Result<()> {
    +        ConfigField::reset(self, key).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Every key in this namespace with its current value and description.
    +    pub fn entries(&self) -> Vec<ConfigEntry> {
    +        struct Visitor(Vec<ConfigEntry>);
    +
    +        impl Visit for Visitor {
    +            fn some<V: Display>(
    +                &mut self,
    +                key: &str,
    +                value: V,
    +                description: &'static str,
    +            ) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: Some(value.to_string()),
    +                    description,
    +                })
    +            }
    +
    +            fn none(&mut self, key: &str, description: &'static str) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: None,
    +                    description,
    +                })
    +            }
    +        }
    +
    +        let mut v = Visitor(vec![]);
    +        self.visit(&mut v, RUNTIME_CONFIG_PREFIX, "");
    +        v.0
    +    }
    +
    +    /// The entries to report for `env`, with values read back from its live
    +    /// resource objects rather than from whatever was last requested.
    +    pub fn env_entries(env: &RuntimeEnv) -> Vec<ConfigEntry> {
    +        let mut entries = Self::from_runtime_env(env).entries();
    +
    +        // An unbounded pool is not unset, but has no byte value to report, so
    +        // `memory_limit` cannot carry it.
    +        if matches!(env.memory_pool.memory_limit(), MemoryLimit::Infinite) {
    +            let key = format!("{RUNTIME_CONFIG_PREFIX}.memory_limit");
    +            if let Some(entry) = entries.iter_mut().find(|e| e.key == key) {
    +                entry.value = Some("unlimited".to_string());
    +            }
    +        }
    +
    +        entries
    +    }
    +
    +    /// Read the values currently in effect from the live resource objects.
    +    ///
    +    /// A [`MemoryLimit::Infinite`] pool has no representation here, which is why
    +    /// [`Self::env_entries`] handles it separately.
    +    fn from_runtime_env(env: &RuntimeEnv) -> Self {
    +        let memory_limit = match env.memory_pool.memory_limit() {
    +            MemoryLimit::Finite(size) => Some(CapacityLimit(size)),
    +            MemoryLimit::Infinite | MemoryLimit::Unknown => None,
    +        };
    +
    +        let temp_paths = env.disk_manager.temp_dir_paths();
    +        let temp_directory = (!temp_paths.is_empty()).then(|| {
    +            temp_paths
    +                .iter()
    +                .map(|p| p.display().to_string())
    +                .collect::<Vec<_>>()
    +                .join(",")
    +        });
    +
    +        Self {
    +            memory_limit,
    +            max_temp_directory_size: CapacityLimit(
    +                env.disk_manager.max_temp_directory_size() as usize,
    +            ),
    +            max_spill_merge_fan_in: NonNegativeCount(
    +                env.disk_manager.max_spill_merge_fan_in(),
    +            ),
    +            temp_directory,
    +            metadata_cache_limit: CapacityLimit(
    +                env.cache_manager.get_metadata_cache_limit(),
    +            ),
    +            list_files_cache_limit: CapacityLimit(
    +                env.cache_manager.get_list_files_cache_limit(),
    +            ),
    +            list_files_cache_ttl: env
    +                .cache_manager
    +                .get_list_files_cache_ttl()
    +                .map(CacheTtl),
    +            file_statistics_cache_limit: CapacityLimit(
    +                env.cache_manager.get_file_statistic_cache_limit(),
    +            ),
    +        }
    +    }
    +
    +    /// Write the value of a single `key` onto `builder`.
    +    ///
    +    /// Only the named key is applied: rebuilding every resource on each `SET`
    +    /// would discard the live memory pool and its outstanding reservations.
    +    pub fn apply_key(
    +        &self,
    +        key: &str,
    +        mut builder: RuntimeEnvBuilder,
    +    ) -> Result<RuntimeEnvBuilder> {
    +        builder = match key {
    +            "memory_limit" => match self.memory_limit {
    +                Some(limit) => builder.with_memory_limit(limit.0, 1.0),
    +                None => {
    +                    builder.memory_pool = None;
    +                    builder
    +                }
    +            },
    +            "max_temp_directory_size" => builder
    +                .with_max_temp_directory_size(self.max_temp_directory_size.0 as u64),
    +            "max_spill_merge_fan_in" => {
    +                builder.with_max_spill_merge_fan_in(self.max_spill_merge_fan_in.0)
    +            }
    +            "temp_directory" => match &self.temp_directory {
    +                Some(path) => builder.with_temp_file_path(path),
    +                None => {
    +                    builder.disk_manager_builder = Some(DiskManagerBuilder::default());
    +                    builder
    +                }
    +            },
    +            "metadata_cache_limit" => {
    +                builder.with_metadata_cache_limit(self.metadata_cache_limit.0)
    +            }
    +            "list_files_cache_limit" => {
    +                builder.with_object_list_cache_limit(self.list_files_cache_limit.0)
    +            }
    +            "list_files_cache_ttl" => builder
    +                .with_object_list_cache_ttl(self.list_files_cache_ttl.map(|ttl| ttl.0)),
    +            "file_statistics_cache_limit" => builder
    +                .with_file_statistics_cache_limit(self.file_statistics_cache_limit.0),
    +            _ => return Err(unknown_key(key)),
    +        };
    +        Ok(builder)
    +    }
    +}
    +
    +/// `config_namespace!` reports an unknown key as a [`DataFusionError::Configuration`];
    +/// parse failures below are [`DataFusionError::Plan`]. Restate the former in this
    +/// namespace's wording, and name the key on the latter.
    +fn qualify(e: DataFusionError, key: &str) -> DataFusionError {
    +    match e {
    +        DataFusionError::Configuration(_) => unknown_key(key),
    +        other => name_config(other, &format!("{RUNTIME_CONFIG_PREFIX}.{key}")),
    +    }
    +}
    +
    +/// The parsers below take only the value, because [`ConfigField::set`] is not
    +/// given the key it is setting. Callers that know the key append it here.
    +fn name_config(e: DataFusionError, config_name: &str) -> DataFusionError {
    +    match e {
    +        DataFusionError::Plan(msg) => {
    +            plan_datafusion_err!("{msg} when setting '{config_name}'")
    +        }
    +        other => other,
    +    }
    +}
    +
    +fn unknown_key(key: &str) -> DataFusionError {
    +    plan_datafusion_err!("Unknown runtime configuration: {RUNTIME_CONFIG_PREFIX}.{key}")
    +}
    +
    +/// [`parse_capacity`], with `config_name` named in any error.
    +pub fn parse_capacity_limit(config_name: &str, limit: &str) -> Result<usize> {
    +    parse_capacity(limit).map_err(|e| name_config(e, config_name))
    +}
    +
    +/// [`parse_ttl`], with `config_name` named in any error.
    +pub fn parse_duration(config_name: &str, duration: &str) -> Result<Duration> {
    +    parse_ttl(duration).map_err(|e| name_config(e, config_name))
    +}
    +
    +/// Parse a byte capacity: `0`, or a number with a `K`, `M` or `G` suffix.
    +pub fn parse_capacity(limit: &str) -> Result<usize> {
    +    if limit.trim().is_empty() {
    +        return plan_err!("Empty limit value found");
    +    }
    +    if limit == "0" {
    +        return Ok(0);
    +    }
    +    let (unit_start, unit) = limit
    +        .char_indices()
    +        .next_back()
    +        .ok_or_else(|| plan_datafusion_err!("Empty limit value found"))?;
    +    let number: f64 = limit[..unit_start].parse().map_err(|_| {
    +        plan_datafusion_err!("Failed to parse number from limit '{limit}'")
    +    })?;
    +    if number.is_sign_negative() || number.is_infinite() {
    +        return plan_err!("Limit value should be positive finite number");
    +    }
    +
    +    match unit {
    +        'K' => Ok((number * 1024.0) as usize),
    +        'M' => Ok((number * 1024.0 * 1024.0) as usize),
    +        'G' => Ok((number * 1024.0 * 1024.0 * 1024.0) as usize),
    +        _ => plan_err!(
    +            "Unsupported unit '{unit}' in limit '{limit}'. \
    +             Unit must be one of: 'K', 'M', 'G'"
    +        ),
    +    }
    +}
    +
    +/// Parse a cache TTL: minutes and/or seconds, in that order (`90s`, `2m`, `1m30s`).
    +pub fn parse_ttl(ttl: &str) -> Result<Duration> {
    +    if ttl.trim().is_empty() {
    +        return plan_err!("Duration should not be empty or blank");
    +    }
    +
    +    let mut minutes = None;
    +    let mut seconds = None;
    +
    +    for part in ttl.split_inclusive(&['m', 's']) {
    +        let (unit_start, unit) = part.char_indices().next_back().ok_or_else(|| {
    +            plan_datafusion_err!("Duration should not be empty or blank")
    +        })?;
    +        let number: u64 = part[..unit_start].parse().map_err(|_| {
    +            plan_datafusion_err!("Failed to parse number from duration '{part}'")
    +        })?;
    +
    +        match unit {
    +            'm' if minutes.is_none() && seconds.is_none() => minutes = Some(number),
    +            's' if seconds.is_none() => seconds = Some(number),
    +            other => plan_err!(
    +                "Invalid duration unit: '{other}'. The unit must be either 'm' (minutes), \
    +                 or 's' (seconds), and be in the correct order"
    +            )?,
    +        }
    +    }
    +
    +    let secs = checked_secs(minutes, seconds)?;
    +    let duration = Duration::from_secs(secs);
    +    if duration.is_zero() {
    +        return plan_err!("Duration must be greater than 0 seconds");
    +    }
    +    Ok(duration)
    +}
    +
    +fn checked_secs(mins: Option<u64>, secs: Option<u64>) -> Result<u64> {
    +    mins.unwrap_or_default()
    +        .checked_mul(60)
    +        .ok_or_else(|| {
    +            plan_datafusion_err!(
    +                "Duration has overflowed allowed maximum limit due to 'mins * 60'"

    old {multiplier} always called with hardcoded 60 now, since Old check_overflow(config_name, mins, multiplier, secs) took multiplier as param, but only ever called once: Self::check_overflow(config_name, minutes, 60, seconds).

    haochunchang haochunchang commented on Sep 10, 2026 11:22 UTC
    Reviewer

    Behavior changes after this refactoring:
    1. Error message phrasing/order: suffix style "... for 'config_name'" → new "... when setting 'config_name'".
    - Affected:
    - Capacity parsing (parse_capacity, was SessionContext::parse_capacity_limit)
    - Duration parsing (parse_ttl, was SessionContext::parse_duration)
    - Overflow (checked_secs, was check_overflow)
    - max_spill_merge_fan_in (was inline in set_runtime_variable, now config_field!-generated on NonNegativeCount)
    - Unknown runtime configuration: {variable} -> Unknown runtime configuration: {RUNTIME_CONFIG_PREFIX}.{key} (Text identical at runtime — variable was already "datafusion.runtime.{key}", RUNTIME_CONFIG_PREFIX is that same literal.)

    2. New public API surface on datafusion-execution
    - Newly exported: runtime_options::{RuntimeOptions, CapacityLimit, CacheTtl, NonNegativeCount, RUNTIME_CONFIG_PREFIX, parse_capacity, parse_capacity_limit, parse_ttl, parse_duration}.
    - SessionContext::parse_capacity_limit/parse_duration (in datafusion-core) now thin wrappers over these — same signature, same return values, just relocated logic.

    3. Untouched, now slightly inconsistent
    - Deprecated SessionContext::parse_memory_limit (marked #[deprecated(since="53.0.0")]) keeps its own old-style inline parser, not delegating to runtime_options.

    ByteBaker ByteBaker commented on code on Oct 21, 2026 12:38 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {
    +        /// Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub memory_limit: Option<CapacityLimit>, default = None
    +
    +        /// Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub max_temp_directory_size: CapacityLimit, default = CapacityLimit(DEFAULT_MAX_TEMP_DIRECTORY_SIZE as usize)

    Concern: this trims down the size of DEFAULT_MAX_TEMP_DIRECTORY_SIZE from u64 to usize, which may be very different on different machines and may cause data loss.

    ByteBaker ByteBaker commented on code on Oct 21, 2026 12:44 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {

    Every member of this struct is public. I'd rather not have the implementation public and be accessed through valid APIs only and for applicable members.

    ByteBaker ByteBaker commented on code on Oct 21, 2026 13:13 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {
    +        /// Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub memory_limit: Option<CapacityLimit>, default = None
    +
    +        /// Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub max_temp_directory_size: CapacityLimit, default = CapacityLimit(DEFAULT_MAX_TEMP_DIRECTORY_SIZE as usize)
    +
    +        /// Maximum number of spill files opened by one external merge pass. Use 0 for unlimited. Values below 2 still use 2 so a merge can make progress.
    +        pub max_spill_merge_fan_in: NonNegativeCount, default = NonNegativeCount(DEFAULT_MAX_SPILL_MERGE_FAN_IN)
    +
    +        /// The path to the temporary file directory.
    +        pub temp_directory: Option<String>, default = None
    +
    +        /// Maximum memory to use for file metadata cache such as Parquet metadata. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub metadata_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_METADATA_CACHE_LIMIT)
    +
    +        /// Maximum memory to use for list files cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub list_files_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT)
    +
    +        /// TTL (time-to-live) of the entries in the list file cache. Supports units m (minutes), and s (seconds). Example: '2m' for 2 minutes.
    +        pub list_files_cache_ttl: Option<CacheTtl>, default = DEFAULT_LIST_FILES_CACHE_TTL.map(CacheTtl)
    +
    +        /// Maximum memory to use for file statistics cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub file_statistics_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_FILE_STATISTICS_MEMORY_LIMIT)
    +    }
    +}
    +
    +impl RuntimeOptions {
    +    /// Set `key` (without the `datafusion.runtime.` prefix) from its string form.
    +    pub fn set_entry(&mut self, key: &str, value: &str) -> Result<()> {
    +        ConfigField::set(self, key, value).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Restore `key` (without the `datafusion.runtime.` prefix) to its default.
    +    pub fn reset_entry(&mut self, key: &str) -> Result<()> {
    +        ConfigField::reset(self, key).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Every key in this namespace with its current value and description.
    +    pub fn entries(&self) -> Vec<ConfigEntry> {
    +        struct Visitor(Vec<ConfigEntry>);
    +
    +        impl Visit for Visitor {
    +            fn some<V: Display>(
    +                &mut self,
    +                key: &str,
    +                value: V,
    +                description: &'static str,
    +            ) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: Some(value.to_string()),
    +                    description,
    +                })
    +            }
    +
    +            fn none(&mut self, key: &str, description: &'static str) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: None,
    +                    description,
    +                })
    +            }
    +        }
    +
    +        let mut v = Visitor(vec![]);
    +        self.visit(&mut v, RUNTIME_CONFIG_PREFIX, "");
    +        v.0
    +    }
    +
    +    /// The entries to report for `env`, with values read back from its live
    +    /// resource objects rather than from whatever was last requested.
    +    pub fn env_entries(env: &RuntimeEnv) -> Vec<ConfigEntry> {
    +        let mut entries = Self::from_runtime_env(env).entries();
    +
    +        // An unbounded pool is not unset, but has no byte value to report, so
    +        // `memory_limit` cannot carry it.
    +        if matches!(env.memory_pool.memory_limit(), MemoryLimit::Infinite) {
    +            let key = format!("{RUNTIME_CONFIG_PREFIX}.memory_limit");
    +            if let Some(entry) = entries.iter_mut().find(|e| e.key == key) {
    +                entry.value = Some("unlimited".to_string());
    +            }
    +        }
    +
    +        entries
    +    }
    +
    +    /// Read the values currently in effect from the live resource objects.
    +    ///
    +    /// A [`MemoryLimit::Infinite`] pool has no representation here, which is why
    +    /// [`Self::env_entries`] handles it separately.
    +    fn from_runtime_env(env: &RuntimeEnv) -> Self {
    +        let memory_limit = match env.memory_pool.memory_limit() {
    +            MemoryLimit::Finite(size) => Some(CapacityLimit(size)),
    +            MemoryLimit::Infinite | MemoryLimit::Unknown => None,
    +        };
    +
    +        let temp_paths = env.disk_manager.temp_dir_paths();
    +        let temp_directory = (!temp_paths.is_empty()).then(|| {
    +            temp_paths
    +                .iter()
    +                .map(|p| p.display().to_string())
    +                .collect::<Vec<_>>()
    +                .join(",")
    +        });
    +
    +        Self {
    +            memory_limit,
    +            max_temp_directory_size: CapacityLimit(
    +                env.disk_manager.max_temp_directory_size() as usize,
    +            ),
    +            max_spill_merge_fan_in: NonNegativeCount(
    +                env.disk_manager.max_spill_merge_fan_in(),
    +            ),
    +            temp_directory,
    +            metadata_cache_limit: CapacityLimit(
    +                env.cache_manager.get_metadata_cache_limit(),
    +            ),
    +            list_files_cache_limit: CapacityLimit(
    +                env.cache_manager.get_list_files_cache_limit(),
    +            ),
    +            list_files_cache_ttl: env
    +                .cache_manager
    +                .get_list_files_cache_ttl()
    +                .map(CacheTtl),
    +            file_statistics_cache_limit: CapacityLimit(
    +                env.cache_manager.get_file_statistic_cache_limit(),
    +            ),
    +        }
    +    }
    +
    +    /// Write the value of a single `key` onto `builder`.
    +    ///
    +    /// Only the named key is applied: rebuilding every resource on each `SET`
    +    /// would discard the live memory pool and its outstanding reservations.
    +    pub fn apply_key(
    +        &self,
    +        key: &str,
    +        mut builder: RuntimeEnvBuilder,
    +    ) -> Result<RuntimeEnvBuilder> {
    +        builder = match key {
    +            "memory_limit" => match self.memory_limit {
    +                Some(limit) => builder.with_memory_limit(limit.0, 1.0),
    +                None => {
    +                    builder.memory_pool = None;
    +                    builder
    +                }
    +            },
    +            "max_temp_directory_size" => builder
    +                .with_max_temp_directory_size(self.max_temp_directory_size.0 as u64),
    +            "max_spill_merge_fan_in" => {
    +                builder.with_max_spill_merge_fan_in(self.max_spill_merge_fan_in.0)
    +            }
    +            "temp_directory" => match &self.temp_directory {
    +                Some(path) => builder.with_temp_file_path(path),
    +                None => {
    +                    builder.disk_manager_builder = Some(DiskManagerBuilder::default());
    +                    builder
    +                }
    +            },
    +            "metadata_cache_limit" => {
    +                builder.with_metadata_cache_limit(self.metadata_cache_limit.0)
    +            }
    +            "list_files_cache_limit" => {
    +                builder.with_object_list_cache_limit(self.list_files_cache_limit.0)
    +            }
    +            "list_files_cache_ttl" => builder
    +                .with_object_list_cache_ttl(self.list_files_cache_ttl.map(|ttl| ttl.0)),
    +            "file_statistics_cache_limit" => builder
    +                .with_file_statistics_cache_limit(self.file_statistics_cache_limit.0),
    +            _ => return Err(unknown_key(key)),
    +        };
    +        Ok(builder)
    +    }
    +}
    +
    +/// `config_namespace!` reports an unknown key as a [`DataFusionError::Configuration`];
    +/// parse failures below are [`DataFusionError::Plan`]. Restate the former in this
    +/// namespace's wording, and name the key on the latter.
    +fn qualify(e: DataFusionError, key: &str) -> DataFusionError {
    +    match e {
    +        DataFusionError::Configuration(_) => unknown_key(key),
    +        other => name_config(other, &format!("{RUNTIME_CONFIG_PREFIX}.{key}")),
    +    }
    +}
    +
    +/// The parsers below take only the value, because [`ConfigField::set`] is not
    +/// given the key it is setting. Callers that know the key append it here.
    +fn name_config(e: DataFusionError, config_name: &str) -> DataFusionError {
    +    match e {
    +        DataFusionError::Plan(msg) => {
    +            plan_datafusion_err!("{msg} when setting '{config_name}'")
    +        }
    +        other => other,
    +    }
    +}
    +
    +fn unknown_key(key: &str) -> DataFusionError {
    +    plan_datafusion_err!("Unknown runtime configuration: {RUNTIME_CONFIG_PREFIX}.{key}")
    +}
    +
    +/// [`parse_capacity`], with `config_name` named in any error.
    +pub fn parse_capacity_limit(config_name: &str, limit: &str) -> Result<usize> {
    +    parse_capacity(limit).map_err(|e| name_config(e, config_name))
    +}
    +
    +/// [`parse_ttl`], with `config_name` named in any error.
    +pub fn parse_duration(config_name: &str, duration: &str) -> Result<Duration> {

    The tests for this live inside datafusion-core, they should be here. We can actually get rid of this public function from here altogether once we move those tests in here.

    ByteBaker ByteBaker requested changes on Oct 21, 2026 13:13 UTC
    Changes Requested Reviewer

    Requested changes.

    haochunchang haochunchang commented on code on Oct 24, 2026 09:37 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {
    +        /// Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub memory_limit: Option<CapacityLimit>, default = None
    +
    +        /// Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub max_temp_directory_size: CapacityLimit, default = CapacityLimit(DEFAULT_MAX_TEMP_DIRECTORY_SIZE as usize)

    @ByteBaker Thanks for the catch!
    If DEFAULT_MAX_TEMP_DIRECTORY_SIZE >= 2^32 on 32-bit target, it would cause data loss.

    haochunchang haochunchang commented on code on Oct 24, 2026 09:47 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {

    I like this suggestion. Only expose certain valid APIs make future internal changes easier.
    I will go through all the public struct and fns to see if there are other candidates should go private.

    haochunchang haochunchang commented on code on Oct 24, 2026 11:26 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {

    1. I made the RuntimeOptions fields, CapacityLimit, CacheTtl, NonNegativeCount, parse_capacity and parse_ttl private. They are reached only through set_entry, reset_entry and apply_key.
    2. I also added RuntimeEnvBuilder::with_config_entry and with_default_config_entry. SessionContext now uses them here, so RuntimeOptions and its methods are crate-private instead of public API.

    haochunchang haochunchang commented on code on Oct 24, 2026 11:30 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {
    +        /// Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub memory_limit: Option<CapacityLimit>, default = None
    +
    +        /// Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub max_temp_directory_size: CapacityLimit, default = CapacityLimit(DEFAULT_MAX_TEMP_DIRECTORY_SIZE as usize)
    +
    +        /// Maximum number of spill files opened by one external merge pass. Use 0 for unlimited. Values below 2 still use 2 so a merge can make progress.
    +        pub max_spill_merge_fan_in: NonNegativeCount, default = NonNegativeCount(DEFAULT_MAX_SPILL_MERGE_FAN_IN)
    +
    +        /// The path to the temporary file directory.
    +        pub temp_directory: Option<String>, default = None
    +
    +        /// Maximum memory to use for file metadata cache such as Parquet metadata. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub metadata_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_METADATA_CACHE_LIMIT)
    +
    +        /// Maximum memory to use for list files cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub list_files_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT)
    +
    +        /// TTL (time-to-live) of the entries in the list file cache. Supports units m (minutes), and s (seconds). Example: '2m' for 2 minutes.
    +        pub list_files_cache_ttl: Option<CacheTtl>, default = DEFAULT_LIST_FILES_CACHE_TTL.map(CacheTtl)
    +
    +        /// Maximum memory to use for file statistics cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub file_statistics_cache_limit: CapacityLimit, default = CapacityLimit(DEFAULT_FILE_STATISTICS_MEMORY_LIMIT)
    +    }
    +}
    +
    +impl RuntimeOptions {
    +    /// Set `key` (without the `datafusion.runtime.` prefix) from its string form.
    +    pub fn set_entry(&mut self, key: &str, value: &str) -> Result<()> {
    +        ConfigField::set(self, key, value).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Restore `key` (without the `datafusion.runtime.` prefix) to its default.
    +    pub fn reset_entry(&mut self, key: &str) -> Result<()> {
    +        ConfigField::reset(self, key).map_err(|e| qualify(e, key))
    +    }
    +
    +    /// Every key in this namespace with its current value and description.
    +    pub fn entries(&self) -> Vec<ConfigEntry> {
    +        struct Visitor(Vec<ConfigEntry>);
    +
    +        impl Visit for Visitor {
    +            fn some<V: Display>(
    +                &mut self,
    +                key: &str,
    +                value: V,
    +                description: &'static str,
    +            ) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: Some(value.to_string()),
    +                    description,
    +                })
    +            }
    +
    +            fn none(&mut self, key: &str, description: &'static str) {
    +                self.0.push(ConfigEntry {
    +                    key: key.to_string(),
    +                    value: None,
    +                    description,
    +                })
    +            }
    +        }
    +
    +        let mut v = Visitor(vec![]);
    +        self.visit(&mut v, RUNTIME_CONFIG_PREFIX, "");
    +        v.0
    +    }
    +
    +    /// The entries to report for `env`, with values read back from its live
    +    /// resource objects rather than from whatever was last requested.
    +    pub fn env_entries(env: &RuntimeEnv) -> Vec<ConfigEntry> {
    +        let mut entries = Self::from_runtime_env(env).entries();
    +
    +        // An unbounded pool is not unset, but has no byte value to report, so
    +        // `memory_limit` cannot carry it.
    +        if matches!(env.memory_pool.memory_limit(), MemoryLimit::Infinite) {
    +            let key = format!("{RUNTIME_CONFIG_PREFIX}.memory_limit");
    +            if let Some(entry) = entries.iter_mut().find(|e| e.key == key) {
    +                entry.value = Some("unlimited".to_string());
    +            }
    +        }
    +
    +        entries
    +    }
    +
    +    /// Read the values currently in effect from the live resource objects.
    +    ///
    +    /// A [`MemoryLimit::Infinite`] pool has no representation here, which is why
    +    /// [`Self::env_entries`] handles it separately.
    +    fn from_runtime_env(env: &RuntimeEnv) -> Self {
    +        let memory_limit = match env.memory_pool.memory_limit() {
    +            MemoryLimit::Finite(size) => Some(CapacityLimit(size)),
    +            MemoryLimit::Infinite | MemoryLimit::Unknown => None,
    +        };
    +
    +        let temp_paths = env.disk_manager.temp_dir_paths();
    +        let temp_directory = (!temp_paths.is_empty()).then(|| {
    +            temp_paths
    +                .iter()
    +                .map(|p| p.display().to_string())
    +                .collect::<Vec<_>>()
    +                .join(",")
    +        });
    +
    +        Self {
    +            memory_limit,
    +            max_temp_directory_size: CapacityLimit(
    +                env.disk_manager.max_temp_directory_size() as usize,
    +            ),
    +            max_spill_merge_fan_in: NonNegativeCount(
    +                env.disk_manager.max_spill_merge_fan_in(),
    +            ),
    +            temp_directory,
    +            metadata_cache_limit: CapacityLimit(
    +                env.cache_manager.get_metadata_cache_limit(),
    +            ),
    +            list_files_cache_limit: CapacityLimit(
    +                env.cache_manager.get_list_files_cache_limit(),
    +            ),
    +            list_files_cache_ttl: env
    +                .cache_manager
    +                .get_list_files_cache_ttl()
    +                .map(CacheTtl),
    +            file_statistics_cache_limit: CapacityLimit(
    +                env.cache_manager.get_file_statistic_cache_limit(),
    +            ),
    +        }
    +    }
    +
    +    /// Write the value of a single `key` onto `builder`.
    +    ///
    +    /// Only the named key is applied: rebuilding every resource on each `SET`
    +    /// would discard the live memory pool and its outstanding reservations.
    +    pub fn apply_key(
    +        &self,
    +        key: &str,
    +        mut builder: RuntimeEnvBuilder,
    +    ) -> Result<RuntimeEnvBuilder> {
    +        builder = match key {
    +            "memory_limit" => match self.memory_limit {
    +                Some(limit) => builder.with_memory_limit(limit.0, 1.0),
    +                None => {
    +                    builder.memory_pool = None;
    +                    builder
    +                }
    +            },
    +            "max_temp_directory_size" => builder
    +                .with_max_temp_directory_size(self.max_temp_directory_size.0 as u64),
    +            "max_spill_merge_fan_in" => {
    +                builder.with_max_spill_merge_fan_in(self.max_spill_merge_fan_in.0)
    +            }
    +            "temp_directory" => match &self.temp_directory {
    +                Some(path) => builder.with_temp_file_path(path),
    +                None => {
    +                    builder.disk_manager_builder = Some(DiskManagerBuilder::default());
    +                    builder
    +                }
    +            },
    +            "metadata_cache_limit" => {
    +                builder.with_metadata_cache_limit(self.metadata_cache_limit.0)
    +            }
    +            "list_files_cache_limit" => {
    +                builder.with_object_list_cache_limit(self.list_files_cache_limit.0)
    +            }
    +            "list_files_cache_ttl" => builder
    +                .with_object_list_cache_ttl(self.list_files_cache_ttl.map(|ttl| ttl.0)),
    +            "file_statistics_cache_limit" => builder
    +                .with_file_statistics_cache_limit(self.file_statistics_cache_limit.0),
    +            _ => return Err(unknown_key(key)),
    +        };
    +        Ok(builder)
    +    }
    +}
    +
    +/// `config_namespace!` reports an unknown key as a [`DataFusionError::Configuration`];
    +/// parse failures below are [`DataFusionError::Plan`]. Restate the former in this
    +/// namespace's wording, and name the key on the latter.
    +fn qualify(e: DataFusionError, key: &str) -> DataFusionError {
    +    match e {
    +        DataFusionError::Configuration(_) => unknown_key(key),
    +        other => name_config(other, &format!("{RUNTIME_CONFIG_PREFIX}.{key}")),
    +    }
    +}
    +
    +/// The parsers below take only the value, because [`ConfigField::set`] is not
    +/// given the key it is setting. Callers that know the key append it here.
    +fn name_config(e: DataFusionError, config_name: &str) -> DataFusionError {
    +    match e {
    +        DataFusionError::Plan(msg) => {
    +            plan_datafusion_err!("{msg} when setting '{config_name}'")
    +        }
    +        other => other,
    +    }
    +}
    +
    +fn unknown_key(key: &str) -> DataFusionError {
    +    plan_datafusion_err!("Unknown runtime configuration: {RUNTIME_CONFIG_PREFIX}.{key}")
    +}
    +
    +/// [`parse_capacity`], with `config_name` named in any error.
    +pub fn parse_capacity_limit(config_name: &str, limit: &str) -> Result<usize> {
    +    parse_capacity(limit).map_err(|e| name_config(e, config_name))
    +}
    +
    +/// [`parse_ttl`], with `config_name` named in any error.
    +pub fn parse_duration(config_name: &str, duration: &str) -> Result<Duration> {

    The tests now call parse_ttl (private) directly (starting from L456), and the public parse_duration wrapper is gone.

    haochunchang haochunchang commented on code on Oct 24, 2026 12:22 UTC
    Code Review
    datafusion/execution/src/runtime_options.rs:1
    @@ -0,0 +1,508 @@
    +// 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.
    +
    +//! Typed schema for the `datafusion.runtime.*` configuration namespace.
    +//!
    +//! [`RuntimeOptions`] owns the runtime keys, their descriptions, their defaults
    +//! and their parsing, using the same [`ConfigField`] machinery that backs
    +//! `ConfigOptions`. It does not live inside `ConfigOptions` because
    +//! `datafusion-execution` depends on `datafusion-common`, never the reverse.
    +
    +use std::fmt::{self, Display, Formatter};
    +use std::time::Duration;
    +
    +use crate::cache::cache_manager::{
    +    DEFAULT_FILE_STATISTICS_MEMORY_LIMIT, DEFAULT_LIST_FILES_CACHE_MEMORY_LIMIT,
    +    DEFAULT_LIST_FILES_CACHE_TTL, DEFAULT_METADATA_CACHE_LIMIT,
    +};
    +use crate::disk_manager::{
    +    DEFAULT_MAX_SPILL_MERGE_FAN_IN, DEFAULT_MAX_TEMP_DIRECTORY_SIZE, DiskManagerBuilder,
    +};
    +use crate::memory_pool::MemoryLimit;
    +use crate::runtime_env::{RuntimeEnv, RuntimeEnvBuilder};
    +
    +use datafusion_common::config::{ConfigEntry, ConfigField, Visit};
    +use datafusion_common::{
    +    DataFusionError, Result, config_field, config_namespace, plan_datafusion_err,
    +    plan_err,
    +};
    +
    +/// Prefix shared by every key in this namespace.
    +pub const RUNTIME_CONFIG_PREFIX: &str = "datafusion.runtime";
    +
    +/// A byte capacity written as a plain number of bytes (`0`) or a number with a
    +/// `K`, `M` or `G` suffix (`512K`, `100M`, `1.5G`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CapacityLimit(pub usize);
    +
    +impl Display for CapacityLimit {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        const GB: usize = 1024 * 1024 * 1024;
    +        const MB: usize = 1024 * 1024;
    +        const KB: usize = 1024;
    +
    +        match self.0 {
    +            s if s >= GB => write!(f, "{}G", s / GB),
    +            s if s >= MB => write!(f, "{}M", s / MB),
    +            s if s >= KB => write!(f, "{}K", s / KB),
    +            s => write!(f, "{s}"),
    +        }
    +    }
    +}
    +
    +config_field!(CapacityLimit, value => CapacityLimit(parse_capacity(value)?));
    +
    +/// A cache time-to-live written as minutes and/or seconds (`90s`, `2m`, `1m30s`).
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct CacheTtl(pub Duration);
    +
    +impl Display for CacheTtl {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        let total = self.0.as_secs();
    +        write!(f, "{}m{}s", total / 60, total % 60)
    +    }
    +}
    +
    +config_field!(CacheTtl, value => CacheTtl(parse_ttl(value)?));
    +
    +/// A count that must not be negative.
    +///
    +/// A plain `usize` would report `Error parsing '-1' as usize`, naming the Rust
    +/// type rather than the constraint.
    +#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
    +pub struct NonNegativeCount(pub usize);
    +
    +impl Display for NonNegativeCount {
    +    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
    +        write!(f, "{}", self.0)
    +    }
    +}
    +
    +config_field!(NonNegativeCount, value => NonNegativeCount(
    +    value.parse::<usize>().map_err(|e| plan_datafusion_err!(
    +        "Failed to parse non-negative integer from value '{value}': {e}"
    +    ))?
    +));
    +
    +config_namespace! {
    +    /// Options that configure the [`RuntimeEnv`] shared by a session.
    +    ///
    +    /// Field order below is the order entries are reported in.
    +    pub struct RuntimeOptions {
    +        /// Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub memory_limit: Option<CapacityLimit>, default = None
    +
    +        /// Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
    +        pub max_temp_directory_size: CapacityLimit, default = CapacityLimit(DEFAULT_MAX_TEMP_DIRECTORY_SIZE as usize)

    I turned CapacityLimit into a private struct.

  • Disk sizes use from_bytes / as_u64, with no conversion.

  • In-memory sizes use From<usize> (lossless) and as_usize, which uses usize::try_from.
  • On a target where the value doesn't fit, SET returns an error naming the key instead of truncating.

    github-actions[bot] github-actions[bot] commented on Nov 14, 2026 01:07 UTC
    Bot

    Marked as draft after 14 days without activity: failing CI checks.

    Please address these items and mark Ready for review when ready.

    codewarnab codewarnab commented on Nov 27, 2026 17:08 UTC
    Contributor

    Hi @haochunchang, are you still planning to continue this PR? If you don't have time for it anymore, I'd be happy to pick it up and build on your work here (keeping you credited). No pressure either way, just let me know.

    haochunchang haochunchang commented on Dec 02, 2026 02:08 UTC
    Author

    Thanks for following up.
    You can take it and feel free to pick it up. :)

    On Sat, Nov 28, 2026 at 1:09 AM Arnab Mondal @.**>
    wrote:

    codewarnab left a comment (apache/datafusion#25114)

    <https://github.com/apache/datafusion/pull/25114#issuecomment-7224079678>

    > Hi @haochunchang <https://github.com/haochunchang>, are you still

    planning to continue this PR? If you don't have time for it anymore, I'd be

    happy to pick it up and build on your work here (keeping you credited). No

    pressure either way, just let me know.

    > —

    Reply to this email directly, view it on GitHub

    <https://github.com/apache/datafusion/pull/25114?email_source=notifications&email_token=AGASHUCZ33RAGJUOPTKGQMD53GYLVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMRSGQYDOOJWG44KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLDGN5XXIZLSL5RWY2LDNM#issuecomment-7224079678>,

    or unsubscribe

    <https://github.com/notifications/unsubscribe-auth/AGASHUERIZXJBEE7HB2OZK353GYLVAVCNFSNUABFKJSXA33TNF2G64TZHMZTKOBZGE3TGMJYHNEXG43VMU5TKNBQGAYTOMBZG4ZKC5QC>

    .

    Triage notifications, keep track of coding agent tasks and review pull

    requests on the go with GitHub Mobile for iOS

    <https://github.com/notifications/mobile/ios/AGASHUGJR6O46FMIPOE5IN353GYLVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMRSGQYDOOJWG44KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJKTGN5XXIZLSL5UW64Y>

    and Android

    <https://github.com/notifications/mobile/android/AGASHUFFFZIFVK2JCEHH27D53GYLVA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTOMRSGQYDOOJWG44KM4TFMFZW63VHNVSW45DJN5XKKZLWMVXHJLTGN5XXIZLSL5QW4ZDSN5UWI>.

    Download it today!

    You are receiving this because you were mentioned.Message ID:

    @.>

    --

    張皓鈞 HaoChun Chang
    Mobile: 0918788771
    Email:
    @.*

    Reviewers
    Assignees
    haochunchang haochunchang
    Labels
    risk: low confidence: 83.1% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 94.5% (HIGH) · Higher = larger blast radius
    94.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 83.1% · Lower = rushed or shallow review
    83.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 16.0% · Safe to merge
    16.0%