Skip to content

Commit b89c38b

Browse files
committed
[SPARK-17659][SQL] Partitioned View is Not Supported By SHOW CREATE TABLE
### What changes were proposed in this pull request? `Partitioned View` is not supported by SPARK SQL. For Hive partitioned view, SHOW CREATE TABLE is unable to generate the right DDL. Thus, SHOW CREATE TABLE should not support it like the other Hive-only features. This PR is to issue an exception when detecting the view is a partitioned view. ### How was this patch tested? Added a test case Author: gatorsmile <[email protected]> Closes #15233 from gatorsmile/partitionedView. (cherry picked from commit e256392) Signed-off-by: gatorsmile <[email protected]>
1 parent f672083 commit b89c38b

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ case class ShowCreateTableCommand(table: TableIdentifier) extends RunnableComman
780780
private def showCreateHiveTable(metadata: CatalogTable): String = {
781781
def reportUnsupportedError(features: Seq[String]): Unit = {
782782
throw new AnalysisException(
783-
s"Failed to execute SHOW CREATE TABLE against table ${metadata.identifier.quotedString}, " +
783+
s"Failed to execute SHOW CREATE TABLE against table/view ${metadata.identifier}, " +
784784
"which is created by Hive and uses the following unsupported feature(s)\n" +
785785
features.map(" - " + _).mkString("\n")
786786
)

sql/hive/src/main/scala/org/apache/spark/sql/hive/client/HiveClientImpl.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,10 @@ private[hive] class HiveClientImpl(
377377
unsupportedFeatures += "bucketing"
378378
}
379379

380+
if (h.getTableType == HiveTableType.VIRTUAL_VIEW && partCols.nonEmpty) {
381+
unsupportedFeatures += "partitioned view"
382+
}
383+
380384
val properties = Option(h.getParameters).map(_.asScala.toMap).orNull
381385

382386
CatalogTable(

sql/hive/src/test/scala/org/apache/spark/sql/hive/ShowCreateTableSuite.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,34 @@ class ShowCreateTableSuite extends QueryTest with SQLTestUtils with TestHiveSing
265265
}
266266
}
267267

268+
test("hive partitioned view is not supported") {
269+
withTable("t1") {
270+
withView("v1") {
271+
sql(
272+
s"""
273+
|CREATE TABLE t1 (c1 INT, c2 STRING)
274+
|PARTITIONED BY (
275+
| p1 BIGINT COMMENT 'bla',
276+
| p2 STRING )
277+
""".stripMargin)
278+
279+
createRawHiveTable(
280+
s"""
281+
|CREATE VIEW v1
282+
|PARTITIONED ON (p1, p2)
283+
|AS SELECT * from t1
284+
""".stripMargin
285+
)
286+
287+
val cause = intercept[AnalysisException] {
288+
sql("SHOW CREATE TABLE v1")
289+
}
290+
291+
assert(cause.getMessage.contains(" - partitioned view"))
292+
}
293+
}
294+
}
295+
268296
private def createRawHiveTable(ddl: String): Unit = {
269297
hiveContext.sharedState.externalCatalog.asInstanceOf[HiveExternalCatalog].client.runSqlHive(ddl)
270298
}

0 commit comments

Comments
 (0)