Skip to content

Commit 03f84a6

Browse files
authored
added api_get_table_schema for TableClient (#104)
* added `api_get_table_schema` for TableClient * added returned example * fmt * fmt
1 parent cca0899 commit 03f84a6

1 file changed

Lines changed: 42 additions & 1 deletion

File tree

  • libs/foundry-dev-tools/src/foundry_dev_tools/clients

libs/foundry-dev-tools/src/foundry_dev_tools/clients/tables.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
if TYPE_CHECKING:
1010
import requests
1111

12-
from foundry_dev_tools.utils.api_types import FolderRid, SourceRid
12+
from foundry_dev_tools.utils.api_types import Branch, FolderRid, SourceRid, TableRid
1313

1414

1515
class TablesClient(APIClient):
@@ -143,3 +143,44 @@ def list_tables(self, connection_rid: SourceRid) -> list[dict]:
143143
response_json = self.api_list_tables(connection_rid=connection_rid, page_token=next_page_token).json()
144144
tables.extend(response_json["tables"])
145145
return tables
146+
147+
def api_get_table_schema(self, table_rid: TableRid, branches: list[Branch], **kwargs) -> requests.Response:
148+
"""Retrieves schema for a Foundry table object per given list of branches.
149+
150+
Args:
151+
table_rid: The RID of the table to get schema for.
152+
branches: List of branch names to get schema for.
153+
**kwargs: gets passed to :py:meth:`APIClient.api_request`
154+
155+
Returns:
156+
requests.Response: The API response containing the table schema.
157+
158+
Example::
159+
>>> response = tables_client.api_get_table_schema("ri.foundry.main.dataset.abc123", ["master"])
160+
>>> schema = response.json()
161+
>>> schema
162+
{
163+
"fieldSchemaList": [
164+
{
165+
"type": "DECIMAL",
166+
"name": "column_A",
167+
"nullable": false,
168+
"precision": 38,
169+
"scale": 0
170+
},
171+
{
172+
"type": "STRING",
173+
"name": "column_B",
174+
"nullable": false
175+
}
176+
],
177+
"primaryKey": null,
178+
"customMetadata": {"format": "snowflake"}
179+
}
180+
"""
181+
return self.api_request(
182+
"POST",
183+
api_path=f"tables/{table_rid}/schema",
184+
json={"branches": branches},
185+
**kwargs,
186+
)

0 commit comments

Comments
 (0)