Skip to content

Commit

Permalink
uses qualified names in queries for test utils
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfix committed Aug 7, 2023
1 parent 2f9f2ef commit 37235cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
12 changes: 6 additions & 6 deletions tests/google_sheets/test_google_sheets_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,12 @@ def test_two_overlapping_tables(destination_name) -> None:
# assert first column
assert_query_data(
pipeline,
"SELECT col_1 FROM two_tables ORDER BY 1 ASC",
"SELECT col_1 FROM two_tables ORDER BY col_1 ASC",
list(range(10, 21)) + [None] * 11,
)
# assert first overlapped column
assert_query_data(
pipeline, "SELECT col_7 FROM two_tables ORDER BY 1 ASC", list(range(1, 23))
pipeline, "SELECT col_7 FROM two_tables ORDER BY col_7 ASC", list(range(1, 23))
)


Expand Down Expand Up @@ -459,7 +459,7 @@ def test_explicit_named_range(destination_name) -> None:
# check spreadsheet info
assert_query_data(
pipeline,
"SELECT range FROM spreadsheet_info ORDER BY 1",
"SELECT range FROM spreadsheet_info ORDER BY range ASC",
["empty!ZY1:AAA4", "more_data!A4:D7"],
)

Expand Down Expand Up @@ -516,18 +516,18 @@ def test_table_not_A1():
# check range
assert_query_data(
pipeline,
"SELECT range FROM spreadsheet_info ORDER BY 1",
"SELECT range FROM spreadsheet_info ORDER BY range ASC",
["table_in_middle!AB9:AJ1000"],
)
# check first column
assert_query_data(
pipeline,
"SELECT col_1 FROM table_in_middle ORDER BY 1 ASC",
"SELECT col_1 FROM table_in_middle ORDER BY col_1 ASC",
list(map(str, range(11, 21))) + ["AB9_head"],
)
# check last column
assert_query_data(
pipeline, "SELECT col_9 FROM table_in_middle ORDER BY 1 ASC", range(90, 101)
pipeline, "SELECT col_9 FROM table_in_middle ORDER BY col_9 ASC", range(90, 101)
)


Expand Down
22 changes: 13 additions & 9 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,13 @@ def assert_load_info(info: LoadInfo, expected_load_packages: int = 1) -> None:

def load_table_counts(p: dlt.Pipeline, *table_names: str) -> DictStrAny:
"""Returns row counts for `table_names` as dict"""
query = "\nUNION ALL\n".join(
[f"SELECT '{name}' as name, COUNT(1) as c FROM {name}" for name in table_names]
)
with p.sql_client() as c:
query = "\nUNION ALL\n".join(
[
f"SELECT '{name}' as name, COUNT(1) as c FROM {c.make_qualified_table_name(name)}"
for name in table_names
]
)
with c.execute_query(query) as cur:
rows = list(cur.fetchall())
return {r[0]: r[1] for r in rows}
Expand All @@ -209,13 +212,14 @@ def load_table_distinct_counts(
p: dlt.Pipeline, distinct_column: str, *table_names: str
) -> DictStrAny:
"""Returns counts of distinct values for column `distinct_column` for `table_names` as dict"""
query = "\nUNION ALL\n".join(
[
f"SELECT '{name}' as name, COUNT(DISTINCT {distinct_column}) as c FROM {name}"
for name in table_names
]
)
with p.sql_client() as c:
query = "\nUNION ALL\n".join(
[
f"SELECT '{name}' as name, COUNT(DISTINCT {distinct_column}) as c FROM {c.make_qualified_table_name(name)}"
for name in table_names
]
)

with c.execute_query(query) as cur:
rows = list(cur.fetchall())
return {r[0]: r[1] for r in rows}

0 comments on commit 37235cc

Please sign in to comment.