cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to drop a table

User16869510359
Esteemed Contributor

I have a Table which and I do not have access to the underlying data any longer. We do not need this dataset anymore, but unable to drop the table

1 ACCEPTED SOLUTION

Accepted Solutions

User16869510359
Esteemed Contributor

Use the below code snippet to forcefully drop the table:

package org.apache.spark.sql.hive {
import org.apache.spark.sql.hive.HiveUtils
import org.apache.spark.SparkContext
 
object utils {
    def dropTable(sc: SparkContext, dbName: String, tableName: String, ignoreIfNotExists: Boolean, purge: Boolean): Unit = {
      HiveUtils
          .newClientForMetadata(sc.getConf, sc.hadoopConfiguration)
          .dropTable(dbName, tableName, ignoreIfNotExists, false)
    }
  }
}

import org.apache.spark.sql.hive.utils
utils.dropTable(sc, "default", "my_table", true, true)

View solution in original post

1 REPLY 1

User16869510359
Esteemed Contributor

Use the below code snippet to forcefully drop the table:

package org.apache.spark.sql.hive {
import org.apache.spark.sql.hive.HiveUtils
import org.apache.spark.SparkContext
 
object utils {
    def dropTable(sc: SparkContext, dbName: String, tableName: String, ignoreIfNotExists: Boolean, purge: Boolean): Unit = {
      HiveUtils
          .newClientForMetadata(sc.getConf, sc.hadoopConfiguration)
          .dropTable(dbName, tableName, ignoreIfNotExists, false)
    }
  }
}

import org.apache.spark.sql.hive.utils
utils.dropTable(sc, "default", "my_table", true, true)

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.