HWM Type Registry¶
- class etl_entities.hwm.hwm_type_registry.HWMTypeRegistry¶
Registry class for HWM types
- classmethod add(type_name: str, klass: type[HWM]) None¶
Add mapping
HWM class->type nameto registry- Parameters:
- type_name
str Type name
- klass
type HWM class
- type_name
Examples
>>> from etl_entities.hwm import HWMTypeRegistry, HWM >>> class MyHWM(HWM): ... >>> HWMTypeRegistry.add("my_hwm", MyHWM) >>> HWMTypeRegistry.get("my_hwm") <class 'etl_entities.hwm.hwm_type_registry.MyHWM'>
- classmethod get(type_name: str) type[HWM]¶
Get HWM class by type name
- Parameters:
- type_namestr
Type name
Examples
>>> from etl_entities.hwm import HWMTypeRegistry, ColumnIntHWM, ColumnDateHWM >>> HWMTypeRegistry.get("column_int") <class 'etl_entities.hwm.column.int_hwm.ColumnIntHWM'> >>> HWMTypeRegistry.get("column_date") <class 'etl_entities.hwm.column.date_hwm.ColumnDateHWM'> >>> HWMTypeRegistry.get("unknown") Traceback (most recent call last): ... KeyError: "Unknown HWM type 'unknown'"
- classmethod get_key(klass: type[HWM]) str¶
Get HWM type name for a class
- Parameters:
- klassobj:type
HWM class
Examples
>>> from etl_entities.hwm import HWMTypeRegistry, ColumnIntHWM, ColumnDateHWM, HWM >>> HWMTypeRegistry.get_key(ColumnIntHWM) 'column_int' >>> HWMTypeRegistry.get_key(ColumnDateHWM) 'column_date' >>> class UnknownHWM(HWM): ... >>> HWMTypeRegistry.get_key(UnknownHWM) Traceback (most recent call last): ... KeyError: "You should register 'UnknownHWM' class using @register_hwm_type decorator"
- classmethod parse(inp: dict) HWM¶
Parse HWM from dict representation
- Returns:
- resultHWM
Deserialized HWM
Examples
>>> from etl_entities.hwm import HWMTypeRegistry, ColumnIntHWM >>> hwm = HWMTypeRegistry.parse( ... { ... "type": "column_int", ... "name": "some_name", ... "value": "1", ... "entity": "some_entity", ... "description": "some description", ... } ... ) >>> type(hwm) <class 'etl_entities.hwm.column.int_hwm.ColumnIntHWM'> >>> hwm.name 'some_name' >>> hwm.value 1 >>> hwm.entity 'some_entity' >>> hwm.description 'some description' >>> HWMTypeRegistry.parse({"type": "unknown"}) Traceback (most recent call last): ... KeyError: "Unknown HWM type 'unknown'"
- etl_entities.hwm.hwm_type_registry.register_hwm_type(type_name: str)¶
Decorator register some HWM class with a type name
Examples
>>> from etl_entities.hwm import HWMTypeRegistry, register_hwm_type, ColumnHWM >>> @register_hwm_type("my_hwm") ... class MyHWM(ColumnHWM): ... >>> HWMTypeRegistry.get("my_hwm") <class 'etl_entities.hwm.hwm_type_registry.MyHWM'> >>> hwm = HWMTypeRegistry.parse( ... { ... "type": "my_hwm", ... "name": "some_name", ... "value": 1, ... "entity": "some_entity", ... "description": "some description", ... }, ... ) >>> type(hwm) <class 'etl_entities.hwm.hwm_type_registry.MyHWM'> >>> hwm.name 'some_name' >>> hwm.value 1 >>> hwm.entity 'some_entity' >>> hwm.description 'some description'