Skip to content

Commit

Permalink
feat(ingest/postgres): fetch table sizes for profile (datahub-project…
Browse files Browse the repository at this point in the history
  • Loading branch information
pie1nthesky authored Jul 16, 2024
1 parent 4b83adf commit 298c299
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
16 changes: 16 additions & 0 deletions metadata-ingestion/src/datahub/ingestion/source/sql/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,19 @@ def get_identifier(
return f"{self.config.database}.{regular}"
current_database = self.get_db_name(inspector)
return f"{current_database}.{regular}"

def add_profile_metadata(self, inspector: Inspector) -> None:
try:
with inspector.engine.connect() as conn:
for row in conn.execute(
"""SELECT table_catalog, table_schema, table_name, pg_table_size('"' || table_catalog || '"."' || table_schema || '"."' || table_name || '"') AS table_size FROM information_schema.TABLES"""
):
self.profile_metadata_info.dataset_name_to_storage_bytes[
self.get_identifier(
schema=row.table_schema,
entity=row.table_name,
inspector=inspector,
)
] = row.table_size
except Exception as e:
logger.error(f"failed to fetch profile metadata: {e}")
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,8 @@
{
"fieldPath": "metadata_json"
}
]
],
"sizeInBytes": 16384
}
},
"systemMetadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,8 @@
},
"rowCount": 2,
"columnCount": 9,
"fieldProfiles": []
"fieldProfiles": [],
"sizeInBytes": 16384
}
},
"systemMetadata": {
Expand Down

0 comments on commit 298c299

Please sign in to comment.