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
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import org.apache.hadoop.fs.{FileSystem, Path}

import org.apache.spark.sql.{AnalysisException, Row, SparkSession}
import org.apache.spark.sql.catalyst.analysis.EliminateSubqueryAliases
import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable}
import org.apache.spark.sql.catalyst.catalog.{CatalogRelation, CatalogTable, SimpleCatalogRelation}


/**
Expand All @@ -41,7 +41,7 @@ case class AnalyzeTableCommand(tableName: String) extends RunnableCommand {
val relation = EliminateSubqueryAliases(sessionState.catalog.lookupRelation(tableIdent))

relation match {
case relation: CatalogRelation =>
case relation: CatalogRelation if !relation.isInstanceOf[SimpleCatalogRelation] =>
val catalogTable: CatalogTable = relation.catalogTable
// This method is mainly based on
// org.apache.hadoop.hive.ql.stats.StatsUtils.getFileSizeForTable(HiveConf, Table)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
assert(catalog.getTableMetadata(tableIdent1) === expectedTable)
}

test("Analyze in-memory cataloged tables(SimpleCatalogRelation)") {
withTable("tbl") {
sql("CREATE TABLE tbl(a INT, b INT) USING parquet")
val e = intercept[AnalysisException] {
sql("ANALYZE TABLE tbl COMPUTE STATISTICS")
}.getMessage
assert(e.contains("ANALYZE TABLE is only supported for Hive tables, " +
"but 'tbl' is a SimpleCatalogRelation"))
}
}

test("create table using") {
val catalog = spark.sessionState.catalog
withTable("tbl") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,21 @@ class HiveDDLSuite
}
}

test("Analyze data source tables(LogicalRelation)") {
withTable("t1") {
withTempPath { dir =>
val path = dir.getCanonicalPath
spark.range(1).write.format("parquet").save(path)
sql(s"CREATE TABLE t1 USING parquet OPTIONS (PATH '$path')")
val e = intercept[AnalysisException] {
sql("ANALYZE TABLE t1 COMPUTE STATISTICS")
}.getMessage
assert(e.contains("ANALYZE TABLE is only supported for Hive tables, " +
"but 't1' is a LogicalRelation"))
}
}
}

test("desc table for data source table") {
withTable("tab1") {
val tabName = "tab1"
Expand Down