- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2023 11:47 PM
Hi,
I need some quick way to return True if Delta Table is Empty.
Tried this, but is is quite slow when checking more tables.
spark.read.table("table_name").count()
spark.read.table("table_name").rdd.isEmpty()
len(spark.read.table("table_name").head(1)) == 0
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-13-2023 01:10 AM
@Retko Okter :
Use the isEmpty method of the DataFrame API in Spark to check if a Delta table is empty
from delta.tables import DeltaTable
def is_delta_table_empty(table_name):
delta_table = DeltaTable.forPath(spark, table_name)
return delta_table.toDF().isEmpty()
# Usage example
if is_delta_table_empty("table_name"):
print("Table is empty")
else:
print("Table is not empty")
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-31-2023 02:59 AM
Hi @Retko Okter
Just wanted to check in if you were able to resolve your issue. If yes, would you be happy to mark an answer as best? If not, please tell us so we can help you.
Thanks!