Skip to content

Commit 60371d8

Browse files
committed
address comments
1 parent 61749b7 commit 60371d8

3 files changed

Lines changed: 10 additions & 15 deletions

File tree

sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import scala.util.control.NonFatal
2222
import org.apache.hadoop.fs.{FileSystem, Path}
2323

2424
import org.apache.spark.sql.{AnalysisException, Dataset, Row, SparkSession}
25+
import org.apache.spark.sql.catalyst.TableIdentifier
2526
import org.apache.spark.sql.catalyst.analysis.EliminateSubqueryAliases
2627
import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
27-
import org.apache.spark.sql.catalyst.plans.logical.{LeafNode, Statistics}
28+
import org.apache.spark.sql.catalyst.plans.logical.Statistics
2829
import org.apache.spark.sql.execution.datasources.LogicalRelation
2930

3031

@@ -37,7 +38,9 @@ case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extend
3738
override def run(sparkSession: SparkSession): Seq[Row] = {
3839
val sessionState = sparkSession.sessionState
3940
val tableIdent = sessionState.sqlParser.parseTableIdentifier(tableName)
40-
val relation = EliminateSubqueryAliases(sessionState.catalog.lookupRelation(tableIdent))
41+
val db = tableIdent.database.getOrElse(sessionState.catalog.getCurrentDatabase)
42+
val qualifiedName = TableIdentifier(tableIdent.table, Some(db))
43+
val relation = EliminateSubqueryAliases(sessionState.catalog.lookupRelation(qualifiedName))
4144

4245
relation match {
4346
case relation: CatalogRelation =>
@@ -91,9 +94,6 @@ case class AnalyzeTableCommand(tableName: String, noscan: Boolean = true) extend
9194
case logicalRel: LogicalRelation if logicalRel.catalogTable.isDefined =>
9295
updateTableStats(logicalRel.catalogTable.get, logicalRel.relation.sizeInBytes)
9396

94-
case o if !o.isInstanceOf[LeafNode] =>
95-
throw new AnalysisException(s"Operation not allowed: ANALYZE TABLE on views: $tableName")
96-
9797
case otherRelation =>
9898
throw new AnalysisException(s"ANALYZE TABLE is not supported for " +
9999
s"${otherRelation.nodeName}.")

sql/core/src/main/scala/org/apache/spark/sql/execution/command/ddl.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import org.apache.hadoop.mapred.{FileInputFormat, JobConf}
2828

2929
import org.apache.spark.sql.{AnalysisException, Row, SparkSession}
3030
import org.apache.spark.sql.catalyst.TableIdentifier
31-
import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
3231
import org.apache.spark.sql.catalyst.catalog.{CatalogDatabase, CatalogTable, CatalogTablePartition, CatalogTableType, SessionCatalog}
3332
import org.apache.spark.sql.catalyst.catalog.CatalogTypes.TablePartitionSpec
3433
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference}
@@ -266,13 +265,10 @@ case class AlterTableUnsetPropertiesCommand(
266265
override def run(sparkSession: SparkSession): Seq[Row] = {
267266
val catalog = sparkSession.sessionState.catalog
268267
DDLUtils.verifyAlterTableType(catalog, tableName, isView)
269-
val table = catalog.getTableMetadata(tableName)
268+
val db = tableName.database.getOrElse(catalog.getCurrentDatabase)
269+
val qualifiedName = TableIdentifier(tableName.table, Some(db))
270+
val table = catalog.getTableMetadata(qualifiedName)
270271

271-
if (catalog.isTemporaryTable(tableName)) {
272-
throw new NoSuchTableException(
273-
db = tableName.database.getOrElse(catalog.getCurrentDatabase),
274-
table = tableName.table)
275-
}
276272
if (!ifExists) {
277273
propKeys.foreach { k =>
278274
if (!table.properties.contains(k)) {

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/SQLViewSuite.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,9 @@ class SQLViewSuite extends QueryTest with SQLTestUtils with TestHiveSingleton {
173173
}.getMessage
174174
assert(e.contains(s"Operation not allowed: SHOW PARTITIONS on temporary tables: `$viewName`"))
175175

176-
e = intercept[AnalysisException] {
176+
intercept[NoSuchTableException] {
177177
sql(s"ANALYZE TABLE $viewName COMPUTE STATISTICS")
178-
}.getMessage
179-
assert(e.contains(s"Operation not allowed: ANALYZE TABLE on views: `$viewName`"))
178+
}
180179
}
181180
}
182181

0 commit comments

Comments
 (0)