diepvries.field module

Module for a Data Vault field.

class diepvries.field.Field(parent_table_name, name, data_type, position, is_mandatory, precision=None, scale=None, length=None)

Bases: object

A field in a Data Vault model.

__eq__(other)

Equality of a Data Vault field.

__hash__()

Hash of a Data Vault field.

__init__(parent_table_name, name, data_type, position, is_mandatory, precision=None, scale=None, length=None)

Instantiate a Field.

Convert both name and parent_table_name to lower case.

Parameters:
  • parent_table_name (str) – Name of parent table in the database.

  • name (str) – Column name in the database.

  • data_type (FieldDataType) – Column data type in the database.

  • position (int) – Column position in the database.

  • is_mandatory (bool) – Column is mandatory in the database.

  • precision (Optional[int]) – Numeric precision (maximum number of digits before the decimal separator). Only applicable when self.data_type==FieldDataType.NUMBER.

  • scale (Optional[int]) – Numeric scale (maximum number of digits after the decimal separator). Only applicable when self.data_type==FieldDataType.NUMBER.

  • length (Optional[int]) – Character length (maximum number of characters allowed). Only applicable when self.data_type==FieldDataType.TEXT.

__str__()

Representation of a Field object as a string.

This helps the tracking of logging events per entity.

Return type:

str

Returns:

String representation for the Field object.

property data_type_sql: str

Build SQL expression to represent the field data type.

Return type:

str

property ddl_in_staging: str

Get DDL expression to create this field in the staging table.

Return type:

str

Returns:

The DDL expression for this field.

property hash_concatenation_sql: str

Build SQL expression to deterministically represent the field as a string.

This expression is needed to produce hashes (hashkey/hashdiff) that are consistent, independently on the data type used to store the field in the extraction table.

The SQL expression does the following steps:

  1. Cast field to its data type in the DV model.

2. Produce a consistent string representation of the result of step 1, depending on the field data type. 3. Ensure the result of step 2 never returns NULL.

Return type:

str

Returns:

SQL expression to deterministically represent the field as a string.

property name_in_staging: str

Get the name that this field should have, when created in a staging table.

In most cases this function will return self.name, but for hashdiffs the name is <parent_table_name>_hashdiff (every Satellite has one hashdiff field, named s_hashdiff).

Return type:

str

Returns:

Name of the field in staging.

property parent_table_type: TableType

Get parent table type, based on table prefix.

Return type:

TableType

Returns:

Table type (HUB, LINK or SATELLITE).

property prefix: str

Get field prefix.

Return type:

str

Returns:

Field prefix.

property role: FieldRole

Get the role of the field in a Data Vault model.

See FieldRole enum for more information.

Return type:

FieldRole

Returns:

Field role in a Data Vault model.

Raises:

RuntimeError – When no field role can be attributed.

property suffix: str

Get field suffix.

Return type:

str

Returns:

Field suffix.