Skip to content

Commit b9dacc5

Browse files
committed
Address comments.
1 parent 7795355 commit b9dacc5

File tree

2 files changed

+50
-13
lines changed

2 files changed

+50
-13
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,7 +1165,7 @@ case class ShowCreateTableAsSparkCommand(table: TableIdentifier)
11651165

11661166
val stmt = if (DDLUtils.isDatasourceTable(tableMetadata)) {
11671167
throw new AnalysisException(
1168-
s"$table is already a Spark data source table. Using `SHOW CREATE TABLE` instead.")
1168+
s"$table is already a Spark data source table. Use `SHOW CREATE TABLE` instead.")
11691169
} else {
11701170
if (tableMetadata.unsupportedFeatures.nonEmpty) {
11711171
throw new AnalysisException(
@@ -1180,6 +1180,13 @@ case class ShowCreateTableAsSparkCommand(table: TableIdentifier)
11801180
throw new AnalysisException("Hive view isn't supported by SHOW CREATE TABLE AS SPARK")
11811181
}
11821182

1183+
// scalastyle:off caselocale
1184+
if (tableMetadata.properties.getOrElse("transactional", "false").toLowerCase.equals("true")) {
1185+
throw new AnalysisException(
1186+
"SHOW CRETE TABLE AS SPARK doesn't support transactional Hive table")
1187+
}
1188+
// scalastyle:on caselocale
1189+
11831190
showCreateDataSourceTable(convertTableMetadata(tableMetadata))
11841191
}
11851192

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

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,8 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
263263
test("simple hive table as spark") {
264264
withTable("t1") {
265265
sql(
266-
s"""CREATE TABLE t1 (
266+
s"""
267+
|CREATE TABLE t1 (
267268
| c1 STRING COMMENT 'bla',
268269
| c2 STRING
269270
|)
@@ -281,7 +282,8 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
281282
test("show create table as spark can't work on data source table") {
282283
withTable("t1") {
283284
sql(
284-
s"""CREATE TABLE t1 (
285+
s"""
286+
|CREATE TABLE t1 (
285287
| c1 STRING COMMENT 'bla',
286288
| c2 STRING
287289
|)
@@ -293,15 +295,16 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
293295
checkCreateSparkTable("t1")
294296
}
295297

296-
assert(cause.getMessage.contains("Using `SHOW CREATE TABLE` instead"))
298+
assert(cause.getMessage.contains("Use `SHOW CREATE TABLE` instead"))
297299
}
298300
}
299301

300302
test("simple external hive table as spark") {
301303
withTempDir { dir =>
302304
withTable("t1") {
303305
sql(
304-
s"""CREATE TABLE t1 (
306+
s"""
307+
|CREATE TABLE t1 (
305308
| c1 STRING COMMENT 'bla',
306309
| c2 STRING
307310
|)
@@ -321,7 +324,8 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
321324
test("hive table with STORED AS clause as spark") {
322325
withTable("t1") {
323326
sql(
324-
s"""CREATE TABLE t1 (
327+
s"""
328+
|CREATE TABLE t1 (
325329
| c1 INT COMMENT 'bla',
326330
| c2 STRING
327331
|)
@@ -336,7 +340,8 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
336340
test("hive table with unsupported fileformat as spark") {
337341
withTable("t1") {
338342
sql(
339-
s"""CREATE TABLE t1 (
343+
s"""
344+
|CREATE TABLE t1 (
340345
| c1 INT COMMENT 'bla',
341346
| c2 STRING
342347
|)
@@ -355,7 +360,8 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
355360
test("hive table with serde info as spark") {
356361
withTable("t1") {
357362
sql(
358-
s"""CREATE TABLE t1 (
363+
s"""
364+
|CREATE TABLE t1 (
359365
| c1 INT COMMENT 'bla',
360366
| c2 STRING
361367
|)
@@ -373,10 +379,7 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
373379
test("hive view is not supported as spark") {
374380
withTable("t1") {
375381
withView("v1") {
376-
sql(
377-
s"""
378-
|CREATE TABLE t1 (c1 STRING, c2 STRING)
379-
""".stripMargin)
382+
sql("CREATE TABLE t1 (c1 STRING, c2 STRING)")
380383

381384
createRawHiveTable(
382385
s"""
@@ -397,7 +400,8 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
397400
test("partitioned, bucketed hive table as spark") {
398401
withTable("t1") {
399402
sql(
400-
s"""CREATE TABLE t1 (
403+
s"""
404+
|CREATE TABLE t1 (
401405
| emp_id INT COMMENT 'employee id', emp_name STRING,
402406
| emp_dob STRING COMMENT 'employee date of birth', emp_sex STRING COMMENT 'M/F'
403407
|)
@@ -413,4 +417,30 @@ class HiveShowCreateTableSuite extends ShowCreateTableSuite with TestHiveSinglet
413417
checkCreateSparkTable("t1")
414418
}
415419
}
420+
421+
test("transactional hive table as spark") {
422+
withTable("t1") {
423+
sql(
424+
s"""
425+
|CREATE TABLE t1 (
426+
| c1 STRING COMMENT 'bla',
427+
| c2 STRING
428+
|)
429+
|TBLPROPERTIES (
430+
| 'transactional' = 'true',
431+
| 'prop1' = 'value1',
432+
| 'prop2' = 'value2'
433+
|)
434+
""".stripMargin
435+
)
436+
437+
438+
val cause = intercept[AnalysisException] {
439+
sql("SHOW CREATE TABLE t1 AS SPARK")
440+
}
441+
442+
assert(cause.getMessage.contains(
443+
"SHOW CRETE TABLE AS SPARK doesn't support transactional Hive table"))
444+
}
445+
}
416446
}

0 commit comments

Comments
 (0)