azure-databrickssparkr

How to drop a table in Databricks using SparkR


I have a table written to the warehouse in Databricks, and I would like to drop it using the {SparkR} package. Essentially I would like to do the opposite of SparkR::saveAsTable().

Using SparkR::sql("DROP TABLE IF EXISTS x.y.z;") does work, but is there a dedicated function for this task?


Solution

  • SparkR follows the same syntax and behavior as Spark SQL. There is no dedicated function in the SparkR package for dropping a table.

    However, As you mentioned you are able to use the SparkR::sql() function to execute the SQL statement DROP TABLE IF EXISTS x.y.z; to drop the table.

    I have tried drop a table using SparkR:

    %r
    SparkR::sql
    sql("DROP TABLE IF EXISTS default.my_table;")
    

    enter image description here