Skip to content

Commit 2f29038

Browse files
authored
Support '0' value for parse_capacity_limit() (#22014)
## Which issue does this PR close? - None ## Rationale for this change This extends `parse_capacity_limit()` to support \`0\` to set a limit of 0 instead of using \`0K\`. This simplifies configuration and avoids confusion with the word \`OK\` (Okay). This is based on the [suggestion](#20047 (comment)) from @martin-g. Usage: ``` SET datafusion.runtime.example_limit = '0' ``` instead of: ``` SET datafusion.runtime.example_limit = '0K' ``` ## What changes are included in this PR? see above. ## Are these changes tested? Yes. ## Are there any user-facing changes? Yes.
1 parent aca4d13 commit 2f29038

5 files changed

Lines changed: 30 additions & 17 deletions

File tree

datafusion/core/src/execution/context/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1275,7 +1275,7 @@ impl SessionContext {
12751275
}
12761276

12771277
/// Parse capacity limit from string to number of bytes by allowing units: K, M and G.
1278-
/// Supports formats like '1.5G', '100M', '512K'
1278+
/// Supports formats like '1.5G', '100M', '512K'. Capacity limit can be set to 0 with '0'.
12791279
///
12801280
/// # Examples
12811281
/// ```
@@ -1296,6 +1296,9 @@ impl SessionContext {
12961296
"Empty limit value found for '{config_name}'"
12971297
));
12981298
}
1299+
if limit == "0" {
1300+
return Ok(0);
1301+
}
12991302
let (number, unit) = limit.split_at(limit.len() - 1);
13001303
let number: f64 = number.parse().map_err(|_| {
13011304
plan_datafusion_err!(
@@ -2970,6 +2973,7 @@ mod tests {
29702973

29712974
// Valid capacity_limit
29722975
for (limit, want) in [
2976+
("0", 0),
29732977
("1.5K", (1.5 * 1024.0) as usize),
29742978
("2M", (2f64 * 1024.0 * 1024.0) as usize),
29752979
("1G", (1f64 * 1024.0 * 1024.0 * 1024.0) as usize),

datafusion/execution/src/runtime_env.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ fn create_runtime_config_entries(
108108
ConfigEntry {
109109
key: "datafusion.runtime.memory_limit".to_string(),
110110
value: memory_limit,
111-
description: "Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.",
111+
description: "Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.",
112112
},
113113
ConfigEntry {
114114
key: "datafusion.runtime.max_temp_directory_size".to_string(),
115115
value: max_temp_directory_size,
116-
description: "Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.",
116+
description: "Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.",
117117
},
118118
ConfigEntry {
119119
key: "datafusion.runtime.temp_directory".to_string(),
@@ -123,12 +123,12 @@ fn create_runtime_config_entries(
123123
ConfigEntry {
124124
key: "datafusion.runtime.metadata_cache_limit".to_string(),
125125
value: metadata_cache_limit,
126-
description: "Maximum memory to use for file metadata cache such as Parquet metadata. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.",
126+
description: "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.",
127127
},
128128
ConfigEntry {
129129
key: "datafusion.runtime.list_files_cache_limit".to_string(),
130130
value: list_files_cache_limit,
131-
description: "Maximum memory to use for list files cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.",
131+
description: "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.",
132132
},
133133
ConfigEntry {
134134
key: "datafusion.runtime.list_files_cache_ttl".to_string(),

datafusion/sqllogictest/test_files/information_schema.slt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,11 +479,11 @@ datafusion.optimizer.skip_failed_rules false When set to true, the logical plan
479479
datafusion.optimizer.subset_repartition_threshold 4 Partition count threshold for subset satisfaction optimization. When the current partition count is >= this threshold, DataFusion will skip repartitioning if the required partitioning expression is a subset of the current partition expression such as Hash(a) satisfies Hash(a, b). When the current partition count is < this threshold, DataFusion will repartition to increase parallelism even when subset satisfaction applies. Set to 0 to always repartition (disable subset satisfaction optimization). Set to a high value to always use subset satisfaction. Example (subset_repartition_threshold = 4): ```text Hash([a]) satisfies Hash([a, b]) because (Hash([a, b]) is subset of Hash([a]) If current partitions (3) < threshold (4), repartition: AggregateExec: mode=FinalPartitioned, gby=[a, b], aggr=[SUM(x)] RepartitionExec: partitioning=Hash([a, b], 8), input_partitions=3 AggregateExec: mode=Partial, gby=[a, b], aggr=[SUM(x)] DataSourceExec: file_groups={...}, output_partitioning=Hash([a], 3) If current partitions (8) >= threshold (4), use subset satisfaction: AggregateExec: mode=SinglePartitioned, gby=[a, b], aggr=[SUM(x)] DataSourceExec: file_groups={...}, output_partitioning=Hash([a], 8) ```
480480
datafusion.optimizer.top_down_join_key_reordering true When set to true, the physical plan optimizer will run a top down process to reorder the join keys
481481
datafusion.optimizer.use_statistics_registry false When set to true, the physical plan optimizer uses the pluggable `StatisticsRegistry` for statistics propagation across operators. This enables more accurate cardinality estimates compared to each operator's built-in `partition_statistics`.
482-
datafusion.runtime.list_files_cache_limit 1M Maximum memory to use for list files cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.
482+
datafusion.runtime.list_files_cache_limit 1M 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.
483483
datafusion.runtime.list_files_cache_ttl NULL TTL (time-to-live) of the entries in the list file cache. Supports units m (minutes), and s (seconds). Example: '2m' for 2 minutes.
484-
datafusion.runtime.max_temp_directory_size 100G Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.
485-
datafusion.runtime.memory_limit unlimited Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.
486-
datafusion.runtime.metadata_cache_limit 50M Maximum memory to use for file metadata cache such as Parquet metadata. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes.
484+
datafusion.runtime.max_temp_directory_size 100G Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
485+
datafusion.runtime.memory_limit unlimited Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes.
486+
datafusion.runtime.metadata_cache_limit 50M 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.
487487
datafusion.runtime.temp_directory NULL The path to the temporary file directory.
488488
datafusion.sql_parser.collect_spans false When set to true, the source locations relative to the original SQL query (i.e. [`Span`](https://docs.rs/sqlparser/latest/sqlparser/tokenizer/struct.Span.html)) will be collected and recorded in the logical plan nodes.
489489
datafusion.sql_parser.default_null_ordering nulls_max Specifies the default null ordering for query results. There are 4 options: - `nulls_max`: Nulls appear last in ascending order. - `nulls_min`: Nulls appear first in ascending order. - `nulls_first`: Nulls always be first in any order. - `nulls_last`: Nulls always be last in any order. By default, `nulls_max` is used to follow Postgres's behavior. postgres rule: <https://www.postgresql.org/docs/current/queries-order.html>

datafusion/sqllogictest/test_files/set_variable.slt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,15 @@ SHOW datafusion.runtime.list_files_cache_ttl
632632
----
633633
datafusion.runtime.list_files_cache_ttl 1m30s
634634

635+
# Test SET and SHOW for limit 0
636+
statement ok
637+
SET datafusion.runtime.list_files_cache_limit = '0'
638+
639+
query TT
640+
SHOW datafusion.runtime.list_files_cache_limit
641+
----
642+
datafusion.runtime.list_files_cache_limit 0
643+
635644
# Note: runtime.temp_directory shows the actual temp directory path with a unique suffix,
636645
# so we cannot test the exact value. We verify it exists in information_schema instead.
637646

docs/source/user-guide/configs.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,14 @@ SET datafusion.runtime.memory_limit = '2G';
229229

230230
The following runtime configuration settings are available:
231231

232-
| key | default | description |
233-
| ------------------------------------------ | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
234-
| datafusion.runtime.list_files_cache_limit | 1M | Maximum memory to use for list files cache. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes. |
235-
| datafusion.runtime.list_files_cache_ttl | NULL | TTL (time-to-live) of the entries in the list file cache. Supports units m (minutes), and s (seconds). Example: '2m' for 2 minutes. |
236-
| datafusion.runtime.max_temp_directory_size | 100G | Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes. |
237-
| datafusion.runtime.memory_limit | NULL | Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes. |
238-
| datafusion.runtime.metadata_cache_limit | 50M | Maximum memory to use for file metadata cache such as Parquet metadata. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes). Example: '2G' for 2 gigabytes. |
239-
| datafusion.runtime.temp_directory | NULL | The path to the temporary file directory. |
232+
| key | default | description |
233+
| ------------------------------------------ | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
234+
| datafusion.runtime.list_files_cache_limit | 1M | 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. |
235+
| datafusion.runtime.list_files_cache_ttl | NULL | TTL (time-to-live) of the entries in the list file cache. Supports units m (minutes), and s (seconds). Example: '2m' for 2 minutes. |
236+
| datafusion.runtime.max_temp_directory_size | 100G | Maximum temporary file directory size. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes. |
237+
| datafusion.runtime.memory_limit | NULL | Maximum memory limit for query execution. Supports suffixes K (kilobytes), M (megabytes), and G (gigabytes) or '0' for 0. Example: '2G' for 2 gigabytes. |
238+
| datafusion.runtime.metadata_cache_limit | 50M | 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. |
239+
| datafusion.runtime.temp_directory | NULL | The path to the temporary file directory. |
240240

241241
# Tuning Guide
242242

0 commit comments

Comments
 (0)