From 5c1e04986606f4ed3d823d9eb104d2b349fcc484 Mon Sep 17 00:00:00 2001 From: mibe Date: Wed, 24 Apr 2024 10:00:23 +0100 Subject: [PATCH] #114 Added as_udf_path method --- exasol/bucketfs/_buckets.py | 38 +++++++++++++++++++++---------------- exasol/bucketfs/_path.py | 9 +++++++++ 2 files changed, 31 insertions(+), 16 deletions(-) diff --git a/exasol/bucketfs/_buckets.py b/exasol/bucketfs/_buckets.py index bed61f95..8d59debc 100644 --- a/exasol/bucketfs/_buckets.py +++ b/exasol/bucketfs/_buckets.py @@ -34,15 +34,15 @@ class BucketLike(Protocol): """ @property - def service_name(self) -> Optional[str]: + def name(self) -> str: """ - Returns the name of the BucketFS service, if known. + Returns the bucket name. """ @property - def name(self) -> str: + def udf_path(self) -> str: """ - Returns the bucket name. + Returns the path to the bucket's base directory, as it's seen from a UDF. """ @property @@ -159,13 +159,17 @@ def __init__( def __str__(self): return f"Bucket<{self.name} | on: {self._service}>" - def service_name(self) -> Optional[str]: - return self._service_name - @property def name(self) -> str: return self._name + @property + def udf_path(self) -> str: + if self._service_name is None: + raise BucketFsError('The bucket cannot provide its udf_path ' + 'as the service name is unknown.') + return f'buckets/{self._service_name}/{self._name}' + @property def _auth(self) -> HTTPBasicAuth: return HTTPBasicAuth(username=self._username, password=self._password) @@ -256,14 +260,17 @@ def __init__(self, url: str, account_id: str, database_id: str, pat: str) -> Non self.database_id = database_id self._pat = pat - def service_name(self) -> str: - # TODO: Find out the name of the service in SaaS - return 'bfsdefault' - + @property def name(self) -> str: # TODO: Find out the name of the bucket in SaaS return 'default' + @property + def udf_path(self) -> str: + # TODO: Find out the name of the service in SaaS + # and how the udf path is constructed. Below is just a guess. + return f'buckets/bfsdefault/{self.name}' + def files(self) -> Iterable[str]: """To be provided""" raise NotImplementedError() @@ -306,21 +313,20 @@ def __init__(self, service_name: str = 'bfsdefault', bucket_name: str = 'default', base_path: Optional[str] = None): - self._service_name = service_name self._name = bucket_name if base_path: self.root = Path(base_path) else: self.root = Path('buckets') / service_name / bucket_name - @property - def service_name(self) -> str: - return self._service_name - @property def name(self) -> str: return self._name + @property + def udf_path(self) -> str: + return str(self.root) + @property def files(self) -> list[str]: return [str(pth.relative_to(self.root)) for pth in self.root.rglob('*.*')] diff --git a/exasol/bucketfs/_path.py b/exasol/bucketfs/_path.py index 14759a01..3193ac3d 100644 --- a/exasol/bucketfs/_path.py +++ b/exasol/bucketfs/_path.py @@ -50,6 +50,12 @@ def as_uri(self) -> str: Represent the path as a file URI. Can be used to reconstruct the location/path. """ + def as_udf_path(self) -> str: + """ + This method is specific to a BucketFS flavour of the PathLike. + It returns a corresponding path, as it's seen from a UDF. + """ + def exists(self) -> bool: """ Return True if the path points to an existing file or directory. @@ -281,6 +287,9 @@ def parent(self) -> str: def as_uri(self) -> str: return self._path.as_uri() + def as_udf_path(self) -> str: + return self._bucket_api.udf_path + def exists(self) -> bool: return self._navigate() is not None