Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
NickA01
Resolver III
Resolver III

Notebook for checking lakehouse table row counts.

Hi All. 

I've been trying to look at metadata for a fabric lakehouse. 
Comming from many years of experience, I was looking at doing something with the SQL endpint, information schema ect but that wasn't playing nicely so I've bodged this notebook together. 

Hopefully it will be of use to some people. 


# get all databases in the workspace that start with "xxxxx"
databases = [database.name for database in spark.catalog.listDatabases() if database.name.startswith("WhiteSpace")]
print(databases)
# works 🙂 #

# set database context #
for database in databases:
    print(f"Tables in database {database}:")
 # set the current database
    spark.catalog.setCurrentDatabase(database)

#loop through tables and
tables = spark.catalog.listTables()
lh_tabledata=[]
for table in tables:
    name=table.name
    lh_tabledata.append({"Database": database,"Tables":name,"Rows": spark.read.table(name).count()})

df_metadata = spark.createDataFrame(lh_tabledata)
df_metadata.show(df_metadata.count(),truncate=False)

 

The Nick

If the post helps please give a thumbs up || If it solves your issue, please accept it as the solution to help the other members find it more quickly.

If it's the biggest heap of stinky smelly stuff then I'm sorry .

1 ACCEPTED SOLUTION

@v-gchenna-msft , just sharing info for the hive mind.  😎

View solution in original post

2 REPLIES 2
v-gchenna-msft
Community Support
Community Support

Hi @NickA01 ,

Thanks for using Fabric Community.
Is this a question posted? Or were you sharing some information in this thread?

Can you please confirm it?

@v-gchenna-msft , just sharing info for the hive mind.  😎

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

April Fabric Update Carousel

Fabric Monthly Update - April 2024

Check out the April 2024 Fabric update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Kudoed Authors