Forum Discussion

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi italogomes 

     

    Here is one method with notebook.

    # Step 1: Read the existing Delta table and get its schema
    tablePath = "Tables/TableName"
    read_df = spark.read.format("delta").load(tablePath)
    schema = read_df.schema
    
    # Step 2: Create an empty dataframe with the same structure
    empty_df = spark.createDataFrame([], schema)
    
    # Step 3: Save the empty dataframe to overwrite the existing Delta table
    empty_df.write.format("delta").mode("overwrite").save(tablePath)

     

    Result:

     

    Best Regards,
    Jing
    If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!