Skip to content

Commit 68a2416

Browse files
timsaucerclaude
andcommitted
feat: expose SessionContext.copied_config and parse_capacity_limit
Adds two small additions to SessionContext that mirror upstream: - copied_config(): returns a copy of the active SessionConfig wrapped in the existing SessionConfig Python class. Useful when callers want to seed a new context from another context's settings, or inspect the current configuration without sharing mutable state. - parse_capacity_limit(config_name, limit): static helper that parses size strings like "100M", "1.5G", "512K", or "0" into a byte count. Useful when configuring a RuntimeEnvBuilder from human-friendly inputs. Wraps SessionContext::parse_capacity_limit; the deprecated parse_memory_limit is intentionally not exposed. Three other items from the same gap cluster (runtime_env, copied_table_options, the deprecated parse_memory_limit) are not included here. The first two would require wrapping new Rust types (RuntimeEnv, TableOptions) whose surface is much larger than the accessors themselves; the third is deprecated upstream. Those are filed as separate follow-up issues. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d021e6a commit 68a2416

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

crates/core/src/context.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1162,6 +1162,20 @@ impl PySessionContext {
11621162
self.ctx.session_id()
11631163
}
11641164

1165+
/// Return a copy of the active `SessionConfig`. Mutating the returned
1166+
/// config does not affect this context.
1167+
pub fn copied_config(&self) -> PySessionConfig {
1168+
self.ctx.copied_config().into()
1169+
}
1170+
1171+
/// Parse a string like `"100M"`, `"1.5G"`, or `"512K"` into a byte count.
1172+
/// `"0"` is accepted and returns 0. Use this when constructing a
1173+
/// `RuntimeEnvBuilder` from a human-friendly size string.
1174+
#[staticmethod]
1175+
pub fn parse_capacity_limit(config_name: &str, limit: &str) -> PyDataFusionResult<usize> {
1176+
Ok(SessionContext::parse_capacity_limit(config_name, limit)?)
1177+
}
1178+
11651179
pub fn session_start_time(&self) -> String {
11661180
self.ctx.session_start_time().to_rfc3339()
11671181
}

python/datafusion/context.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,45 @@ def enable_ident_normalization(self) -> bool:
15061506
"""
15071507
return self.ctx.enable_ident_normalization()
15081508

1509+
def copied_config(self) -> SessionConfig:
1510+
"""Return a copy of the active :py:class:`SessionConfig`.
1511+
1512+
Mutating the returned config does not affect this context; use
1513+
the result when you need a starting point for a new context or
1514+
want to inspect the current settings independent of further
1515+
changes here.
1516+
1517+
Examples:
1518+
>>> ctx = SessionContext(SessionConfig().with_batch_size(1024))
1519+
>>> isinstance(ctx.copied_config(), SessionConfig)
1520+
True
1521+
"""
1522+
config = SessionConfig()
1523+
config.config_internal = self.ctx.copied_config()
1524+
return config
1525+
1526+
@staticmethod
1527+
def parse_capacity_limit(config_name: str, limit: str) -> int:
1528+
"""Parse a size string into a byte count.
1529+
1530+
Accepts strings like ``"100M"``, ``"1.5G"``, or ``"512K"``.
1531+
``"0"`` is accepted and returns 0. ``config_name`` is used purely
1532+
for error messages and identifies which configuration setting the
1533+
limit belongs to. Use this helper when constructing a
1534+
:py:class:`RuntimeEnvBuilder` from a human-friendly size string.
1535+
1536+
Examples:
1537+
>>> SessionContext.parse_capacity_limit(
1538+
... "datafusion.runtime.memory_limit", "1M"
1539+
... )
1540+
1048576
1541+
>>> SessionContext.parse_capacity_limit(
1542+
... "datafusion.runtime.memory_limit", "0"
1543+
... )
1544+
0
1545+
"""
1546+
return SessionContextInternal.parse_capacity_limit(config_name, limit)
1547+
15091548
def parse_sql_expr(self, sql: str, schema: DFSchema) -> Expr:
15101549
"""Parse a SQL expression string into a logical expression.
15111550

0 commit comments

Comments
 (0)