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

migrate library scripts to ingest - FacDB #1313

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
20 changes: 19 additions & 1 deletion dcpy/data/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
client: postgres.PostgresClient,
*,
ignore_columns: list[str] | None = None,
cast_to_numeric: list[str] | None = None,
):
left_columns = client.get_table_columns(left)
right_columns = client.get_table_columns(right)
Expand Down Expand Up @@ -134,6 +135,9 @@
def query(column: str) -> str:
lc = f'"left"."{column}"'
rc = f'"right"."{column}"'
if cast_to_numeric and column in cast_to_numeric:
lc = lc + "::numeric"
rc = rc + "::numeric"

Check warning on line 140 in dcpy/data/compare.py

View check run for this annotation

Codecov / codecov/patch

dcpy/data/compare.py#L139-L140

Added lines #L139 - L140 were not covered by tests
return f"""
SELECT
{left_keys}, {lc} AS "left", {rc} AS "right"
Expand Down Expand Up @@ -194,6 +198,8 @@
key_columns=key_columns,
left_only=_df_to_set_of_lists(left_only),
right_only=_df_to_set_of_lists(right_only),
ignored_columns=ignore_columns,
columns_coerced_to_numeric=cast_to_numeric,
columns_with_diffs=set(comps.keys()),
differences_by_column=comps,
)
Expand All @@ -205,12 +211,19 @@
client: postgres.PostgresClient,
*,
ignore_columns: list[str] | None = None,
cast_to_numeric: list[str] | None = None,
):
left_columns = client.get_table_columns(left)
right_columns = client.get_table_columns(right)

columns = set(left_columns) & set(right_columns) - set(ignore_columns or [])
query_columns = ",".join(f'"{c}"' for c in columns)
if cast_to_numeric:
_columns = [

Check warning on line 221 in dcpy/data/compare.py

View check run for this annotation

Codecov / codecov/patch

dcpy/data/compare.py#L221

Added line #L221 was not covered by tests
f'"{c}"::numeric' if c in cast_to_numeric else f'"{c}"' for c in columns
]
query_columns = ",".join(_columns)

Check warning on line 224 in dcpy/data/compare.py

View check run for this annotation

Codecov / codecov/patch

dcpy/data/compare.py#L224

Added line #L224 was not covered by tests
else:
query_columns = ",".join(f'"{c}"' for c in columns)

Check warning on line 226 in dcpy/data/compare.py

View check run for this annotation

Codecov / codecov/patch

dcpy/data/compare.py#L226

Added line #L226 was not covered by tests

def query(one, two):
return client.execute_select_query(f"""
Expand All @@ -221,6 +234,8 @@

return comparison.SimpleTable(
compared_columns=columns,
ignored_columns=ignore_columns,
columns_coerced_to_numeric=cast_to_numeric,
left_only=query(left, right),
right_only=query(right, left),
)
Expand All @@ -244,6 +259,7 @@
key_columns: list[str] | None = None,
ignore_columns: list[str] | None = None,
columns_only_comparison: bool = False,
cast_to_numeric: list[str] | None = None,
) -> comparison.SqlReport:
left_rows = client.execute_select_query(f"SELECT count(*) AS count FROM {left}")
right_rows = client.execute_select_query(f"SELECT count(*) AS count FROM {right}")
Expand All @@ -256,13 +272,15 @@
key_columns,
client,
ignore_columns=ignore_columns,
cast_to_numeric=cast_to_numeric,
)
else:
data_comp = compare_sql_rows(
left,
right,
client,
ignore_columns=ignore_columns,
cast_to_numeric=cast_to_numeric,
)
return comparison.SqlReport(
tables=comparison.Simple[str](left=left, right=right),
Expand Down
38 changes: 0 additions & 38 deletions dcpy/library/script/dcp_colp.py

This file was deleted.

23 changes: 0 additions & 23 deletions dcpy/library/script/dcp_facilities_with_unmapped.py

This file was deleted.

22 changes: 0 additions & 22 deletions dcpy/library/script/dcp_sfpsd.py

This file was deleted.

61 changes: 0 additions & 61 deletions dcpy/library/script/hra_centers.py

This file was deleted.

18 changes: 0 additions & 18 deletions dcpy/library/script/nysed_nonpublicenrollment.py

This file was deleted.

35 changes: 0 additions & 35 deletions dcpy/library/templates/dcp_colp.yml

This file was deleted.

33 changes: 0 additions & 33 deletions dcpy/library/templates/dcp_facilities_with_unmapped.yml

This file was deleted.

30 changes: 0 additions & 30 deletions dcpy/library/templates/dcp_sfpsd.yml

This file was deleted.

27 changes: 0 additions & 27 deletions dcpy/library/templates/hra_centers.yml

This file was deleted.

Loading