Remove Temporary Tables from Apache SQL Spark

一个人想着一个人 提交于 2019-11-28 21:21:12

Spark 2.x

For temporary views you can use Catalog.dropTempView:

spark.catalog.dropTempView("df")

For global views you can use Catalog.dropGlobalTempView:

spark.catalog.dropGlobalTempView("df")

Both methods are safe to call if view doesn't exist and, since Spark 2.1, return boolean indicating if the operation succeed.

Spark 1.x

You can use SQLContext.dropTempTable:

scala.util.Try(sqlContext.dropTempTable("df"))

It can be still used in Spark 2.0, but delegates processing to Catalog.dropTempView and is safe to use if table doesn't exist.

in new ver (2.0 and latest) of spark. one should use: createOrReplaceTempView in place of registerTempTable (depricated) and corresponding method to deallocate is: dropTempView

spark.catalog.dropTempView("temp_view_name") //drops the table
심형성 Hyung Sung Shim

If you want to remove your temp table on zeppelin, try like this.

sqlc.dropTempTable("hvac")

or

%sql DROP VIEW hvac

And you can get the informations you need from spark API Docs(http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.package)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!