forked from amundsen-io/amundsendatabuilder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dict_to_model.py
37 lines (25 loc) · 935 Bytes
/
dict_to_model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright Contributors to the Amundsen project.
# SPDX-License-Identifier: Apache-2.0
import importlib
import logging
from pyhocon import ConfigTree # noqa: F401
from typing import Any, Dict # noqa: F401
from databuilder.transformer.base_transformer import Transformer
MODEL_CLASS = 'model_class'
LOGGER = logging.getLogger(__name__)
class DictToModel(Transformer):
"""
Transforms dictionary into model
"""
def init(self, conf):
# type: (ConfigTree) -> None
model_class = conf.get_string(MODEL_CLASS)
module_name, class_name = model_class.rsplit(".", 1)
mod = importlib.import_module(module_name)
self._model_class = getattr(mod, class_name)
def transform(self, record):
# type: (Dict[str, Any]) -> Dict[str, Any]
return self._model_class(**record)
def get_scope(self):
# type: () -> str
return 'transformer.dict_to_model'