Skip to content

Commit 13f54e2

Browse files
tianyimarmbrus
authored andcommitted
[SPARK-2817] [SQL] add "show create table" support
In spark sql component, the "show create table" syntax had been disabled. We thought it is a useful funciton to describe a hive table. Author: tianyi <[email protected]> Author: tianyi <[email protected]> Author: tianyi <[email protected]> Closes #1760 from tianyi/spark-2817 and squashes the following commits: 7d28b15 [tianyi] [SPARK-2817] fix too short prefix problem cbffe8b [tianyi] [SPARK-2817] fix the case problem 565ec14 [tianyi] [SPARK-2817] fix the case problem 60d48a9 [tianyi] [SPARK-2817] use system temporary folder instead of temporary files in the source tree, and also clean some empty line dbe1031 [tianyi] [SPARK-2817] move some code out of function rewritePaths, as it may be called multiple times 9b2ba11 [tianyi] [SPARK-2817] fix the line length problem 9f97586 [tianyi] [SPARK-2817] remove test.tmp.dir from pom.xml bfc2999 [tianyi] [SPARK-2817] add "File.separator" support, create a "testTmpDir" outside the rewritePaths bde800a [tianyi] [SPARK-2817] add "${system:test.tmp.dir}" support add "last_modified_by" to nonDeterministicLineIndicators in HiveComparisonTest bb82726 [tianyi] [SPARK-2817] remove test which requires a system from the whitelist. bbf6b42 [tianyi] [SPARK-2817] add a systemProperties named "test.tmp.dir" to pass the test which contains "${system:test.tmp.dir}" a337bd6 [tianyi] [SPARK-2817] add "show create table" support a03db77 [tianyi] [SPARK-2817] add "show create table" support
1 parent bdc7a1a commit 13f54e2

File tree

37 files changed

+199
-0
lines changed

37 files changed

+199
-0
lines changed

sql/hive/compatibility/src/test/scala/org/apache/spark/sql/hive/execution/HiveCompatibilitySuite.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,14 @@ class HiveCompatibilitySuite extends HiveQueryFileTest with BeforeAndAfter {
635635
"serde_regex",
636636
"serde_reported_schema",
637637
"set_variable_sub",
638+
"show_create_table_partitioned",
639+
"show_create_table_delimited",
640+
"show_create_table_alter",
641+
"show_create_table_view",
642+
"show_create_table_serde",
643+
"show_create_table_db_table",
644+
"show_create_table_does_not_exist",
645+
"show_create_table_index",
638646
"show_describe_func_quotes",
639647
"show_functions",
640648
"show_partitions",

sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ private[hive] object HiveQl {
5353
protected val nativeCommands = Seq(
5454
"TOK_DESCFUNCTION",
5555
"TOK_DESCDATABASE",
56+
"TOK_SHOW_CREATETABLE",
5657
"TOK_SHOW_TABLESTATUS",
5758
"TOK_SHOWDATABASES",
5859
"TOK_SHOWFUNCTIONS",

sql/hive/src/main/scala/org/apache/spark/sql/hive/TestHive.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
7070
setConf("hive.metastore.warehouse.dir", warehousePath)
7171
}
7272

73+
val testTempDir = File.createTempFile("testTempFiles", "spark.hive.tmp")
74+
testTempDir.delete()
75+
testTempDir.mkdir()
76+
77+
// For some hive test case which contain ${system:test.tmp.dir}
78+
System.setProperty("test.tmp.dir", testTempDir.getCanonicalPath)
79+
7380
configure() // Must be called before initializing the catalog below.
7481

7582
/** The location of the compiled hive distribution */
@@ -109,6 +116,7 @@ class TestHiveContext(sc: SparkContext) extends HiveContext(sc) {
109116
hiveFilesTemp.mkdir()
110117
hiveFilesTemp.deleteOnExit()
111118

119+
112120
val inRepoTests = if (System.getProperty("user.dir").endsWith("sql" + File.separator + "hive")) {
113121
new File("src" + File.separator + "test" + File.separator + "resources" + File.separator)
114122
} else {

sql/hive/src/test/resources/golden/show_create_table_alter-0-813886d6cf0875c62e89cd1d06b8b0b4

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CREATE EXTERNAL TABLE tmp_showcrt1(
2+
key smallint,
3+
value float)
4+
CLUSTERED BY (
5+
key)
6+
SORTED BY (
7+
value DESC)
8+
INTO 5 BUCKETS
9+
ROW FORMAT SERDE
10+
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
11+
STORED AS INPUTFORMAT
12+
'org.apache.hadoop.mapred.TextInputFormat'
13+
OUTPUTFORMAT
14+
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
15+
LOCATION
16+
'file:/tmp/sparkHiveWarehouse1280221975983654134/tmp_showcrt1'
17+
TBLPROPERTIES (
18+
'transient_lastDdlTime'='1407132100')

sql/hive/src/test/resources/golden/show_create_table_alter-10-259d978ed9543204c8b9c25b6e25b0de

Whitespace-only changes.

sql/hive/src/test/resources/golden/show_create_table_alter-2-928cc85c025440b731e5ee33e437e404

Whitespace-only changes.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
CREATE TABLE tmp_showcrt1(
2+
key smallint,
3+
value float)
4+
COMMENT 'temporary table'
5+
CLUSTERED BY (
6+
key)
7+
SORTED BY (
8+
value DESC)
9+
INTO 5 BUCKETS
10+
ROW FORMAT SERDE
11+
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
12+
STORED AS INPUTFORMAT
13+
'org.apache.hadoop.mapred.TextInputFormat'
14+
OUTPUTFORMAT
15+
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
16+
LOCATION
17+
'file:/tmp/sparkHiveWarehouse1280221975983654134/tmp_showcrt1'
18+
TBLPROPERTIES (
19+
'EXTERNAL'='FALSE',
20+
'last_modified_by'='tianyi',
21+
'last_modified_time'='1407132100',
22+
'transient_lastDdlTime'='1407132100')

sql/hive/src/test/resources/golden/show_create_table_alter-4-c2cb6a7d942d4dddd1aababccb1239f9

Whitespace-only changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
CREATE EXTERNAL TABLE tmp_showcrt1(
2+
key smallint,
3+
value float)
4+
COMMENT 'changed comment'
5+
CLUSTERED BY (
6+
key)
7+
SORTED BY (
8+
value DESC)
9+
INTO 5 BUCKETS
10+
ROW FORMAT SERDE
11+
'org.apache.hadoop.hive.serde2.lazy.LazySimpleSerDe'
12+
STORED AS INPUTFORMAT
13+
'org.apache.hadoop.mapred.TextInputFormat'
14+
OUTPUTFORMAT
15+
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
16+
LOCATION
17+
'file:/tmp/sparkHiveWarehouse1280221975983654134/tmp_showcrt1'
18+
TBLPROPERTIES (
19+
'last_modified_by'='tianyi',
20+
'last_modified_time'='1407132100',
21+
'transient_lastDdlTime'='1407132100')

0 commit comments

Comments
 (0)