Skip to content

Commit 99c2fd0

Browse files
committed
change enable_url_table as method
1 parent 62ae451 commit 99c2fd0

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

examples/create-context.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,5 @@
3838
ctx = SessionContext(config, runtime)
3939
print(ctx)
4040

41-
config = config.with_url_table(True)
42-
ctx = SessionContext(config, runtime)
41+
ctx = ctx.enable_url_table()
4342
print(ctx)

python/datafusion/context.py

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,27 +66,13 @@ def __arrow_c_array__( # noqa: D105
6666
class SessionConfig:
6767
"""Session configuration options."""
6868

69-
def __init__(self, config_options: dict[str, str] | None = None, enable_url_table: bool = False) -> None:
69+
def __init__(self, config_options: dict[str, str] | None = None) -> None:
7070
"""Create a new :py:class:`SessionConfig` with the given configuration options.
7171
7272
Args:
7373
config_options: Configuration options.
7474
"""
7575
self.config_internal = SessionConfigInternal(config_options)
76-
self.enable_url_table = enable_url_table
77-
78-
def with_url_table(self, enabled: bool = True) -> SessionConfig:
79-
80-
"""Control if local files can be queried as tables.
81-
82-
Args:
83-
enabled: Whether local files can be queried as tables.
84-
85-
Returns:
86-
A new :py:class:`SessionConfig` object with the updated setting.
87-
"""
88-
self.enable_url_table = enabled
89-
return self
9076

9177
def with_create_default_catalog_and_schema(
9278
self, enabled: bool = True
@@ -481,11 +467,22 @@ def __init__(
481467
ctx = SessionContext()
482468
df = ctx.read_csv("data.csv")
483469
"""
484-
enable_url_table = config.enable_url_table if config is not None else False
485470
config = config.config_internal if config is not None else None
486471
runtime = runtime.config_internal if runtime is not None else None
487472

488-
self.ctx = SessionContextInternal(config, runtime, enable_url_table)
473+
self.ctx = SessionContextInternal(config, runtime)
474+
475+
def enable_url_table(self) -> "SessionContext":
476+
477+
"""Control if local files can be queried as tables.
478+
479+
Returns:
480+
A new :py:class:`SessionContext` object with url table enabled.
481+
"""
482+
klass = self.__class__
483+
obj = klass.__new__(klass)
484+
obj.ctx = self.ctx.enable_url_table()
485+
return obj
489486

490487
def register_object_store(
491488
self, schema: str, store: Any, host: str | None = None

src/context.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,11 @@ pub struct PySessionContext {
272272

273273
#[pymethods]
274274
impl PySessionContext {
275-
#[pyo3(signature = (config=None, runtime=None, enable_url_table=false))]
275+
#[pyo3(signature = (config=None, runtime=None))]
276276
#[new]
277277
pub fn new(
278278
config: Option<PySessionConfig>,
279279
runtime: Option<PyRuntimeConfig>,
280-
enable_url_table: bool,
281280
) -> PyResult<Self> {
282281
let config = if let Some(c) = config {
283282
c.config
@@ -295,11 +294,15 @@ impl PySessionContext {
295294
.with_runtime_env(runtime)
296295
.with_default_features()
297296
.build();
298-
let mut ctx = SessionContext::new_with_state(session_state);
299-
if enable_url_table {
300-
ctx = ctx.enable_url_table();
301-
}
302-
Ok(PySessionContext { ctx })
297+
Ok(PySessionContext {
298+
ctx: SessionContext::new_with_state(session_state),
299+
})
300+
}
301+
302+
pub fn enable_url_table(&self) -> PyResult<Self> {
303+
Ok(PySessionContext {
304+
ctx: self.ctx.clone().enable_url_table(),
305+
})
303306
}
304307

305308
/// Register an object store with the given name

0 commit comments

Comments
 (0)