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

fetch total rows count #79

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions dbt_automation/utils/bigquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,18 @@ def generate_profiles_yaml_dbt(self, project_name, default_schema):
}

return profiles_yml

def get_total_rows(self, schema: str, table: str) -> int:
"""Fetches the total number of rows for a specified table."""
try:
resultset = self.execute(
f"""
SELECT COUNT(*)
FROM "{schema}"."{table}";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't bigquery syntax use backticks... have you tested this

"""
)
total_rows = resultset[0][0] if resultset else 0
return total_rows
except Exception as e:
logger.error(f"Failed to fetch total rows for {schema}.{table}: {e}")
raise
15 changes: 15 additions & 0 deletions dbt_automation/utils/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,18 @@ def generate_profiles_yaml_dbt(self, project_name, default_schema):
}

return profiles_yml

def get_total_rows(self, schema: str, table: str) -> int:
"""Fetches the total number of rows for a specified table."""
try:
resultset = self.execute(
f"""
SELECT COUNT(*)
FROM "{schema}"."{table}";
"""
)
total_rows = resultset[0][0] if resultset else 0
return total_rows
except Exception as e:
logger.error(f"Failed to fetch total rows for {schema}.{table}: {e}")
raise
Loading