diepvries.table module

Data Vault table.

class diepvries.table.DataVaultTable(schema, name, fields, *_args, **_kwargs)

Bases: Table

A Data Vault table.

Abstract class DataVaultTable. It holds common properties between all subclasses: Hub, Link and Satellite.

__init__(schema, name, fields, *_args, **_kwargs)

Instantiate a Data Vault table.

Besides setting each __init__ argument as instance attributes, it also performs the following actions:

  • Calculate fields_by_name: dictionary with each Field as values and its name as key;

  • Calculate fields_by_role: dictionary with a list of Field as values and its role as key;

  • Check if table structure is valid: in this class, only generic checks (applicable to all Table subclasses). Each subclass will call super()._validate before starting each specific test (only applicable to instances of the subclass).

Parameters:
  • schema (str) – Data Vault schema name.

  • name (str) – Data Vault table name.

  • fields (List[Field]) – List of fields that this table holds.

  • _args – Unused here, useful for children classes.

  • _kwargs – Unused here, useful for children classes.

property fields: List[Field]

Get fields list for the current table.

Return type:

List[Field]

Returns:

Fields for the current table.

property fields_by_name: Dict[str, Field]

Get a dictionary of fields, indexed by their names.

Returns:

Dictionary of fields, indexed by their names.

property fields_by_role: Dict[FieldRole, List[Field]]

Get a dictionary of fields, indexed by their roles.

See _fields_by_role_as_dict.

Returns:

Dictionary of fields, indexed by their roles.

property hashkey_sql: str

Get SQL expression to calculate hashkey fields.

The hashkey formula is the following: MD5(business_key_1 + |~~| + business_key_n + |~~| child_key_1).

Return type:

str

Returns:

Hashkey SQL expression.

abstract property loading_order: int

Get loading order.

Return type:

int

abstract property sql_load_statement: str

Get SQL script to load current table.

Return type:

str

Returns:

SQL script to load current table.

property sql_placeholders: Dict[str, str]

Get common placeholders needed to generate SQL for this Table.

Return type:

Dict[str, str]

Returns:

Common placeholders to be used in all Table SQL scripts.

staging_table: StagingTable
class diepvries.table.StagingTable(schema, name, extract_start_timestamp)

Bases: Table

A table used for staging.

__init__(schema, name, extract_start_timestamp)

Instantiate a StagingTable.

Parameters:
  • schema (str) – Schema name.

  • name (str) – Table name.

  • extract_start_timestamp (datetime) – Extract start timestamp.

class diepvries.table.Table(schema, name, *_args, **_kwargs)

Bases: ABC

A generic table.

Abstract class Table. Holds common properties between all database tables.

__init__(schema, name, *_args, **_kwargs)

Instantiate a table.

Parameters:
  • schema (str) – Schema name.

  • name (str) – Table name.

  • _args – Unused, useful for child classes.

  • _kwargs – Unused, useful for child classes.

__str__()

Representation of a Table object as a string.

This helps the tracking of logging events per entity.

Return type:

str

Returns:

String representation of a Table.