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

api for table data count #501

Merged
merged 2 commits into from
Mar 9, 2024
Merged
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
18 changes: 18 additions & 0 deletions ddpui/api/warehouse_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@
order_by=order_by,
order=order,
)

@warehouseapi.get(
"/table_count/{schema_name}/{table_name}", auth=auth.CanManagePipelines()
)
def get_table_count(request, schema_name: str, table_name: str):
"""Fetches the total number of rows for a specified table."""
try:
org_user = request.orguser
org_warehouse = OrgWarehouse.objects.filter(org=org_user.org).first()
wtype = org_warehouse.wtype
credentials = secretsmanager.retrieve_warehouse_credentials(org_warehouse)

Check warning on line 139 in ddpui/api/warehouse_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/warehouse_api.py#L135-L139

Added lines #L135 - L139 were not covered by tests

client = get_client(wtype, credentials, org_warehouse.bq_location)
total_rows = client.get_total_rows(schema_name, table_name)
return {"total_rows": total_rows}
except Exception as e:
logger.error(f"Failed to fetch total rows for {schema_name}.{table_name}: {e}")
raise HttpError(500, f"Failed to fetch total rows for {schema_name}.{table_name}")

Check warning on line 146 in ddpui/api/warehouse_api.py

View check run for this annotation

Codecov / codecov/patch

ddpui/api/warehouse_api.py#L141-L146

Added lines #L141 - L146 were not covered by tests
Loading