Skip to content

Commit

Permalink
add lovac queries and dbt configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Raphaël Courivaud <[email protected]>
  • Loading branch information
rcourivaud committed Jun 30, 2024
1 parent 52553a3 commit d03aa24
Show file tree
Hide file tree
Showing 79 changed files with 282,357 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ yarn-error.log*
.pyc
__pycache__
analytics/dagster/storage/
.duckdb
.jsonl
5 changes: 4 additions & 1 deletion analytics/dagster/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dagster-dbt
dbt-duckdb

matplotlib
pandas
requests
requests
7 changes: 7 additions & 0 deletions analytics/dagster/src/zlv_dbt/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.dagster]
module_name = "zlv_dbt.definitions"
code_location_name = "zlv_dbt"
18 changes: 18 additions & 0 deletions analytics/dagster/src/zlv_dbt/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from setuptools import find_packages, setup

setup(
name="zlv_dbt",
version="0.0.1",
packages=find_packages(),
install_requires=[
"dagster",
"dagster-cloud",
"dagster-dbt",
"dbt-snowflake<1.9",
],
extras_require={
"dev": [
"dagster-webserver",
]
},
)
1 change: 1 addition & 0 deletions analytics/dagster/src/zlv_dbt/zlv_dbt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .definitions import defs as defs
10 changes: 10 additions & 0 deletions analytics/dagster/src/zlv_dbt/zlv_dbt/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dagster import AssetExecutionContext
from dagster_dbt import DbtCliResource, dbt_assets

from .constants import dbt_manifest_path


@dbt_assets(manifest=dbt_manifest_path)
def zlv_dbt_project_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()

21 changes: 21 additions & 0 deletions analytics/dagster/src/zlv_dbt/zlv_dbt/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from pathlib import Path

from dagster_dbt import DbtCliResource

dbt_project_dir = Path(__file__).joinpath("..", "..", "..", "..", "..", "dbt").resolve()
dbt = DbtCliResource(project_dir=os.fspath(dbt_project_dir))

# If DAGSTER_DBT_PARSE_PROJECT_ON_LOAD is set, a manifest will be created at run time.
# Otherwise, we expect a manifest to be present in the project's target directory.
if os.getenv("DAGSTER_DBT_PARSE_PROJECT_ON_LOAD"):
dbt_manifest_path = (
dbt.cli(
["--quiet", "parse"],
target_path=Path("target"),
)
.wait()
.target_path.joinpath("manifest.json")
)
else:
dbt_manifest_path = dbt_project_dir.joinpath("target", "manifest.json")
16 changes: 16 additions & 0 deletions analytics/dagster/src/zlv_dbt/zlv_dbt/definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

from dagster import Definitions
from dagster_dbt import DbtCliResource

from .assets import zlv_dbt_project_dbt_assets
from .constants import dbt_project_dir
from .schedules import schedules

defs = Definitions(
assets=[zlv_dbt_project_dbt_assets],
schedules=schedules,
resources={
"dbt": DbtCliResource(project_dir=os.fspath(dbt_project_dir)),
},
)
15 changes: 15 additions & 0 deletions analytics/dagster/src/zlv_dbt/zlv_dbt/schedules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
To add a daily schedule that materializes your dbt assets, uncomment the following lines.
"""
from dagster_dbt import build_schedule_from_dbt_selection

from .assets import zlv_dbt_project_dbt_assets

schedules = [
# build_schedule_from_dbt_selection(
# [zlv_dbt_project_dbt_assets],
# job_name="materialize_dbt_models",
# cron_schedule="0 0 * * *",
# dbt_select="fqn:*",
# ),
]
3 changes: 2 additions & 1 deletion analytics/dagster/workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
load_from:
- python_module: src
- python_module: src
- python_module: src.zlv_dbt.zlv_dbt
7 changes: 7 additions & 0 deletions analytics/dagster/zlv_dbt/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[tool.dagster]
module_name = "zlv_dbt.definitions"
code_location_name = "zlv_dbt"
18 changes: 18 additions & 0 deletions analytics/dagster/zlv_dbt/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from setuptools import find_packages, setup

setup(
name="zlv_dbt",
version="0.0.1",
packages=find_packages(),
install_requires=[
"dagster",
"dagster-cloud",
"dagster-dbt",
"dbt-snowflake<1.9",
],
extras_require={
"dev": [
"dagster-webserver",
]
},
)
Empty file.
10 changes: 10 additions & 0 deletions analytics/dagster/zlv_dbt/zlv_dbt/assets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from dagster import AssetExecutionContext
from dagster_dbt import DbtCliResource, dbt_assets

from .constants import dbt_manifest_path


@dbt_assets(manifest=dbt_manifest_path)
def zlv_dbt_project_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource):
yield from dbt.cli(["build"], context=context).stream()

21 changes: 21 additions & 0 deletions analytics/dagster/zlv_dbt/zlv_dbt/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
from pathlib import Path

from dagster_dbt import DbtCliResource

dbt_project_dir = Path(__file__).joinpath("..", "..", "..", "..", "dbt_project").resolve()
dbt = DbtCliResource(project_dir=os.fspath(dbt_project_dir))

# If DAGSTER_DBT_PARSE_PROJECT_ON_LOAD is set, a manifest will be created at run time.
# Otherwise, we expect a manifest to be present in the project's target directory.
if os.getenv("DAGSTER_DBT_PARSE_PROJECT_ON_LOAD"):
dbt_manifest_path = (
dbt.cli(
["--quiet", "parse"],
target_path=Path("target"),
)
.wait()
.target_path.joinpath("manifest.json")
)
else:
dbt_manifest_path = dbt_project_dir.joinpath("target", "manifest.json")
16 changes: 16 additions & 0 deletions analytics/dagster/zlv_dbt/zlv_dbt/definitions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import os

from dagster import Definitions
from dagster_dbt import DbtCliResource

from .assets import zlv_dbt_project_dbt_assets
from .constants import dbt_project_dir
from .schedules import schedules

defs = Definitions(
assets=[zlv_dbt_project_dbt_assets],
schedules=schedules,
resources={
"dbt": DbtCliResource(project_dir=os.fspath(dbt_project_dir)),
},
)
15 changes: 15 additions & 0 deletions analytics/dagster/zlv_dbt/zlv_dbt/schedules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
"""
To add a daily schedule that materializes your dbt assets, uncomment the following lines.
"""
from dagster_dbt import build_schedule_from_dbt_selection

from .assets import zlv_dbt_project_dbt_assets

schedules = [
# build_schedule_from_dbt_selection(
# [zlv_dbt_project_dbt_assets],
# job_name="materialize_dbt_models",
# cron_schedule="0 0 * * *",
# dbt_select="fqn:*",
# ),
]
4 changes: 4 additions & 0 deletions analytics/dbt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

target/
dbt_packages/
logs/
2 changes: 2 additions & 0 deletions analytics/dbt/.sqlfluff
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[sqlfluff]
dialect = ansi
1 change: 1 addition & 0 deletions analytics/dbt/.user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
id: 21b741a1-0ed3-4565-8a7c-468d9e923bf0
Empty file added analytics/dbt/analyses/.gitkeep
Empty file.
Loading

0 comments on commit d03aa24

Please sign in to comment.