Skip to content

Commit

Permalink
chore: add dbt read_csv test (#2732)
Browse files Browse the repository at this point in the history
  • Loading branch information
talagluck authored and tychoish committed Mar 6, 2024
1 parent cd0faf9 commit 9dcda74
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{{ config(materialized='view') }}

select *
from dbt_test
JOIN read_csv('https://github.com/GlareDB/glaredb/raw/main/testdata/csv/userdata1.csv') csv
ON dbt_test.amount = csv.id
9 changes: 9 additions & 0 deletions tests/fixtures/dbt_project/profiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,13 @@ glaredb_dbt_test:
threads: 1
type: postgres
user: "{{ env_var('DBT_USER') }}"
cloud:
dbname: default
host: o_PRocU0j.proxy.glaredb.com
pass: glaredb_pw_SFZmILqgkZgsJWPUlnEF1KUts6b1
port: 6543
schema: public
threads: 1
type: postgres
user: 6AhiEN7GQDmo
target: test_target
1 change: 0 additions & 1 deletion tests/fixtures/glaredb.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ def glaredb_path() -> list[pathlib.Path]:
def binary_path(glaredb_path: list[pathlib.Path]) -> pathlib.Path:
return glaredb_path[0] if glaredb_path[0].exists() else glaredb_path[1]


@pytest.fixture
def glaredb_connection(
binary_path: list[pathlib.Path],
Expand Down
38 changes: 38 additions & 0 deletions tests/test_dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,41 @@ def test_dbt_glaredb_external_postgres(
result: list = curr.fetchone()[0]

assert result == 5

def test_dbt_join_csv_with_table(
glaredb_connection: psycopg2.extensions.connection,
dbt_project_path: pathlib.Path,
):
model_name = "join_csv_with_table"

with glaredb_connection.cursor() as curr:
curr.execute("create table dbt_test (amount int)")
curr.execute(
"INSERT INTO dbt_test (amount) VALUES (0), (1), (2), (3), (4), (5), (6), (7), (8), (9)"
)
curr.execute("SELECT * FROM public.dbt_test")
a = curr.fetchall()

with (
tests.tools.env("GLAREDB_PORT", str(glaredb_connection.info.port)),
tests.tools.env("DBT_USER", glaredb_connection.info.user),
):
res: dbtRunnerResult = dbtRunner().invoke(
[
"run",
"--project-dir",
dbt_project_path,
"--profiles-dir",
dbt_project_path,
"-m",
model_name,
]
)

assert res.success is True

with glaredb_connection.cursor() as curr:
curr.execute(f"select count(*) from {model_name}")
result: list = curr.fetchone()[0]

assert result == 9

0 comments on commit 9dcda74

Please sign in to comment.