Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#8752] feat(gvfs-python): set operation context in Python gvfs hook (#8868)

Junda Yang89b2012dba21
diff --git a/clients/client-python/gravitino/filesystem/gvfs.py b/clients/client-python/gravitino/filesystem/gvfs.py
index ed7a007ef5..5f0b13aa88 100644
--- a/clients/client-python/gravitino/filesystem/gvfs.py
+++ b/clients/client-python/gravitino/filesystem/gvfs.py
@@ -75,6 +75,7 @@ class GravitinoVirtualFileSystem(fsspec.AbstractFileSystem):
self._operations = self._get_gvfs_operations_class(
server_uri, metalake_name, options
)
+ self._hook.set_operations_context(self._operations)
super().__init__(**kwargs)
diff --git a/clients/client-python/gravitino/filesystem/gvfs_hook.py b/clients/client-python/gravitino/filesystem/gvfs_hook.py
index 22018d3c41..c8ac00249e 100644
--- a/clients/client-python/gravitino/filesystem/gvfs_hook.py
+++ b/clients/client-python/gravitino/filesystem/gvfs_hook.py
@@ -30,6 +30,17 @@ class GravitinoVirtualFileSystemHook(ABC):
idempotent issues if required.
"""
+ def set_operations_context(self, operations):
+ """
+ Set the operations context for this hook. This method will be called during GVFS initialization
+ to provide the hook with access to the BaseGVFSOperations instance.
+
+ Args:
+ operations: The BaseGVFSOperations instance.
+ """
+ # Default implementation does nothing - hooks can override if they need operations access
+ pass
+
@abstractmethod
def initialize(self, config: Optional[Dict[str, str]]):
"""
diff --git a/clients/client-python/tests/unittests/test_gvfs_with_hook.py b/clients/client-python/tests/unittests/test_gvfs_with_hook.py
index 44c721e738..150b6ce07a 100644
--- a/clients/client-python/tests/unittests/test_gvfs_with_hook.py
+++ b/clients/client-python/tests/unittests/test_gvfs_with_hook.py
@@ -34,6 +34,8 @@ class MockGVFSHook(GravitinoVirtualFileSystemHook):
# pylint: disable=too-many-instance-attributes
def __init__(self):
+ self.set_operations_context_called = False
+ self.operations = None
self.ls_called = False
self.info_called = False
self.exists_called = False
@@ -65,6 +67,10 @@ class MockGVFSHook(GravitinoVirtualFileSystemHook):
self.post_created_called = False
self.post_modified_called = False
+ def set_operations_context(self, operations):
+ self.set_operations_context_called = True
+ self.operations = operations
+
def initialize(self, config: Optional[Dict[str, str]]):
pass
@@ -260,6 +266,11 @@ class TestGVFSHook(unittest.TestCase):
},
)
+ # Test that set_operations_context was called during initialization
+ self.assertTrue(fs.hook.set_operations_context_called)
+ self.assertIsNotNone(fs.hook.operations)
+ self.assertEqual(fs.operations, fs.hook.operations)
+
# Test pre_exists and post_exists hook
fs.exists(fileset_virtual_path)
self.assertTrue(fs.hook.exists_called)