Dataset_Schema

a class based approach for interacting with Domo Datasets
token_auth = dmda.DomoTokenAuth(
    domo_instance=os.environ["DOMO_INSTANCE"],
    domo_access_token=os.environ["DOMO_ACCESS_TOKEN"],
)

await token_auth.who_am_i()

datasets = (
    await datacenter_routes.search_datacenter(
        auth=token_auth,
        entity_type=datacenter_routes.Datacenter_Enum.DATASET.value,
        # maximum = 25
    )
).response

parent = next(
    (
        dataset
        for dataset in datasets
        if dataset["rowCount"] != 0 
        # and dataset["ownedById"] == token_auth.user_id
    )
)
parent
dataset_id = parent['databaseId']
dataset_id
'f17bae29-3caa-4408-afbd-e2130b7281a5'

Component Classes

DatasetSchema

The DomoDataset_Schema class will be a subclass of DomoDataset. It will handle all of the methods for interacting with schemas.

  • In execution, the schema is separate from the data that gets uploaded from Vault to Adrenaline. The domo schema defines how the data is loaded into Vault.
  • Be cognizant to match dataset uploads with schema definitions. If the schema and uploaded data types do not match, the dataset may be unable to index in Adrenaline (and therefore not update).

source

DomoDataset_Schema_Column

 DomoDataset_Schema_Column (name:str, id:str,
                            type:__main__.DatasetSchema_Types,
                            order:int=0, visible:bool=True,
                            upsert_key:bool=False)

source

DatasetSchema_Types

 DatasetSchema_Types (value, names=None, module=None, qualname=None,
                      type=None, start=1)

An enumeration.

DomoDataset_Schema


source

DomoDataset_Schema

 DomoDataset_Schema (auth:domolibrary.client.DomoAuth.DomoAuth,
                     dataset_id:str, parent:Any=None, columns:List[__main_
                     _.DomoDataset_Schema_Column]=<factory>)

class for interacting with dataset schemas

Sample implementation of getting a dataset schema

Standard implementation will be to access the DomoDataset_Schema class as the DomoDataset.schema property


source

DatasetSchema_InvalidSchema

 DatasetSchema_InvalidSchema (domo_instance, dataset_id, missing_columns,
                              dataset_name=None, message=None)

base exception

ds_schema = DomoDataset_Schema(auth=token_auth, dataset_id=dataset_id)


(await ds_schema.get())[0:5]
[DomoDataset_Schema_Column(name='patronus', id='patronus', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='hogwartsStudent', id='hogwartsStudent', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='image', id='image', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='ancestry', id='ancestry', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='gender', id='gender', type='STRING', order=0, visible=True, upsert_key=False)]
test_df = pd.DataFrame(columns=["A", "B", "C"])

try:
    print(await ds_schema._test_missing_columns(
        auth=token_auth, dataset_id=dataset_id, df=test_df
    ))

except DatasetSchema_InvalidSchema as e:
    print(e)
🛑  DatasetSchema_InvalidSchema 🛑 - function: f17bae29-3caa-4408-afbd-e2130b7281a5 is missing columns A, B, C at domo-community
ds_schema.to_dict()
{'columns': [{'name': 'patronus',
   'id': 'patronus',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'hogwartsStudent',
   'id': 'hogwartsStudent',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'image',
   'id': 'image',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'ancestry',
   'id': 'ancestry',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'gender',
   'id': 'gender',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'alive',
   'id': 'alive',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'hairColour',
   'id': 'hairColour',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'dateOfBirth',
   'id': 'dateOfBirth',
   'type': 'DATE',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'house',
   'id': 'house',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'hogwartsStaff',
   'id': 'hogwartsStaff',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'alternate_names',
   'id': 'alternate_names',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'actor',
   'id': 'actor',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'alternate_actors',
   'id': 'alternate_actors',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'species',
   'id': 'species',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'wand',
   'id': 'wand',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'name',
   'id': 'name',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'wizard',
   'id': 'wizard',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'eyeColour',
   'id': 'eyeColour',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'id',
   'id': 'id',
   'type': 'STRING',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': 'yearOfBirth',
   'id': 'yearOfBirth',
   'type': 'LONG',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': '_BATCH_ID_',
   'id': '_BATCH_ID_',
   'type': 'DOUBLE',
   'order': 0,
   'visible': True,
   'upsertKey': False},
  {'name': '_BATCH_LAST_RUN_',
   'id': '_BATCH_LAST_RUN_',
   'type': 'DATETIME',
   'order': 0,
   'visible': True,
   'upsertKey': False}]}
old_col = ds_schema.columns[-1]
print(old_col.name)

ds_schema.remove_col(old_col, debug_prn=True)[0:5]
_BATCH_LAST_RUN_
[DomoDataset_Schema_Column(name='patronus', id='patronus', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='hogwartsStudent', id='hogwartsStudent', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='image', id='image', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='ancestry', id='ancestry', type='STRING', order=0, visible=True, upsert_key=False),
 DomoDataset_Schema_Column(name='gender', id='gender', type='STRING', order=0, visible=True, upsert_key=False)]
await ds_schema.alter_schema(
    auth=token_auth, dataset_id=dataset_id, return_raw=False
)
ResponseGetData(status=200, response={'schemaId': 11}, is_success=True, parent_class=None)