-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-18217] [SQL] Disallow creating permanent views based on temporary views or UDFs #15764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
509327e
1b430bb
695110f
4dbd3b6
7100a8f
86e7f9d
a4df82b
1c3899f
fec0066
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -553,16 +553,16 @@ class SessionCatalog( | |
| val relationAlias = alias.getOrElse(table) | ||
| if (db == globalTempViewManager.database) { | ||
| globalTempViewManager.get(table).map { viewDef => | ||
| SubqueryAlias(relationAlias, viewDef, Some(name))(isGeneratedByTempTable = true) | ||
| SubqueryAlias(relationAlias, viewDef, Some(name)) | ||
| }.getOrElse(throw new NoSuchTableException(db, table)) | ||
| } else if (name.database.isDefined || !tempTables.contains(table)) { | ||
| val metadata = externalCatalog.getTable(db, table) | ||
| val view = Option(metadata.tableType).collect { | ||
| case CatalogTableType.VIEW => name | ||
| } | ||
| SubqueryAlias(relationAlias, SimpleCatalogRelation(db, metadata), view)() | ||
| SubqueryAlias(relationAlias, SimpleCatalogRelation(db, metadata), view) | ||
| } else { | ||
| SubqueryAlias(relationAlias, tempTables(table), Option(name))(isGeneratedByTempTable = true) | ||
| SubqueryAlias(relationAlias, tempTables(table), Option(name)) | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -926,7 +926,7 @@ class SessionCatalog( | |
| /** | ||
| * Returns whether it is a temporary function. | ||
| */ | ||
| def isTempFunction(name: FunctionIdentifier): Boolean = { | ||
| def isTemporaryFunction(name: FunctionIdentifier): Boolean = { | ||
| // copied from HiveSessionCatalog | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i'd update HiveSessionCatalog to say don't forget to update this place. Otherwise it will be inconsistent.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. Thanks! |
||
| val hiveFunctions = Seq( | ||
| "hash", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,9 @@ | |
| package org.apache.spark.sql.execution.command | ||
|
|
||
| import scala.util.control.NonFatal | ||
|
|
||
| import org.apache.spark.sql.{AnalysisException, Row, SparkSession} | ||
| import org.apache.spark.sql.catalyst.{SQLBuilder, TableIdentifier} | ||
| import org.apache.spark.sql.catalyst.analysis.UnresolvedFunction | ||
| import org.apache.spark.sql.catalyst.analysis.{UnresolvedFunction, UnresolvedRelation} | ||
| import org.apache.spark.sql.catalyst.catalog.{CatalogStorageFormat, CatalogTable, CatalogTableType} | ||
| import org.apache.spark.sql.catalyst.expressions.Alias | ||
| import org.apache.spark.sql.catalyst.plans.QueryPlan | ||
|
|
@@ -133,18 +132,17 @@ case class CreateViewCommand( | |
|
|
||
| // When creating a permanent view, not allowed to reference temporary objects. | ||
| if (!isTemporary) { | ||
|
||
| // Disallow creating permanent views based on temporary views. | ||
| analyzedPlan.collectFirst { | ||
| case s: SubqueryAlias if s.isGeneratedByTempTable => | ||
| child.collect { | ||
| // Disallow creating permanent views based on temporary views. | ||
|
||
| case s: UnresolvedRelation | ||
| if sparkSession.sessionState.catalog.isTemporaryTable(s.tableIdentifier) => | ||
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temp view `${s.alias}`. " + | ||
| s"referencing a temp view ${s.tableIdentifier}. " + | ||
|
||
| originalText.map(sql => s"""SQL: "$sql".""").getOrElse("")) | ||
|
||
| } | ||
|
|
||
| // Disallow creating permanent views based on temporary UDFs. | ||
| child.collect { | ||
| case other if !other.resolved => other.expressions.flatMap(_.collect { | ||
| case e: UnresolvedFunction if sparkSession.sessionState.catalog.isTempFunction(e.name) => | ||
| // Disallow creating permanent views based on temporary UDFs. | ||
| case e: UnresolvedFunction | ||
| if sparkSession.sessionState.catalog.isTemporaryFunction(e.name) => | ||
| throw new AnalysisException(s"Not allowed to create a permanent view $name by " + | ||
| s"referencing a temp function `${e.name}`. " + | ||
|
||
| originalText.map(sql => s"""SQL: "$sql".""").getOrElse("")) | ||
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a unit test for this function?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also what's the behavior if the function doesn't exist? make sure you test it in the unit test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will resolve this tomorrow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like
isTemporaryTable, we return false when the function/table does not existThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea please docuemnt it.