diff --git a/clients/client-python/gravitino/exceptions.py b/clients/client-python/gravitino/exceptions.py deleted file mode 100644 index 5779a3ad252..00000000000 --- a/clients/client-python/gravitino/exceptions.py +++ /dev/null @@ -1,4 +0,0 @@ -""" -Copyright 2024 Datastrato Pvt Ltd. -This software is licensed under the Apache License version 2. -""" diff --git a/clients/client-python/gravitino/gravitino_client.py b/clients/client-python/gravitino/gravitino_client.py deleted file mode 100644 index a8f97bb85c7..00000000000 --- a/clients/client-python/gravitino/gravitino_client.py +++ /dev/null @@ -1,158 +0,0 @@ -""" -Copyright 2024 Datastrato Pvt Ltd. -This software is licensed under the Apache License version 2. -""" - -from gravitino.constants import TIMEOUT -from gravitino.service import initialize_service, service - - -class MetaLake: - def __init__(self, metalake_name: str): - self.name = metalake_name - self.service = service["service"] - self.metalake = self.service.get_metalake(self.name) - self.catalogs = self.service.list_catalogs(self.name) - - def __repr__(self): - return f"MetaLake<{self.name}>" - - def __getattr__(self, catalog_name): - if catalog_name in dir(self): - return Catalog(self.name, catalog_name) - - def __dir__(self): - return [catalog["name"] for catalog in self.catalogs] - - def __contains__(self, item): - return item in dir(self) - - -class Catalog: - def __init__(self, metalake_name: str, catalog_name: str): - self.metalake_name = metalake_name - self.catalog_name = catalog_name - self.name = catalog_name - self.service = service["service"] - self.schemas = self.service.list_schemas(metalake_name, catalog_name) - - def __repr__(self): - return f"Catalog<{self.name}>" - - def __getattr__(self, schema_name): - if schema_name in dir(self): - return Schema(self.metalake_name, self.catalog_name, schema_name) - - def __dir__(self): - return [schema["name"] for schema in self.schemas] - - def __contains__(self, item): - return item in dir(self) - - -class Schema: - def __init__(self, metalake_name: str, catalog_name: str, schema_name: str): - self.metalake_name = metalake_name - self.catalog_name = catalog_name - self.schema_name = schema_name - self.name = schema_name - self.service = service["service"] - self.tables = self.service.list_tables(metalake_name, catalog_name, schema_name) - - def __repr__(self): - return f"Schema<{self.name}>" - - def __getattr__(self, table_name): - if table_name in dir(self): - return Table( - self.metalake_name, self.catalog_name, self.schema_name, table_name - ) - - def __dir__(self): - return [table["name"] for table in self.tables] - - def __contains__(self, item): - return item in dir(self) - - -class Table: - def __init__( - self, metalake_name: str, catalog_name: str, schema_name: str, table_name: str - ): - self.metalake_name = metalake_name - self.catalog_name = catalog_name - self.schema_name = schema_name - self.table_name = table_name - self.name = schema_name - self.service = service["service"] - - def __repr__(self): - return f"Table<{self.name}>" - - def info(self): - return self.service.get_table( - self.metalake_name, self.catalog_name, self.schema_name, self.table_name - ) - - -class GravitinoClient: - def __init__( - self, - host: str, - *, - prefix: str = "/api", - timeout: int = TIMEOUT, - debug: bool = False, - ) -> None: - _base_url = f"{host.rstrip('/')}/{prefix.strip('/')}" - initialize_service(_base_url, timeout) - self.service = service["service"] - self.debug = debug - - @classmethod - def initialize_metalake( - cls, - host: str, - metalake_name: str, - *, - prefix: str = "/api", - timeout: int = TIMEOUT, - debug: bool = False, - ) -> MetaLake: - # keep in mind, all constructors should include same interface as __init__ function - client = cls( - host, - prefix=prefix, - timeout=timeout, - debug=debug, - ) - return client.get_metalake(metalake_name) - - @property - def version(self): - return self.service.get_version() - - def get_metalakes(self) -> [MetaLake]: - return [ - MetaLake(metalake.get("name")) for metalake in self.service.list_metalakes() - ] - - def get_metalake(self, metalake: str) -> MetaLake: - return MetaLake(metalake) - - -def gravitino_metalake( - host: str, - metalake_name: str, - *, - prefix: str = "/api", - timeout: int = TIMEOUT, - debug: bool = False, -) -> MetaLake: - return GravitinoClient.initialize_metalake( - host, - metalake_name, - prefix=prefix, - timeout=timeout, - debug=debug, - ) diff --git a/clients/client-python/gravitino/service.py b/clients/client-python/gravitino/service.py deleted file mode 100644 index 9bd4cd6dfbe..00000000000 --- a/clients/client-python/gravitino/service.py +++ /dev/null @@ -1,77 +0,0 @@ -""" -Copyright 2024 Datastrato Pvt Ltd. -This software is licensed under the Apache License version 2. -""" - -from gravitino.utils import HTTPClient, unpack, Response -from gravitino.constants import TIMEOUT - - -class _Service: - def __init__( - self, - url: str, - timeout: int = TIMEOUT, - ) -> None: - self.http_client = HTTPClient(url, timeout=timeout) - - @unpack("version") - def get_version(self) -> Response: - return self.http_client.get("/version") - - @unpack("metalakes") - def list_metalakes(self) -> Response: - return self.http_client.get("/metalakes") - - @unpack("metalake") - def get_metalake(self, metalake: str) -> Response: - return self.http_client.get(f"/metalakes/{metalake}") - - @unpack("identifiers") - def list_catalogs(self, metalake: str) -> Response: - return self.http_client.get(f"/metalakes/{metalake}/catalogs/") - - @unpack("catalog") - def get_catalog(self, metalake: str, catalog: str) -> Response: - return self.http_client.get(f"/metalakes/{metalake}/catalogs/{catalog}") - - @unpack("identifiers") - def list_schemas(self, metalake: str, catalog: str) -> Response: - return self.http_client.get(f"/metalakes/{metalake}/catalogs/{catalog}/schemas") - - @unpack("schema") - def get_schema(self, metalake: str, catalog: str, schema: str) -> Response: - return self.http_client.get( - f"/metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}" - ) - - @unpack("identifiers") - def list_tables(self, metalake: str, catalog: str, schema: str) -> Response: - return self.http_client.get( - f"/metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/tables" - ) - - @unpack("table") - def get_table( - self, metalake: str, catalog: str, schema: str, table: str - ) -> Response: - return self.http_client.get( - f"/metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/tables/{table}" - ) - - @unpack("names") - def list_partitions( - self, metalake: str, catalog: str, schema: str, table: str - ) -> Response: - return self.http_client.get( - f"/metalakes/{metalake}/catalogs/{catalog}/schemas/{schema}/tables/{table}/partitions" - ) - - -service = {} - - -def initialize_service(url: str, timeout: int = TIMEOUT): - global service - if not service: - service["service"] = _Service(url, timeout) diff --git a/clients/client-python/tests/fixtures.py b/clients/client-python/tests/fixtures.py deleted file mode 100644 index dbf47969934..00000000000 --- a/clients/client-python/tests/fixtures.py +++ /dev/null @@ -1,104 +0,0 @@ -""" -Copyright 2024 Datastrato Pvt Ltd. -This software is licensed under the Apache License version 2. -""" - -services_version = { - "version": "0.4.0", - "compileDate": "06/02/2024 08:37:11", - "gitCommit": "ae87dbdef5a749cdbed66d7f0e841cc809ad2510", -} -services_list_metalakes = [ - { - "name": "metalake_demo", - "comment": "comment", - "audit": {"creator": "anonymous", "createTime": "2024-03-30T13:49:53.382Z"}, - } -] -services_get_metalake = { - "name": "metalake_demo", - "comment": "comment", - "audit": {"creator": "anonymous", "createTime": "2024-03-30T13:49:53.382Z"}, -} -services_list_catalogs = [ - {"namespace": ["metalake_demo"], "name": "catalog_hive"}, - {"namespace": ["metalake_demo"], "name": "catalog_iceberg"}, - {"namespace": ["metalake_demo"], "name": "catalog_postgres"}, -] -services_get_catalog = {"namespace": ["metalake_demo"], "name": "catalog_hive"} -services_list_schemas = [ - {"namespace": ["metalake_demo", "catalog_hive"], "name": "default"}, - {"namespace": ["metalake_demo", "catalog_hive"], "name": "sales"}, -] -services_get_schema = {"namespace": ["metalake_demo", "catalog_hive"], "name": "sales"} -services_list_tables = [ - {"namespace": ["metalake_demo", "catalog_hive", "sales"], "name": "categories"}, - {"namespace": ["metalake_demo", "catalog_hive", "sales"], "name": "customers"}, - {"namespace": ["metalake_demo", "catalog_hive", "sales"], "name": "products"}, - {"namespace": ["metalake_demo", "catalog_hive", "sales"], "name": "sales"}, - {"namespace": ["metalake_demo", "catalog_hive", "sales"], "name": "stores"}, -] -services_get_table = { - "name": "sales", - "comment": "", - "columns": [ - { - "name": "sale_id", - "type": "integer", - "nullable": True, - "autoIncrement": False, - }, - { - "name": "employee_id", - "type": "integer", - "nullable": True, - "autoIncrement": False, - }, - { - "name": "store_id", - "type": "integer", - "nullable": True, - "autoIncrement": False, - }, - { - "name": "product_id", - "type": "integer", - "nullable": True, - "autoIncrement": False, - }, - { - "name": "customer_id", - "type": "integer", - "nullable": True, - "autoIncrement": False, - }, - {"name": "sold", "type": "date", "nullable": True, "autoIncrement": False}, - { - "name": "quantity", - "type": "integer", - "nullable": True, - "autoIncrement": False, - }, - { - "name": "total_amount", - "type": "decimal(10,2)", - "nullable": True, - "autoIncrement": False, - }, - ], - "properties": { - "input-format": "org.apache.hadoop.mapred.TextInputFormat", - "transient_lastDdlTime": "1711806631", - "output-format": "org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat", - "location": "hdfs://hive:9000/user/hive/warehouse/sales.db/sales", - "table-type": "MANAGED_TABLE", - "serde-lib": "org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe", - "STATS_GENERATED_VIA_STATS_TASK": "workaround for potential lack of HIVE-12730", - "serde-name": "sales", - }, - "audit": {"creator": "anonymous", "createTime": "2024-03-30T13:50:31.289Z"}, - "distribution": {"strategy": "none", "number": 0, "funcArgs": []}, - "sortOrders": [], - "partitioning": [], - "indexes": [], -} diff --git a/clients/client-python/tests/test_gravitino_client.py b/clients/client-python/tests/test_gravitino_client.py deleted file mode 100644 index 0a2a7e28552..00000000000 --- a/clients/client-python/tests/test_gravitino_client.py +++ /dev/null @@ -1,58 +0,0 @@ -""" -Copyright 2024 Datastrato Pvt Ltd. -This software is licensed under the Apache License version 2. -""" - -import unittest - -from gravitino.gravitino_client import gravitino_metalake, GravitinoClient -from .utils import services_fixtures - - -@services_fixtures -class TestGravitinoClient(unittest.TestCase): - def setUp(self): - self.client = GravitinoClient("http://localhost:9000") - - def test_version(self, *args): - self.assertIn("version", list(self.client.version.keys())) - - def test_get_metalakes(self, *args): - metalakes = self.client.get_metalakes() - self.assertEqual(len(metalakes), 1) - self.assertEqual(metalakes[0].name, "metalake_demo") - - def test_get_metalake(self, *args): - metalake = self.client.get_metalake("metalake_demo") - self.assertEqual(metalake.name, "metalake_demo") - self.assertIn("catalog_hive", metalake) - - def test_get_catalog(self, *args): - catalog = self.client.get_metalake("metalake_demo").catalog_hive - self.assertEqual(catalog.name, "catalog_hive") - self.assertIn("sales", catalog) - - def test_get_schema(self, *args): - schema = self.client.get_metalake("metalake_demo").catalog_hive.sales - self.assertEqual(schema.name, "sales") - self.assertIn("sales", schema) - - def test_get_table(self, *args): - table = self.client.get_metalake("metalake_demo").catalog_hive.sales.sales - self.assertEqual(table.name, "sales") - self.assertEqual(table.info().get("name"), "sales") - - def test_dynamic_properties(self, *args): - metalake = self.client.get_metalake("metalake_demo") - self.assertIn("catalog_hive", dir(metalake)) - self.assertIn("catalog_iceberg", dir(metalake)) - self.assertIn("catalog_postgres", dir(metalake)) - self.assertEqual(metalake.catalog_hive.name, "catalog_hive") - self.assertEqual(metalake.catalog_hive.sales.name, "sales") - - -@services_fixtures -class TestGravitinoMetalake(unittest.TestCase): - def test_gravitino_metalake(self, *args): - metalake = gravitino_metalake("http://localhost:9000", "metalake_demo") - self.assertEqual(metalake.name, "metalake_demo") diff --git a/clients/client-python/tests/utils.py b/clients/client-python/tests/utils.py deleted file mode 100644 index 9953e929b71..00000000000 --- a/clients/client-python/tests/utils.py +++ /dev/null @@ -1,49 +0,0 @@ -""" -Copyright 2024 Datastrato Pvt Ltd. -This software is licensed under the Apache License version 2. -""" - -from unittest.mock import patch -from . import fixtures - - -def services_fixtures(cls): - @patch( - "gravitino.service._Service.get_version", return_value=fixtures.services_version - ) - @patch( - "gravitino.service._Service.list_metalakes", - return_value=fixtures.services_list_metalakes, - ) - @patch( - "gravitino.service._Service.get_metalake", - return_value=fixtures.services_get_metalake, - ) - @patch( - "gravitino.service._Service.list_catalogs", - return_value=fixtures.services_list_catalogs, - ) - @patch( - "gravitino.service._Service.get_catalog", - return_value=fixtures.services_get_catalog, - ) - @patch( - "gravitino.service._Service.list_schemas", - return_value=fixtures.services_list_schemas, - ) - @patch( - "gravitino.service._Service.get_schema", - return_value=fixtures.services_get_schema, - ) - @patch( - "gravitino.service._Service.list_tables", - return_value=fixtures.services_list_tables, - ) - @patch( - "gravitino.service._Service.get_table", - return_value=fixtures.services_get_table, - ) - class Wrapper(cls): - pass - - return Wrapper