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
initial commit
  • Loading branch information
imback82 committed Nov 10, 2020
commit e534ebf64bc7cf7176f6e3b6e9638b45d9154568
Original file line number Diff line number Diff line change
Expand Up @@ -3301,10 +3301,14 @@ class AstBuilder(conf: SQLConf) extends SqlBaseBaseVisitor[AnyRef] with Logging
}

/**
* Creates a [[ShowCreateTableStatement]]
* Creates a [[ShowCreateTable]]
*/
override def visitShowCreateTable(ctx: ShowCreateTableContext): LogicalPlan = withOrigin(ctx) {
ShowCreateTableStatement(visitMultipartIdentifier(ctx.multipartIdentifier()), ctx.SERDE != null)
ShowCreateTable(
UnresolvedTableOrView(
visitMultipartIdentifier(ctx.multipartIdentifier()),
allowTempView = false),
ctx.SERDE != null)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,6 @@ case class UseStatement(isNamespaceSet: Boolean, nameParts: Seq[String]) extends
*/
case class RepairTableStatement(tableName: Seq[String]) extends ParsedStatement

/**
* A SHOW CREATE TABLE statement, as parsed from SQL.
*/
case class ShowCreateTableStatement(
tableName: Seq[String],
asSerde: Boolean = false) extends ParsedStatement

/**
* A CACHE TABLE statement, as parsed from SQL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -622,3 +622,10 @@ case class LoadData(
partition: Option[TablePartitionSpec]) extends Command {
override def children: Seq[LogicalPlan] = child :: Nil
}

/**
* The logical plan of the SHOW CREATE TABLE command.
*/
case class ShowCreateTable(child: LogicalPlan, asSerde: Boolean = false) extends Command {
override def children: Seq[LogicalPlan] = child :: Nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,13 @@ class DDLParserSuite extends AnalysisTest {
test("SHOW CREATE table") {
comparePlans(
parsePlan("SHOW CREATE TABLE a.b.c"),
ShowCreateTableStatement(Seq("a", "b", "c")))
ShowCreateTable(UnresolvedTableOrView(Seq("a", "b", "c"), allowTempView = false)))

comparePlans(
parsePlan("SHOW CREATE TABLE a.b.c AS SERDE"),
ShowCreateTable(
UnresolvedTableOrView(Seq("a", "b", "c"), allowTempView = false),
asSerde = true))
}

test("CACHE TABLE") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -434,13 +434,12 @@ class ResolveSessionCatalog(
isOverwrite,
partition)

case ShowCreateTableStatement(tbl, asSerde) if !asSerde =>
val name = parseTempViewOrV1Table(tbl, "SHOW CREATE TABLE")
ShowCreateTableCommand(name.asTableIdentifier)

case ShowCreateTableStatement(tbl, asSerde) if asSerde =>
val v1TableName = parseV1Table(tbl, "SHOW CREATE TABLE AS SERDE")
ShowCreateTableAsSerdeCommand(v1TableName.asTableIdentifier)
case ShowCreateTable(ResolvedV1TableOrViewIdentifier(ident), asSerde) =>
if (asSerde) {
ShowCreateTableAsSerdeCommand(ident.asTableIdentifier)
} else {
ShowCreateTableCommand(ident.asTableIdentifier)
}

case CacheTableStatement(tbl, plan, isLazy, options) =>
val name = if (plan.isDefined) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ class DataSourceV2Strategy(session: SparkSession) extends Strategy with Predicat
case LoadData(_: ResolvedTable, _, _, _, _) =>
throw new AnalysisException("LOAD DATA is not supported for v2 tables.")

case ShowCreateTable(_: ResolvedTable, _) =>
throw new AnalysisException("SHOW CREATE TABLE is not supported for v2 tables.")

case _ => Nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,17 @@ abstract class ShowCreateTableSuite extends QueryTest with SQLTestUtils {
val ex = intercept[AnalysisException] {
sql(s"SHOW CREATE TABLE $viewName")
}
assert(ex.getMessage.contains("SHOW CREATE TABLE is not supported on a temporary view"))
assert(ex.getMessage.contains(s"$viewName is a temp view not table or permanent view"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR: One idea to improve the error message is to put the command name in UnresolvedTableOrView or other similar plans when the parser creates the command logical plan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good idea! I will follow up on this.

}

withGlobalTempView(viewName) {
sql(s"CREATE GLOBAL TEMPORARY VIEW $viewName AS SELECT 1 AS a")
val globalTempViewDb = spark.sessionState.catalog.globalTempViewManager.database
val ex = intercept[AnalysisException] {
val globalTempViewDb = spark.sessionState.catalog.globalTempViewManager.database
sql(s"SHOW CREATE TABLE $globalTempViewDb.$viewName")
}
assert(ex.getMessage.contains("SHOW CREATE TABLE is not supported on a temporary view"))
assert(ex.getMessage.contains(
s"$globalTempViewDb.$viewName is a temp view not table or permanent view"))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,8 @@ class DataSourceV2SQLSuite
val t = "testcat.ns1.ns2.tbl"
withTable(t) {
spark.sql(s"CREATE TABLE $t (id bigint, data string) USING foo")
testV1CommandSupportingTempView("SHOW CREATE TABLE", t)
testNotSupportedV2Command("SHOW CREATE TABLE", t)
testNotSupportedV2Command("SHOW CREATE TABLE", s"$t AS SERDE")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ abstract class SQLViewSuite extends QueryTest with SQLTestUtils {
val e3 = intercept[AnalysisException] {
sql(s"SHOW CREATE TABLE $viewName")
}.getMessage
assert(e3.contains("SHOW CREATE TABLE is not supported on a temporary view"))
assert(e3.contains(s"$viewName is a temp view not table or permanent view"))
assertNoSuchTable(s"SHOW PARTITIONS $viewName")
val e4 = intercept[AnalysisException] {
sql(s"ANALYZE TABLE $viewName COMPUTE STATISTICS")
Expand Down