Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion project/MimaExcludes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ object MimaExcludes {
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.spark.sql.catalog.Catalog.tableExists"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.spark.sql.catalog.Catalog.functionExists"),
// [SPARK-17338][SQL] add global temp view
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.spark.sql.catalog.Catalog.dropGlobalTempView")
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.spark.sql.catalog.Catalog.dropGlobalTempView"),
ProblemFilters.exclude[IncompatibleResultTypeProblem]("org.apache.spark.sql.catalog.Catalog.dropTempView"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("org.apache.spark.sql.catalog.Catalog.dropTempView")
)
}

Expand Down
5 changes: 5 additions & 0 deletions python/pyspark/sql/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ def createExternalTable(self, tableName, path=None, source=None, schema=None, **
def dropTempView(self, viewName):
"""Drops the local temporary view with the given view name in the catalog.
If the view has been cached before, then it will also be uncached.
Returns true if this view is dropped successfully, false otherwise.

Note that, the return type of this method was None in Spark 2.0, but changed to Boolean
in Spark 2.1.

>>> spark.createDataFrame([(1, 1)]).createTempView("my_table")
>>> spark.table("my_table").collect()
Expand All @@ -185,6 +189,7 @@ def dropTempView(self, viewName):
def dropGlobalTempView(self, viewName):
"""Drops the global temporary view with the given view name in the catalog.
If the view has been cached before, then it will also be uncached.
Returns true if this view is dropped successfully, false otherwise.

>>> spark.createDataFrame([(1, 1)]).createGlobalTempView("my_table")
>>> spark.table("global_temp.my_table").collect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,17 @@ class SessionCatalog(

/**
* Drop a local temporary view.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain what the return value means

*
* Returns true if this view is dropped successfully, false otherwise.
*/
def dropTempView(name: String): Unit = synchronized {
tempTables.remove(formatTableName(name))
def dropTempView(name: String): Boolean = synchronized {
tempTables.remove(formatTableName(name)).isDefined
}

/**
* Drop a global temporary view.
*
* Returns true if this view is dropped successfully, false otherwise.
*/
def dropGlobalTempView(name: String): Boolean = {
globalTempViewManager.remove(formatTableName(name))
Expand Down
9 changes: 2 additions & 7 deletions sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2494,7 +2494,7 @@ class Dataset[T] private[sql](
* preserved database `_global_temp`, and we must use the qualified name to refer a global temp
* view, e.g. `SELECT * FROM _global_temp.view1`.
*
* @throws TempTableAlreadyExistsException if the view name already exists
* @throws AnalysisException if the view name already exists
*
* @group basic
* @since 2.1.0
Expand All @@ -2508,12 +2508,7 @@ class Dataset[T] private[sql](
viewName: String,
replace: Boolean,
global: Boolean): CreateViewCommand = {
val viewType = if (global) {
GlobalTempView
} else {
LocalTempView
}

val viewType = if (global) GlobalTempView else LocalTempView
CreateViewCommand(
name = sparkSession.sessionState.sqlParser.parseTableIdentifier(viewName),
userSpecifiedColumns = Nil,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,14 @@ abstract class Catalog {
* created it, i.e. it will be automatically dropped when the session terminates. It's not
* tied to any databases, i.e. we can't use `db1.view1` to reference a local temporary view.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a line saying the return type was unit in Spark 2.0, but changed to boolean in Spark 2.1?

* Note that, the return type of this method was Unit in Spark 2.0, but changed to Boolean
* in Spark 2.1.
*
* @param viewName the name of the view to be dropped.
* @return true if the view is dropped successfully, false otherwise.
* @since 2.0.0
*/
def dropTempView(viewName: String): Unit
def dropTempView(viewName: String): Boolean

/**
* Drops the global temporary view with the given view name in the catalog.
Expand All @@ -284,6 +288,7 @@ abstract class Catalog {
* view, e.g. `SELECT * FROM _global_temp.view1`.
*
* @param viewName the name of the view to be dropped.
* @return true if the view is dropped successfully, false otherwise.
* @since 2.1.0
*/
def dropGlobalTempView(viewName: String): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,8 @@ class CatalogImpl(sparkSession: SparkSession) extends Catalog {
* @group ddl_ops
* @since 2.0.0
*/
override def dropTempView(viewName: String): Unit = {
sparkSession.sessionState.catalog.getTempView(viewName).foreach { tempView =>
override def dropTempView(viewName: String): Boolean = {
sparkSession.sessionState.catalog.getTempView(viewName).exists { tempView =>
sparkSession.sharedState.cacheManager.uncacheQuery(Dataset.ofRows(sparkSession, tempView))
sessionCatalog.dropTempView(viewName)
}
Expand Down