Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add dbt read_csv test #2732

Merged
merged 9 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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