Skip to content

Commit c26f926

Browse files
committed
expose session config
1 parent d7e137e commit c26f926

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

python/datafusion/context.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ def set(self, key: str, value: str) -> SessionConfig:
290290
self.config_internal = self.config_internal.set(key, value)
291291
return self
292292

293+
def get_all(self) -> dict[str, str]:
294+
"""Returns all configuration options in a dictionary.
295+
296+
Returns:
297+
All configuration options in a dictionary.
298+
"""
299+
return self.config_internal.get_all()
300+
293301

294302
class RuntimeEnvBuilder:
295303
"""Runtime configuration options."""
@@ -1012,6 +1020,10 @@ def empty_table(self) -> DataFrame:
10121020
"""Create an empty :py:class:`~datafusion.dataframe.DataFrame`."""
10131021
return DataFrame(self.ctx.empty_table())
10141022

1023+
def session_config(self) -> SessionConfig:
1024+
"""Return an copy of :py:class:`SessionConfig`."""
1025+
return self.ctx.session_config()
1026+
10151027
def session_id(self) -> str:
10161028
"""Return an id that uniquely identifies this :py:class:`SessionContext`."""
10171029
return self.ctx.session_id()

python/tests/test_context.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,3 +710,10 @@ def test_create_dataframe_with_global_ctx(batch):
710710
result = df.collect()[0].column(0)
711711

712712
assert result == pa.array([4, 5, 6])
713+
714+
715+
def test_get_session_config(ctx):
716+
config = ctx.session_config()
717+
config_dict = config.get_all()
718+
719+
assert config_dict["datafusion.catalog.create_default_catalog_and_schema"] == "true"

src/context.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,23 @@ impl PySessionConfig {
167167
fn set(&self, key: &str, value: &str) -> Self {
168168
Self::from(self.config.clone().set_str(key, value))
169169
}
170+
171+
pub fn get_all(&self, py: Python) -> PyResult<PyObject> {
172+
let entries: Vec<(String, Option<String>)> = {
173+
let options = self.config.options();
174+
options
175+
.entries()
176+
.into_iter()
177+
.map(|entry| (entry.key.clone(), entry.value.clone()))
178+
.collect()
179+
};
180+
181+
let dict = PyDict::new(py);
182+
for (key, value) in entries {
183+
dict.set_item(key, value.into_pyobject(py)?)?;
184+
}
185+
Ok(dict.into())
186+
}
170187
}
171188

172189
/// Runtime options for a SessionContext
@@ -909,6 +926,10 @@ impl PySessionContext {
909926
Ok(PyDataFrame::new(self.ctx.read_empty()?))
910927
}
911928

929+
pub fn session_config(&self) -> PySessionConfig {
930+
self.ctx.copied_config().into()
931+
}
932+
912933
pub fn session_id(&self) -> String {
913934
self.ctx.session_id()
914935
}

0 commit comments

Comments
 (0)