Skip to content

Commit

Permalink
#114 Added as_udf_path method
Browse files Browse the repository at this point in the history
  • Loading branch information
ahsimb committed Apr 24, 2024
1 parent 1f2d399 commit 5c1e049
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
38 changes: 22 additions & 16 deletions exasol/bucketfs/_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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('*.*')]
Expand Down
9 changes: 9 additions & 0 deletions exasol/bucketfs/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 5c1e049

Please sign in to comment.