Skip to content

Instantly share code, notes, and snippets.

@MarkPryceMaherMSFT
Last active August 22, 2024 13:04
Show Gist options
  • Save MarkPryceMaherMSFT/17677db067b381528870c5d7028543ce to your computer and use it in GitHub Desktop.
Save MarkPryceMaherMSFT/17677db067b381528870c5d7028543ce to your computer and use it in GitHub Desktop.
# Purpose: Print out details of partitions, files per partitions, and size per partition in GB.
from notebookutils import mssparkutils
# Define ABFSS path for your delta table. You can get ABFSS path of a delta table by simply right-clicking on table name and selecting COPY PATH from the list of options.
delta_table_path = "abfss://ITEM_NAME@ONELAKE_PATH.fabric.microsoft.com/YOURLAKEHOUSE_NAME.Lakehouse/Tables"
# List all partitions for given delta table
tables_list = mssparkutils.fs.ls(delta_table_path)
# Initialize a dictionary to store partition details
table_details = {}
# Iterate through each partition
for tables in tables_list:
if tables.isDir:
tables_name = tables.name
tables_path = tables.path
print(f"Table:{tables_name}")
files = mssparkutils.fs.ls(tables_path + "/_delta_log/")
total_size = sum(file.size for file in files if not file.isDir)
total_size = total_size/ 1024/1024
file_count = sum(1 for file in files if not file.isDir)
print(f"Log Size: {total_size:.2f} MB, File Count: {file_count}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment