From 1b03d32eb41c07454ae8262ba009b90a818f6000 Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Fri, 19 Aug 2016 23:36:42 -0700 Subject: [PATCH 1/4] fix. --- .../sql/execution/command/AnalyzeTableCommand.scala | 4 ++-- .../apache/spark/sql/execution/command/DDLSuite.scala | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala index a469d4da8613b..9509b66ffd391 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/command/AnalyzeTableCommand.scala @@ -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} /** @@ -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) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index 0f7fda7666a3b..7227882a53c48 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -634,6 +634,16 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { assert(catalog.getTableMetadata(tableIdent1) === expectedTable) } + test("Analyze in-memory cataloged tables") { + withTable("tbl") { + sql("CREATE TABLE tbl(a INT, b INT) USING parquet") + val e = intercept[AnalysisException] { + sql("ANALYZE TABLE tbl COMPUTE STATISTICS") + }.getMessage + e.contains("ANALYZE TABLE is only supported for Hive tables, but 'tbl'") + } + } + test("create table using") { val catalog = spark.sessionState.catalog withTable("tbl") { From a3485651983247aadcc214c9121bd89ee8ce7f06 Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Fri, 19 Aug 2016 23:50:34 -0700 Subject: [PATCH 2/4] add one more test case --- .../spark/sql/hive/execution/HiveDDLSuite.scala | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala index 970b6885f6254..1a4a0f05b375c 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala @@ -620,6 +620,21 @@ class HiveDDLSuite } } + test("Analyze data source tables") { + 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 + e.contains("ANALYZE TABLE is only supported for Hive tables, but 't1'") + + } + } + } + test("desc table for data source table") { withTable("tab1") { val tabName = "tab1" From a8dd663fc25c52cd0a2dbf0eb259f6f6c66ce55d Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Fri, 19 Aug 2016 23:50:51 -0700 Subject: [PATCH 3/4] fix style --- .../scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala index 1a4a0f05b375c..b4497ebaa7fe9 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala @@ -630,7 +630,6 @@ class HiveDDLSuite sql("ANALYZE TABLE t1 COMPUTE STATISTICS") }.getMessage e.contains("ANALYZE TABLE is only supported for Hive tables, but 't1'") - } } } From bb3fd8f3f88f651dec7d8adb5650b80336c23443 Mon Sep 17 00:00:00 2001 From: gatorsmile Date: Sat, 20 Aug 2016 00:01:14 -0700 Subject: [PATCH 4/4] improved the test cases --- .../org/apache/spark/sql/execution/command/DDLSuite.scala | 5 +++-- .../org/apache/spark/sql/hive/execution/HiveDDLSuite.scala | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala index 7227882a53c48..b88762f48fe23 100644 --- a/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala +++ b/sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala @@ -634,13 +634,14 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach { assert(catalog.getTableMetadata(tableIdent1) === expectedTable) } - test("Analyze in-memory cataloged tables") { + 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 - e.contains("ANALYZE TABLE is only supported for Hive tables, but 'tbl'") + assert(e.contains("ANALYZE TABLE is only supported for Hive tables, " + + "but 'tbl' is a SimpleCatalogRelation")) } } diff --git a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala index b4497ebaa7fe9..26f1b3fee8a35 100644 --- a/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala +++ b/sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala @@ -620,7 +620,7 @@ class HiveDDLSuite } } - test("Analyze data source tables") { + test("Analyze data source tables(LogicalRelation)") { withTable("t1") { withTempPath { dir => val path = dir.getCanonicalPath @@ -629,7 +629,8 @@ class HiveDDLSuite val e = intercept[AnalysisException] { sql("ANALYZE TABLE t1 COMPUTE STATISTICS") }.getMessage - e.contains("ANALYZE TABLE is only supported for Hive tables, but 't1'") + assert(e.contains("ANALYZE TABLE is only supported for Hive tables, " + + "but 't1' is a LogicalRelation")) } } }