Skip to content

Commit f716fb8

Browse files
committed
remove _global_instance
1 parent a9c5b35 commit f716fb8

File tree

2 files changed

+13
-19
lines changed

2 files changed

+13
-19
lines changed

python/datafusion/context.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,6 @@ class SessionContext:
468468
See :ref:`user_guide_concepts` in the online documentation for more information.
469469
"""
470470

471-
_global_instance = None
472-
473471
def __init__(
474472
self,
475473
config: SessionConfig | None = None,
@@ -501,16 +499,16 @@ def __init__(
501499
self.ctx = SessionContextInternal(config, runtime)
502500

503501
@classmethod
504-
def global_ctx(cls) -> "SessionContextInternal":
505-
"""Retrieve the global context.
502+
def global_ctx(cls) -> "SessionContext":
503+
"""Retrieve the global context as a `SessionContext` wrapper.
506504
507505
Returns:
508-
A `SessionContextInternal` object that corresponds to the global context
506+
A `SessionContext` object that wraps the global `SessionContextInternal`.
509507
"""
510-
if cls._global_instance is None:
511-
internal_ctx = SessionContextInternal.global_ctx()
512-
cls._global_instance = internal_ctx
513-
return cls._global_instance
508+
internal_ctx = SessionContextInternal.global_ctx()
509+
wrapper = cls()
510+
wrapper.ctx = internal_ctx
511+
return wrapper
514512

515513
def enable_url_table(self) -> "SessionContext":
516514
"""Control if local files can be queried as tables.
@@ -812,9 +810,11 @@ def register_parquet(
812810
file_extension,
813811
skip_metadata,
814812
schema,
815-
[sort_list_to_raw_sort_list(exprs) for exprs in file_sort_order]
816-
if file_sort_order is not None
817-
else None,
813+
(
814+
[sort_list_to_raw_sort_list(exprs) for exprs in file_sort_order]
815+
if file_sort_order is not None
816+
else None
817+
),
818818
)
819819

820820
def register_csv(

python/tests/test_context.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,7 @@ def test_sql_with_options_no_statements(ctx):
635635

636636
def test_global_context_type():
637637
ctx = SessionContext.global_ctx()
638-
assert isinstance(ctx, SessionContextInternal)
639-
640-
641-
def test_global_context_is_singleton():
642-
ctx1 = SessionContext.global_ctx()
643-
ctx2 = SessionContext.global_ctx()
644-
assert ctx1 is ctx2
638+
assert isinstance(ctx, SessionContext)
645639

646640

647641
@pytest.fixture

0 commit comments

Comments
 (0)