foundry_dev_tools.clients.tables module#

Implementation of the tables API.

class foundry_dev_tools.clients.tables.TablesClient[source]#

Bases: APIClient

TablesClient class that implements the ‘tables’ api.

api_name: ClassVar[str] = 'tables'#
api_create_table(name, parent_rid, upstream_config, skip_validation=False, **kwargs)[source]#

Low level method to create a virtual table.

Use a high level method like TablesClient.create_glue_table() for easier usage.

Parameters:
  • name (str) – The name of the table. This will be the name of the compass resource.

  • parent_rid (FolderRid) – The parent Rid of the compass resource.

  • upstream_config (dict) – Individual table config.

  • skip_validation (bool) – If true, skips the validation of the table. Default is False.

  • **kwargs – gets passed to APIClient.api_request()

Return type:

requests.Response

create_glue_table(name, parent_rid, connection_rid, table, database, skip_validation=False)[source]#

Creates a Virtual Table backed by the Glue Catalog.

Parameters:
  • name (str) – The name of the table. This will be the name of the compass resource.

  • parent_rid (FolderRid) – The parent Rid of the compass resource.

  • connection_rid (SourceRid) – The rid of the compass Source.

  • table (str) – The name of the table in glue.

  • database (str) – The name of the database in glue.

  • skip_validation (bool) – If true, skips the validation of the table. Default is False.

Return type:

dict

create_snowflake_table(name, parent_rid, connection_rid, database, schema, table, skip_validation=False)[source]#

Creates a Virtual Table on a Snowflake Source.

Parameters:
  • name (str) – The name of the table. This will be the name of the compass resource.

  • parent_rid (FolderRid) – The parent Rid of the compass resource.

  • connection_rid (SourceRid) – The rid of the compass Source.

  • table (str) – The name of the table in snowflake.

  • database (str) – The name of the database Snowflake.

  • schema (str) – The name of the schema in Snowflake.

  • skip_validation (bool) – If true, skips the validation of the table. Default is False.

Return type:

dict

api_list_tables(connection_rid, limit=1000, page_token=None, **kwargs)[source]#

List Virtual Tables for a source.

Parameters:
  • connection_rid (SourceRid)

  • limit (int | None)

  • page_token (str | None)

Return type:

requests.Response

list_tables(connection_rid)[source]#

Returns all tables for a connection/source by handling pagination.

Parameters:

connection_rid (SourceRid) – The rid of the compass Source/Connection.

Returns:

{

‘rid’: ‘ri.tables.main.table.<…>’, ‘upstream’: {

’type’: ‘<type>’, ‘<type>’: {

’connectionRid’: ‘ri.magritte..source.<…>’, ‘relation’: {‘database’: ‘test’, ‘schema’: ‘test’, ‘table’: ‘test2’}

}

}

}

Return type:

a list of dicts with the following format

api_get_table_schema(table_rid, branches, **kwargs)[source]#

Retrieves schema for a Foundry table object per given list of branches.

Parameters:
  • table_rid (TableRid) – The RID of the table to get schema for.

  • branches (list[Branch]) – List of branch names to get schema for.

  • **kwargs – gets passed to APIClient.api_request()

Returns:

The API response containing the table schema.

Return type:

requests.Response

Example::
>>> response = tables_client.api_get_table_schema("ri.foundry.main.dataset.abc123", ["master"])
>>> schema = response.json()
>>> schema
{
    "fieldSchemaList": [
        {
            "type": "DECIMAL",
            "name": "column_A",
            "nullable": false,
            "precision": 38,
            "scale": 0
        },
        {
            "type": "STRING",
            "name": "column_B",
            "nullable": false
        }
    ],
    "primaryKey": null,
    "customMetadata": {"format": "snowflake"}
}