Skip to content

Commit

Permalink
Support file create and export (#204)
Browse files Browse the repository at this point in the history
* autogenerates file create and export client code

* updates autogenerated file create and export client code

* adds create_file, export_file

* adds type annotations
  • Loading branch information
antalakas authored Nov 23, 2021
1 parent 69f3d0a commit 4d9b2cd
Show file tree
Hide file tree
Showing 12 changed files with 965 additions and 7 deletions.
2 changes: 2 additions & 0 deletions tiledb/cloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
from tiledb.cloud.array import register_array
from tiledb.cloud.array import share_array
from tiledb.cloud.array import unshare_array
from tiledb.cloud.file import create_file
from tiledb.cloud.file import export_file
from tiledb.cloud.client import Config
from tiledb.cloud.client import Ctx
from tiledb.cloud.client import list_arrays
Expand Down
1 change: 1 addition & 0 deletions tiledb/cloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ def retry_mode(self, mode: RetryOrStr = RetryMode.DEFAULT):
)

self.array_api = rest_api.ArrayApi(client)
self.file_api = rest_api.FilesApi(client)
self.notebook_api = rest_api.NotebookApi(client)
self.organization_api = rest_api.OrganizationApi(client)
self.sql_api = rest_api.SqlApi(client)
Expand Down
66 changes: 66 additions & 0 deletions tiledb/cloud/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
from tiledb.cloud import client
from tiledb.cloud import tiledb_cloud_error
from tiledb.cloud.rest_api import ApiException as GenApiException
from tiledb.cloud.rest_api import models


def create_file(
namespace: str,
input_uri: str,
output_uri: str,
async_req: bool = False,
) -> models.FileCreated:
"""
Creates a TileDB file at the specified location
:param namespace: namespace the create file operation belongs to
:param input_uri: input file uri
:param output_uri: output array uri
:param async_req: return future instead of results for async support
:return: FileCreated details, including file_uuid and output_uri
"""
try:
api_instance = client.client.file_api

file_create = models.FileCreate(
input_uri=input_uri,
output_uri=output_uri,
)

return api_instance.handle_create_file(
namespace,
file_create,
async_req=async_req,
)
except GenApiException as exc:
raise tiledb_cloud_error.check_exc(exc) from None


def export_file(
namespace: str,
file_identifier: str,
output_uri: str,
async_req: bool = False,
) -> models.FileExported:
"""
Exports a TileDB File back to its original file format
:param namespace: namespace the create file operation belongs to
:param file_identifier: the file identifier
:param output_uri: output file uri
:param async_req: return future instead of results for async support
:return: FileExported details, including output_uri
"""
try:
api_instance = client.client.file_api

file_export = models.FileExport(
output_uri=output_uri,
)

return api_instance.handle_export_file(
namespace,
file_identifier,
file_export,
async_req=async_req,
)
except GenApiException as exc:
raise tiledb_cloud_error.check_exc(exc) from None
5 changes: 5 additions & 0 deletions tiledb/cloud/rest_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from tiledb.cloud.rest_api.api.array_api import ArrayApi
from tiledb.cloud.rest_api.api.array_tasks_api import ArrayTasksApi
from tiledb.cloud.rest_api.api.favorites_api import FavoritesApi
from tiledb.cloud.rest_api.api.files_api import FilesApi
from tiledb.cloud.rest_api.api.invitation_api import InvitationApi
from tiledb.cloud.rest_api.api.notebook_api import NotebookApi
from tiledb.cloud.rest_api.api.notebooks_api import NotebooksApi
Expand Down Expand Up @@ -78,6 +79,10 @@
from tiledb.cloud.rest_api.models.domain_array import DomainArray
from tiledb.cloud.rest_api.models.error import Error
from tiledb.cloud.rest_api.models.favorite_create import FavoriteCreate
from tiledb.cloud.rest_api.models.file_create import FileCreate
from tiledb.cloud.rest_api.models.file_created import FileCreated
from tiledb.cloud.rest_api.models.file_export import FileExport
from tiledb.cloud.rest_api.models.file_exported import FileExported
from tiledb.cloud.rest_api.models.file_property_name import FilePropertyName
from tiledb.cloud.rest_api.models.file_type import FileType
from tiledb.cloud.rest_api.models.filter import Filter
Expand Down
1 change: 1 addition & 0 deletions tiledb/cloud/rest_api/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tiledb.cloud.rest_api.api.array_api import ArrayApi
from tiledb.cloud.rest_api.api.array_tasks_api import ArrayTasksApi
from tiledb.cloud.rest_api.api.favorites_api import FavoritesApi
from tiledb.cloud.rest_api.api.files_api import FilesApi
from tiledb.cloud.rest_api.api.invitation_api import InvitationApi
from tiledb.cloud.rest_api.api.notebook_api import NotebookApi
from tiledb.cloud.rest_api.api.notebooks_api import NotebooksApi
Expand Down
23 changes: 16 additions & 7 deletions tiledb/cloud/rest_api/api/favorites_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ def add_ml_model_favorite_with_http_info(self, **kwargs): # noqa: E501
auth_settings = ["ApiKeyAuth", "BasicAuth"] # noqa: E501

