Skip to content

Commit b80f8e6

Browse files
author
ouyangxiaochen
committed
1. add a comment for method visitCreateTableLike in SparkSqlParser.scala file.
2. repair the error for test cases in HiveDDLSuite.scala file, sql statements lost a pair of single quotes.
1 parent 713ca97 commit b80f8e6

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,7 @@ class SparkSqlAstBuilder(conf: SQLConf) extends AstBuilder {
11491149
val sourceTable = visitTableIdentifier(ctx.source)
11501150
val location = Option(ctx.locationSpec).map(visitLocationSpec)
11511151
if (ctx.EXTERNAL != null && location.isEmpty) {
1152+
// If we are creating an EXTERNAL table, then the LOCATION field is required
11521153
operationNotAllowed("CREATE EXTERNAL TABLE LIKE must be accompanied by LOCATION", ctx)
11531154
}
11541155
CreateTableLikeCommand(targetTable, sourceTable, location, ctx.EXISTS != null)

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ class HiveDDLSuite
842842
spark.range(10).select('id as 'a, 'id as 'b, 'id as 'c, 'id as 'd)
843843
.createTempView(sourceViewName)
844844
val tblType = if (i == 0) "" else "EXTERNAL"
845-
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceViewName LOCATION $basePath")
845+
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceViewName LOCATION '$basePath'")
846846

847847
val sourceTable = spark.sessionState.catalog.getTempViewOrPermanentTableMetadata(
848848
TableIdentifier(sourceViewName))
@@ -886,7 +886,7 @@ class HiveDDLSuite
886886
spark.range(10).select('id as 'a, 'id as 'b, 'id as 'c, 'id as 'd)
887887
.write.format("json").saveAsTable(sourceTabName)
888888
val tblType = if (i == 0) "" else "EXTERNAL"
889-
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION $basePath")
889+
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION '$basePath'")
890890

891891
val sourceTable =
892892
spark.sessionState.catalog.getTableMetadata(
@@ -942,7 +942,7 @@ class HiveDDLSuite
942942
.write.format("parquet").save(path)
943943
sql(s"CREATE TABLE $sourceTabName USING parquet OPTIONS (PATH '${dir.toURI}')")
944944
val tblType = if (i == 0) "" else "EXTERNAL"
945-
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION $basePath")
945+
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION '$basePath'")
946946

947947
// The source table should be an external data source table
948948
val sourceTable = spark.sessionState.catalog.getTableMetadata(
@@ -987,7 +987,7 @@ class HiveDDLSuite
987987
withTable(sourceTabName, targetTabName) {
988988
sql(s"CREATE TABLE $sourceTabName TBLPROPERTIES('prop1'='value1') AS SELECT 1 key, 'a'")
989989
val tblType = if (i == 0) "" else "EXTERNAL"
990-
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION $basePath")
990+
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION '$basePath'")
991991

992992
val sourceTable = catalog.getTableMetadata(
993993
TableIdentifier(sourceTabName, Some("default")))
@@ -1064,7 +1064,7 @@ class HiveDDLSuite
10641064
""".stripMargin)
10651065
}
10661066
val tblType = if (i == 0) "" else "EXTERNAL"
1067-
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION $basePath1")
1067+
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceTabName LOCATION '$basePath1'")
10681068

10691069
val sourceTable = catalog.getTableMetadata(
10701070
TableIdentifier(sourceTabName, Some("default")))
@@ -1118,7 +1118,7 @@ class HiveDDLSuite
11181118
.write.format("json").saveAsTable(sourceTabName)
11191119
sql(s"CREATE VIEW $sourceViewName AS SELECT * FROM $sourceTabName")
11201120
val tblType = if (i == 0) "" else "EXTERNAL"
1121-
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceViewName LOCATION $basePath")
1121+
sql(s"CREATE $tblType TABLE $targetTabName LIKE $sourceViewName LOCATION '$basePath'")
11221122

11231123
val sourceView = spark.sessionState.catalog.getTableMetadata(
11241124
TableIdentifier(sourceViewName, Some("default")))

0 commit comments

Comments
 (0)