-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ANSI escape sequence cleanup and replication timing to SlingResource
- Yield sanitized stdout with timings from `replicate` method in SlingResource. - Capture raw logs in `_stdout` list for later streaming. - Include elapsed time metadata in `MaterializeResult` when yielding sync results. - Add Docker-related files for testing Postgres to DuckDB replication using Sling.
- Loading branch information
1 parent
adaaa2d
commit 284a60c
Showing
8 changed files
with
194 additions
and
10 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
7 changes: 7 additions & 0 deletions
7
...lt/dagster_embedded_elt_tests/replication_configs/pg_to_duckdb_with_dag_config/Dockerfile
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,7 @@ | ||
FROM postgres:15 | ||
|
||
ENV POSTGRES_DB=finance | ||
ENV POSTGRES_USER=postgres | ||
ENV POSTGRES_PASSWORD=postgres | ||
|
||
COPY init_finance_db.sql /docker-entrypoint-initdb.d/ |
12 changes: 12 additions & 0 deletions
12
...-elt/dagster_embedded_elt_tests/replication_configs/pg_to_duckdb_with_dag_config/Makefile
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 @@ | ||
@PHONY: build run | ||
|
||
build: | ||
docker build -t finance-postgres . | ||
|
||
run: build | ||
docker run --name finance-db -p 5432:5432 -ti --rm finance-postgres | ||
|
||
sync: | ||
MY_POSTGRES=postgres://postgres:postgres@localhost:5432/finance?sslmode=disable \ | ||
MY_OTHER_POSTGRES=duckdb:///var/tmp/duckdb.db \ | ||
sling run -r sling_replication.yaml |
12 changes: 12 additions & 0 deletions
12
...r_embedded_elt_tests/replication_configs/pg_to_duckdb_with_dag_config/README.md
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 @@ | ||
This is some helper code for internally testing the integration with Sling. | ||
|
||
Run `make run` to build and run a simple Postgres instance that is fed with some | ||
sample data. | ||
|
||
Run the job in `sling_dag.py` with `dagster dev -f sling_dag.py` to see Dagster | ||
load the assets from the replication file, and sync data from PG to DuckDB using | ||
Sling. | ||
|
||
You can interact with the duckdb instance which defaults to /var/tmp/duckdb.db | ||
|
||
This folder is not currently used for automated testing. |
56 changes: 56 additions & 0 deletions
56
...r_embedded_elt_tests/replication_configs/pg_to_duckdb_with_dag_config/init_finance_db.sql
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,56 @@ | ||
\c postgres | ||
|
||
DROP DATABASE IF EXISTS finance; | ||
DROP DATABASE IF EXISTS clone; | ||
CREATE DATABASE finance; | ||
CREATE DATABASE clone; | ||
|
||
\c finance | ||
|
||
CREATE TABLE IF NOT EXISTS accounts ( | ||
account_id serial PRIMARY KEY, | ||
user_id int, | ||
balance decimal(15,2) NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS users ( | ||
user_id serial PRIMARY KEY, | ||
name varchar(255) NOT NULL, | ||
email varchar(255) UNIQUE NOT NULL, | ||
department_id int | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS finance_departments_old ( | ||
department_id serial PRIMARY KEY, | ||
name varchar(255) NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "Transactions"( | ||
id serial PRIMARY KEY, | ||
account_id int, | ||
amount decimal(15,2) NOT NULL, | ||
last_updated_at timestamp without time zone NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "all_Users" ( | ||
all_user_id serial PRIMARY KEY, | ||
name varchar(255) NOT NULL | ||
); | ||
|
||
INSERT INTO accounts (user_id, balance) VALUES | ||
(1, 1000.00), | ||
(2, 1500.00); | ||
|
||
INSERT INTO users (name, email, department_id) VALUES | ||
('John Doe', '[email protected]', 1), | ||
('Jane Smith', '[email protected]', 2); | ||
|
||
INSERT INTO finance_departments_old (name) VALUES ('Accounting'), ('Human Resources'), ('Engineering'); | ||
|
||
INSERT INTO "Transactions" (account_id, amount, last_updated_at) VALUES | ||
(1, -200.00, '2023-01-15 14:30:00'), | ||
(1, 300.00, '2023-02-15 10:00:00'), | ||
(2, -150.00, '2023-01-20 09:00:00'); | ||
|
||
INSERT INTO "all_Users" (name) VALUES ('Alice Johnson'), ('Bob Williams'), ('Charlie Miller'); | ||
|
36 changes: 36 additions & 0 deletions
36
.../dagster_embedded_elt_tests/replication_configs/pg_to_duckdb_with_dag_config/sling_dag.py
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,36 @@ | ||
from dagster import Definitions, file_relative_path | ||
from dagster_embedded_elt.sling import DagsterSlingTranslator, sling_assets | ||
from dagster_embedded_elt.sling.resources import SlingConnectionResource, SlingResource | ||
|
||
replication_config = file_relative_path(__file__, "sling_replication.yaml") | ||
|
||
sling_resource = SlingResource( | ||
connections=[ | ||
SlingConnectionResource( | ||
name="MY_POSTGRES", | ||
type="postgres", | ||
connection_string="postgres://postgres:postgres@localhost:5432/finance?sslmode=disable", | ||
), | ||
SlingConnectionResource( | ||
name="MY_DUCKDB", | ||
type="duckdb", | ||
connection_string="duckdb:///var/tmp/duckdb.db", | ||
), | ||
] | ||
) | ||
|
||
|
||
@sling_assets(replication_config=replication_config) | ||
def my_assets(context, sling: SlingResource): | ||
yield from sling.replicate( | ||
replication_config=replication_config, | ||
dagster_sling_translator=DagsterSlingTranslator(), | ||
) | ||
for row in sling.stream_raw_logs(): | ||
context.log.info(row) | ||
|
||
|
||
defs = Definitions( | ||
assets=[my_assets], | ||
resources={"sling": sling_resource}, | ||
) |
33 changes: 33 additions & 0 deletions
33
...mbedded_elt_tests/replication_configs/pg_to_duckdb_with_dag_config/sling_replication.yaml
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,33 @@ | ||
source: MY_POSTGRES | ||
target: MY_DUCKDB | ||
|
||
defaults: | ||
mode: full-refresh | ||
|
||
object: '{stream_schema}_{stream_table}' | ||
|
||
streams: | ||
public.accounts: | ||
public.users: | ||
disabled: true | ||
public.finance_departments_old: | ||
object: 'departments' # overwrite default object | ||
source_options: | ||
empty_as_null: false | ||
meta: | ||
dagster_source: boo | ||
|
||
public."Transactions": | ||
mode: incremental # overwrite default mode | ||
primary_key: id | ||
update_key: last_updated_at | ||
|
||
public.all_users: | ||
sql: | | ||
select all_user_id, name | ||
from public."all_Users" | ||
object: public.all_users # need to add 'object' key for custom SQL | ||
|
||
env: | ||
SLING_LOADED_AT_COLUMN: true # adds the _sling_loaded_at timestamp column | ||
SLING_STREAM_URL_COLUMN: true # if source is file, adds a _sling_stream_url column with file path / url |
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