return self.api_client.call_api(
"/mlmodels/favorites",
"/ml_models/favorites",
"POST",
path_params,
query_params,
Expand Down Expand Up @@ -735,7 +735,7 @@ def delete_ml_model_favorite_with_http_info(self, id, **kwargs): # noqa: E501
auth_settings = ["ApiKeyAuth", "BasicAuth"] # noqa: E501

return self.api_client.call_api(
"/mlmodels/favorites/{id}",
"/ml_models/favorites/{id}",
"DELETE",
path_params,
query_params,
Expand Down Expand Up @@ -1352,7 +1352,7 @@ def get_ml_model_favorite_with_http_info(self, id, **kwargs): # noqa: E501
auth_settings = ["ApiKeyAuth", "BasicAuth"] # noqa: E501

return self.api_client.call_api(
"/mlmodels/favorites/{id}",
"/ml_models/favorites/{id}",
"GET",
path_params,
query_params,
Expand Down Expand Up @@ -1491,7 +1491,7 @@ def get_ml_model_favorite_for_ml_model_with_http_info(
auth_settings = ["ApiKeyAuth", "BasicAuth"] # noqa: E501

return self.api_client.call_api(
"/mlmodels/favorites/{namespace}/{name}",
"/ml_models/favorites/{namespace}/{name}",
"GET",
path_params,
query_params,
Expand Down Expand Up @@ -2362,7 +2362,7 @@ def list_ml_model_favorites_with_http_info(self, **kwargs): # noqa: E501
auth_settings = ["ApiKeyAuth", "BasicAuth"] # noqa: E501

return self.api_client.call_api(
"/mlmodels/favorites",
"/ml_models/favorites",
"GET",
path_params,
query_params,
Expand Down Expand Up @@ -2473,7 +2473,7 @@ def list_ml_model_favorites_uui_ds_with_http_info(self, **kwargs): # noqa: E501
auth_settings = ["ApiKeyAuth", "BasicAuth"] # noqa: E501

return self.api_client.call_api(
"/mlmodels/favorites/uuids",
"/ml_models/favorites/uuids",
"GET",
path_params,
query_params,
Expand Down Expand Up @@ -2502,6 +2502,7 @@ def list_notebook_favorites(self, **kwargs): # noqa: E501
>>> result = thread.get()
:param async_req bool: execute request asynchronously
:param bool is_dashboard: return only dashboards
:param int page: pagination offset
:param int per_page: pagination limit
:param _preload_content: if False, the urllib3.HTTPResponse object will
Expand All @@ -2528,6 +2529,7 @@ def list_notebook_favorites_with_http_info(self, **kwargs): # noqa: E501
>>> result = thread.get()
:param async_req bool: execute request asynchronously
:param bool is_dashboard: return only dashboards
:param int page: pagination offset
:param int per_page: pagination limit
:param _return_http_data_only: response data without head status code
Expand All @@ -2546,7 +2548,7 @@ def list_notebook_favorites_with_http_info(self, **kwargs): # noqa: E501

local_var_params = locals()

all_params = ["page", "per_page"]
all_params = ["is_dashboard", "page", "per_page"]
all_params.extend(
[
"async_req",
Expand All @@ -2570,6 +2572,13 @@ def list_notebook_favorites_with_http_info(self, **kwargs): # noqa: E501
path_params = {}

query_params = []
if (
"is_dashboard" in local_var_params
and local_var_params["is_dashboard"] is not None
): # noqa: E501
query_params.append(
("is_dashboard", local_var_params["is_dashboard"])
) # noqa: E501
if (
"page" in local_var_params and local_var_params["page"] is not None
): # noqa: E501
Expand Down
Loading

0 comments on commit 4d9b2cd

Please sign in to comment.