Skip to content

Commit

Permalink
feat: add libs library
Browse files Browse the repository at this point in the history
  • Loading branch information
Vixtir committed Sep 18, 2023
1 parent 785dbb3 commit e321f0f
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,19 @@ odd_dbt_test test --profile=my_profile

### Run commands programmatically
You could run that scrip to read, parse and ingest test results to the platform.

```python
# ingest_test_result.py

from odd_dbt import config
from odd_dbt.domain.cli_args import CliArgs
from odd_dbt.lib.dbt import get_context
from odd_dbt.lib.odd import create_dbt_generator_from_oddrn
from odd_dbt.libs.dbt import get_context
from odd_dbt.libs.odd import create_dbt_generator_from_oddrn
from odd_dbt.service.odd import ingest_entities
from odd_dbt.mapper.test_results import DbtTestMapper
from odd_dbt.mapper.lineage import DbtLineageMapper

cfg = config.Config() # All fields can be set manually or read from ENV variables
cfg = config.Config() # All fields can be set manually or read from ENV variables
client = config.create_odd_client(host=cfg.odd_platform_host, token=cfg.odd_platform_token)
generator = create_dbt_generator_from_oddrn(oddrn=cfg.dbt_data_source_oddrn)

Expand Down
2 changes: 1 addition & 1 deletion odd_dbt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from odd_dbt import get_version
from odd_dbt.logger import logger
from odd_dbt.mapper.test_results import DbtTestMapper
from odd_dbt.lib import odd, dbt
from odd_dbt.libs import odd, dbt
from odd_dbt.service import odd as odd_api
from odd_dbt.service.dbt import run_tests, CliArgs

Expand Down
Empty file added odd_dbt/libs/__init__.py
Empty file.
28 changes: 28 additions & 0 deletions odd_dbt/libs/dbt.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import dbt.events.functions as events_functions
from dbt import flags
from dbt.contracts.graph.nodes import ParsedNode, ModelNode

from odd_dbt.domain.cli_args import CliArgs, FlagsArgs
from odd_dbt.domain.context import DbtContext


def collect_flags(cli_args: CliArgs):
flag_args = FlagsArgs(
project_dir=cli_args.project_dir,
profiles_dir=cli_args.profiles_dir,
target=cli_args.target,
profile=cli_args.profile,
)
flags.set_from_args(flag_args, None)
events_functions.set_invocation_id()

return flags.get_flags()


def get_context(cli_args: CliArgs) -> DbtContext:
collect_flags(cli_args)
return DbtContext(cli_args=cli_args)


def is_a_model_node(node: ParsedNode) -> bool:
return isinstance(node, ModelNode)
18 changes: 18 additions & 0 deletions odd_dbt/libs/odd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from odd_models import DataEntity
from oddrn_generator import DbtGenerator


def create_dbt_generator_from_oddrn(oddrn: str) -> DbtGenerator:
return DbtGenerator(host_settings=extract_host_from_oddrn(oddrn))


def create_dbt_generator(host: str) -> DbtGenerator:
return DbtGenerator(host_settings=host)


def extract_host_from_oddrn(oddrn: str) -> str:
return oddrn.split("//dbt/host/")[-1]


def is_data_transformer(data_entity: DataEntity) -> bool:
return data_entity.data_transformer is not None
2 changes: 1 addition & 1 deletion odd_dbt/mapper/lineage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

from odd_dbt import logger
from odd_dbt.domain.context import DbtContext
from odd_dbt.lib.dbt import is_a_model_node
from odd_dbt.libs.dbt import is_a_model_node
from odd_dbt.mapper.generator import create_generator
from odd_dbt.mapper.metadata import get_model_metadata

Expand Down
2 changes: 1 addition & 1 deletion odd_dbt/service/odd.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from odd_models import DataEntityList
from odd_models.api_client.v2.odd_api_client import Client

from odd_dbt.lib.odd import create_dbt_generator
from odd_dbt.libs.odd import create_dbt_generator
from odd_dbt.logger import logger


Expand Down

0 comments on commit e321f0f

Please sign in to comment.