-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
158 changed files
with
20,564 additions
and
3,164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
.vscode | ||
.env | ||
|
||
tmp/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
[submodule "nexus/sqlparser-rs"] | ||
path = nexus/sqlparser-rs | ||
url = git@github.com:PeerDB-io/sqlparser-rs.git | ||
url = https://github.com/PeerDB-io/sqlparser-rs.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
version: v1 | ||
managed: | ||
enabled: true | ||
go_package_prefix: | ||
default: generated/protos | ||
plugins: | ||
- plugin: buf.build/protocolbuffers/go:v1.31.0 | ||
out: flow/generated/protos | ||
opt: paths=source_relative | ||
- plugin: buf.build/grpc/go:v1.3.0 | ||
out: flow/generated/protos | ||
opt: | ||
- paths=source_relative | ||
- plugin: buf.build/community/neoeinstein-prost:v0.2.3 | ||
out: nexus/pt/src | ||
opt: | ||
- compile_well_known_types | ||
- extern_path=.google.protobuf=::pbjson_types | ||
- plugin: buf.build/community/neoeinstein-tonic:v0.3.0 | ||
out: nexus/pt/src | ||
- plugin: buf.build/community/neoeinstein-prost-serde:v0.2.3 | ||
out: nexus/pt/src | ||
opt: | ||
- ignore_unknown_fields=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
*.pyc | ||
|
||
# Packages | ||
*.egg | ||
!/tests/**/*.egg | ||
/*.egg-info | ||
/dist/* | ||
build | ||
_build | ||
.cache | ||
*.so | ||
|
||
# Installer logs | ||
pip-log.txt | ||
|
||
# Unit test / coverage reports | ||
.coverage | ||
.pytest_cache | ||
|
||
.DS_Store | ||
.idea/* | ||
.python-version | ||
.vscode/* | ||
|
||
__pycache__ | ||
|
||
/test.py | ||
/test_*.* | ||
|
||
/setup.cfg | ||
MANIFEST.in | ||
/setup.py | ||
/docs/site/* | ||
/tests/fixtures/simple_project/setup.py | ||
/tests/fixtures/project_with_extras/setup.py | ||
.mypy_cache | ||
|
||
.venv | ||
/releases/* | ||
pip-wheel-metadata | ||
/poetry.toml |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .resources import PeerDBResource | ||
from .ops import peerdb_execute_mirror | ||
from .types import PeerDBMirrorOutput |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from dagster import Config, In, Nothing, Out, Output, op, get_dagster_logger | ||
from pydantic import Field | ||
|
||
from .resources import PeerDBResource | ||
from .types import PeerDBMirrorOutput | ||
|
||
|
||
class PeerDBMirrorConfig(Config): | ||
mirror_name: str = Field( | ||
..., | ||
description="The name of the mirror job to execute." | ||
"This job must already have been created by using the " | ||
"`CREATE MIRROR` commad with `disabled = true`.", | ||
) | ||
|
||
|
||
@op( | ||
ins={"start_after": In(Nothing)}, | ||
out=Out( | ||
PeerDBMirrorOutput, | ||
description=("The output of the peerdb mirror operation."), | ||
), | ||
) | ||
def peerdb_execute_mirror(context, config: PeerDBMirrorConfig, peerdb: PeerDBResource): | ||
log = get_dagster_logger() | ||
workflow_id = peerdb.execute_mirror(config.mirror_name) | ||
log.info(f"Executed PeerDB workflow: {workflow_id}") | ||
output = PeerDBMirrorOutput( | ||
workflow_id=workflow_id, | ||
) | ||
return Output(output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import asyncio | ||
import psycopg | ||
from dagster import ConfigurableResource, get_dagster_logger | ||
from temporalio.client import Client | ||
|
||
|
||
class PeerDBResource(ConfigurableResource): | ||
peerdb_server_jdbc_url: str | ||
temporal_host_port: str | ||
|
||
def execute_mirror( | ||
self, | ||
mirror_name: str, | ||
) -> str: | ||
log = get_dagster_logger() | ||
workflow_id = "" | ||
with psycopg.connect(self.peerdb_server_jdbc_url) as conn: | ||
with conn.cursor() as cur: | ||
cur.execute(f"EXECUTE MIRROR {mirror_name}") | ||
cur.execute( | ||
f"SELECT workflow_id FROM flows WHERE name = '{mirror_name}'" | ||
) | ||
workflow_id = cur.fetchone()[0] | ||
log.info(f"started PeerDB workflow: {workflow_id}") | ||
asyncio.run(self.wait_for_workflow_completion(workflow_id)) | ||
return workflow_id | ||
|
||
async def wait_for_workflow_completion(self, workflow_id: str) -> None: | ||
# sleep for 2 seconds to give the workflow time to start | ||
await asyncio.sleep(2) | ||
log = get_dagster_logger() | ||
client = await Client.connect(self.temporal_host_port, namespace="default") | ||
log.info(f"waiting for PeerDB workflow: {workflow_id}") | ||
handle = client.get_workflow_handle(workflow_id) | ||
await handle.result() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from typing import Any, Mapping, NamedTuple, Optional | ||
|
||
|
||
class PeerDBMirrorOutput( | ||
NamedTuple( | ||
"_PeerDBMirrorOutput", | ||
[ | ||
("workflow_id", str), | ||
], | ||
) | ||
): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from dagster import Definitions, load_assets_from_modules, job | ||
|
||
from dagster_peerdb import PeerDBResource, peerdb_execute_mirror | ||
from dagster_dbt import dbt_cli_resource, dbt_run_op | ||
|
||
from . import assets | ||
from .assets import DBT_PROJECT_DIR | ||
|
||
all_assets = load_assets_from_modules([assets]) | ||
|
||
peerdb_resource = PeerDBResource.configure_at_launch() | ||
|
||
dbt_resource = dbt_cli_resource.configured( | ||
{ | ||
"project_dir": DBT_PROJECT_DIR, | ||
"profiles_dir": DBT_PROJECT_DIR, | ||
}, | ||
) | ||
|
||
|
||
simple_mirror_op = peerdb_execute_mirror.configured( | ||
{ | ||
"mirror_name": "simple_mirror_from_src_to_dst", | ||
}, | ||
name="simple_mirror", | ||
) | ||
|
||
|
||
events_in_usa_op = dbt_run_op.alias(name="events_in_usa_op") | ||
|
||
|
||
@job | ||
def simple_mirror_transform_job(): | ||
dbt_output = events_in_usa_op(start_after=[simple_mirror_op()]) | ||
# return dbt_output | ||
|
||
|
||
defs = Definitions( | ||
assets=all_assets, | ||
jobs=[simple_mirror_transform_job], | ||
resources={ | ||
"peerdb": peerdb_resource, | ||
"dbt": dbt_resource, | ||
}, | ||
) |
Oops, something went wrong.