Skip to content

Commit a6db8a3

Browse files
committed
address comments.
1 parent e116018 commit a6db8a3

File tree

6 files changed

+85
-65
lines changed

6 files changed

+85
-65
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/interface.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,8 @@ case class CatalogTable(
295295
val tableProperties = properties.map(p => p._1 + "=" + p._2).mkString("[", ", ", "]")
296296
val partitionColumns = partitionColumnNames.map(quoteIdentifier).mkString("[", ", ", "]")
297297

298-
map.put("Table", identifier.quotedString)
298+
identifier.database.foreach(map.put("Database", _))
299+
map.put("Table", identifier.table)
299300
if (owner.nonEmpty) map.put("Owner", owner)
300301
map.put("Created", new Date(createTime).toString)
301302
map.put("Last Access", new Date(lastAccessTime).toString)

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ case class DescribeTableCommand(
536536
describePartitionInfo(metadata, result)
537537

538538
if (partitionSpec.nonEmpty) {
539+
// Outputs the partition-specific info for the DDL command:
540+
// "DESCRIBE [EXTENDED|FORMATTED] table_name PARTITION (partitionVal*)"
539541
describeDetailedPartitionInfo(sparkSession, catalog, metadata, result)
540542
} else if (isExtended) {
541543
describeFormattedTableInfo(metadata, result)
@@ -548,15 +550,21 @@ case class DescribeTableCommand(
548550
private def describePartitionInfo(table: CatalogTable, buffer: ArrayBuffer[Row]): Unit = {
549551
if (table.partitionColumnNames.nonEmpty) {
550552
append(buffer, "# Partition Information", "", "")
551-
append(buffer, s"# ${output.head.name}", output(1).name, output(2).name)
552553
describeSchema(table.partitionSchema, buffer)
553554
}
554555
}
555556

556557
private def describeFormattedTableInfo(table: CatalogTable, buffer: ArrayBuffer[Row]): Unit = {
558+
// The following information has been already shown in the previous outputs
559+
val excludedTableInfo = Seq(
560+
"Partition Columns",
561+
"Schema"
562+
)
557563
append(buffer, "", "", "")
558564
append(buffer, "# Detailed Table Information", "", "")
559-
table.toLinkedHashMap.foreach(s => append(buffer, s._1, s._2, ""))
565+
table.toLinkedHashMap.filterKeys(!excludedTableInfo.contains(_)).foreach {
566+
s => append(buffer, s._1, s._2, "")
567+
}
560568
}
561569

562570
private def describeDetailedPartitionInfo(
@@ -594,6 +602,7 @@ case class DescribeTableCommand(
594602
}
595603

596604
private def describeSchema(schema: StructType, buffer: ArrayBuffer[Row]): Unit = {
605+
append(buffer, s"# ${output.head.name}", output(1).name, output(2).name)
597606
schema.foreach { column =>
598607
append(buffer, column.name, column.dataType.simpleString, column.getComment().orNull)
599608
}

sql/core/src/test/resources/sql-tests/results/change-column.sql.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ DESC test_change
1515
-- !query 1 schema
1616
struct<col_name:string,data_type:string,comment:string>
1717
-- !query 1 output
18+
# col_name data_type comment
1819
a int
1920
b string
2021
c int
@@ -34,6 +35,7 @@ DESC test_change
3435
-- !query 3 schema
3536
struct<col_name:string,data_type:string,comment:string>
3637
-- !query 3 output
38+
# col_name data_type comment
3739
a int
3840
b string
3941
c int
@@ -53,6 +55,7 @@ DESC test_change
5355
-- !query 5 schema
5456
struct<col_name:string,data_type:string,comment:string>
5557
-- !query 5 output
58+
# col_name data_type comment
5659
a int
5760
b string
5861
c int
@@ -91,6 +94,7 @@ DESC test_change
9194
-- !query 8 schema
9295
struct<col_name:string,data_type:string,comment:string>
9396
-- !query 8 output
97+
# col_name data_type comment
9498
a int
9599
b string
96100
c int
@@ -125,6 +129,7 @@ DESC test_change
125129
-- !query 12 schema
126130
struct<col_name:string,data_type:string,comment:string>
127131
-- !query 12 output
132+
# col_name data_type comment
128133
a int this is column a
129134
b string #*02?`
130135
c int
@@ -143,6 +148,7 @@ DESC test_change
143148
-- !query 14 schema
144149
struct<col_name:string,data_type:string,comment:string>
145150
-- !query 14 output
151+
# col_name data_type comment
146152
a int this is column a
147153
b string #*02?`
148154
c int
@@ -162,6 +168,7 @@ DESC test_change
162168
-- !query 16 schema
163169
struct<col_name:string,data_type:string,comment:string>
164170
-- !query 16 output
171+
# col_name data_type comment
165172
a int this is column a
166173
b string #*02?`
167174
c int
@@ -186,6 +193,7 @@ DESC test_change
186193
-- !query 18 schema
187194
struct<col_name:string,data_type:string,comment:string>
188195
-- !query 18 output
196+
# col_name data_type comment
189197
a int this is column a
190198
b string #*02?`
191199
c int
@@ -229,6 +237,7 @@ DESC test_change
229237
-- !query 23 schema
230238
struct<col_name:string,data_type:string,comment:string>
231239
-- !query 23 output
240+
# col_name data_type comment
232241
a int this is column A
233242
b string #*02?`
234243
c int

sql/core/src/test/resources/sql-tests/results/describe.sql.out

Lines changed: 42 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ DESCRIBE t
4141
-- !query 4 schema
4242
struct<col_name:string,data_type:string,comment:string>
4343
-- !query 4 output
44+
# col_name data_type comment
4445
a string
4546
b int
4647
c string
@@ -56,6 +57,7 @@ DESC t
5657
-- !query 5 schema
5758
struct<col_name:string,data_type:string,comment:string>
5859
-- !query 5 output
60+
# col_name data_type comment
5961
a string
6062
b int
6163
c string
@@ -71,6 +73,7 @@ DESC TABLE t
7173
-- !query 6 schema
7274
struct<col_name:string,data_type:string,comment:string>
7375
-- !query 6 output
76+
# col_name data_type comment
7477
a string
7578
b int
7679
c string
@@ -86,6 +89,7 @@ DESC FORMATTED t
8689
-- !query 7 schema
8790
struct<col_name:string,data_type:string,comment:string>
8891
-- !query 7 output
92+
# col_name data_type comment
8993
a string
9094
b int
9195
c string
@@ -96,30 +100,26 @@ c string
96100
d string
97101

98102
# Detailed Table Information
99-
Table `default`.`t`
100-
Created[removed by SQLQueryTestSuite]
101-
Last Access[removed by SQLQueryTestSuite]
103+
Database default
104+
Table t
105+
Created [not included in comparison]
106+
Last Access [not included in comparison]
102107
Type MANAGED
103108
Provider parquet
104109
Num Buckets 2
105110
Bucket Columns [`a`]
106111
Sort Columns [`b`]
107112
Comment table_comment
108-
Location[removed by SQLQueryTestSuite]sql/core/spark-warehouse/t
109-
Partition Provider Catalog
110-
Partition Columns [`c`, `d`]
111-
Schema root
112-
|-- a: string (nullable = true)
113-
|-- b: integer (nullable = true)
114-
|-- c: string (nullable = true)
115-
|-- d: string (nullable = true)
113+
Location [not included in comparison]sql/core/spark-warehouse/t
114+
Partition Provider Catalog
116115

117116

118117
-- !query 8
119118
DESC EXTENDED t
120119
-- !query 8 schema
121120
struct<col_name:string,data_type:string,comment:string>
122121
-- !query 8 output
122+
# col_name data_type comment
123123
a string
124124
b int
125125
c string
@@ -130,30 +130,26 @@ c string
130130
d string
131131

132132
# Detailed Table Information
133-
Table `default`.`t`
134-
Created[removed by SQLQueryTestSuite]
135-
Last Access[removed by SQLQueryTestSuite]
133+
Database default
134+
Table t
135+
Created [not included in comparison]
136+
Last Access [not included in comparison]
136137
Type MANAGED
137138
Provider parquet
138139
Num Buckets 2
139140
Bucket Columns [`a`]
140141
Sort Columns [`b`]
141142
Comment table_comment
142-
Location[removed by SQLQueryTestSuite]sql/core/spark-warehouse/t
143-
Partition Provider Catalog
144-
Partition Columns [`c`, `d`]
145-
Schema root
146-
|-- a: string (nullable = true)
147-
|-- b: integer (nullable = true)
148-
|-- c: string (nullable = true)
149-
|-- d: string (nullable = true)
143+
Location [not included in comparison]sql/core/spark-warehouse/t
144+
Partition Provider Catalog
150145

151146

152147
-- !query 9
153148
DESC t PARTITION (c='Us', d=1)
154149
-- !query 9 schema
155150
struct<col_name:string,data_type:string,comment:string>
156151
-- !query 9 output
152+
# col_name data_type comment
157153
a string
158154
b int
159155
c string
@@ -169,6 +165,7 @@ DESC EXTENDED t PARTITION (c='Us', d=1)
169165
-- !query 10 schema
170166
struct<col_name:string,data_type:string,comment:string>
171167
-- !query 10 output
168+
# col_name data_type comment
172169
a string
173170
b int
174171
c string
@@ -182,20 +179,21 @@ d string
182179
Database default
183180
Table t
184181
Partition Values [c=Us, d=1]
185-
Location[removed by SQLQueryTestSuite]sql/core/spark-warehouse/t/c=Us/d=1
182+
Location [not included in comparison]sql/core/spark-warehouse/t/c=Us/d=1
186183

187184
# Table Storage Information
188185
Num Buckets 2
189186
Bucket Columns [`a`]
190187
Sort Columns [`b`]
191-
Location[removed by SQLQueryTestSuite]sql/core/spark-warehouse/t
188+
Location [not included in comparison]sql/core/spark-warehouse/t
192189

193190

194191
-- !query 11
195192
DESC FORMATTED t PARTITION (c='Us', d=1)
196193
-- !query 11 schema
197194
struct<col_name:string,data_type:string,comment:string>
198195
-- !query 11 output
196+
# col_name data_type comment
199197
a string
200198
b int
201199
c string
@@ -209,13 +207,13 @@ d string
209207
Database default
210208
Table t
211209
Partition Values [c=Us, d=1]
212-
Location[removed by SQLQueryTestSuite]sql/core/spark-warehouse/t/c=Us/d=1
210+
Location [not included in comparison]sql/core/spark-warehouse/t/c=Us/d=1
213211

214212
# Table Storage Information
215213
Num Buckets 2
216214
Bucket Columns [`a`]
217215
Sort Columns [`b`]
218-
Location[removed by SQLQueryTestSuite]sql/core/spark-warehouse/t
216+
Location [not included in comparison]sql/core/spark-warehouse/t
219217

220218

221219
-- !query 12
@@ -257,6 +255,7 @@ DESC temp_v
257255
-- !query 15 schema
258256
struct<col_name:string,data_type:string,comment:string>
259257
-- !query 15 output
258+
# col_name data_type comment
260259
a string
261260
b int
262261
c string
@@ -268,6 +267,7 @@ DESC TABLE temp_v
268267
-- !query 16 schema
269268
struct<col_name:string,data_type:string,comment:string>
270269
-- !query 16 output
270+
# col_name data_type comment
271271
a string
272272
b int
273273
c string
@@ -279,6 +279,7 @@ DESC FORMATTED temp_v
279279
-- !query 17 schema
280280
struct<col_name:string,data_type:string,comment:string>
281281
-- !query 17 output
282+
# col_name data_type comment
282283
a string
283284
b int
284285
c string
@@ -290,6 +291,7 @@ DESC EXTENDED temp_v
290291
-- !query 18 schema
291292
struct<col_name:string,data_type:string,comment:string>
292293
-- !query 18 output
294+
# col_name data_type comment
293295
a string
294296
b int
295297
c string
@@ -310,6 +312,7 @@ DESC v
310312
-- !query 20 schema
311313
struct<col_name:string,data_type:string,comment:string>
312314
-- !query 20 output
315+
# col_name data_type comment
313316
a string
314317
b int
315318
c string
@@ -321,6 +324,7 @@ DESC TABLE v
321324
-- !query 21 schema
322325
struct<col_name:string,data_type:string,comment:string>
323326
-- !query 21 output
327+
# col_name data_type comment
324328
a string
325329
b int
326330
c string
@@ -332,51 +336,45 @@ DESC FORMATTED v
332336
-- !query 22 schema
333337
struct<col_name:string,data_type:string,comment:string>
334338
-- !query 22 output
339+
# col_name data_type comment
335340
a string
336341
b int
337342
c string
338343
d string
339344

340345
# Detailed Table Information
341-
Table `default`.`v`
342-
Created[removed by SQLQueryTestSuite]
343-
Last Access[removed by SQLQueryTestSuite]
346+
Database default
347+
Table v
348+
Created [not included in comparison]
349+
Last Access [not included in comparison]
344350
Type VIEW
345351
View Text SELECT * FROM t
346352
View Default Database default
347353
View Query Output Columns [a, b, c, d]
348-
Properties [view.query.out.col.3=d, view.query.out.col.0=a, view.query.out.numCols=4, view.default.database=default, view.query.out.col.1=b, view.query.out.col.2=c]
349-
Schema root
350-
|-- a: string (nullable = true)
351-
|-- b: integer (nullable = true)
352-
|-- c: string (nullable = true)
353-
|-- d: string (nullable = true)
354+
Properties [view.query.out.col.3=d, view.query.out.col.0=a, view.query.out.numCols=4, view.default.database=default, view.query.out.col.1=b, view.query.out.col.2=c]
354355

355356

356357
-- !query 23
357358
DESC EXTENDED v
358359
-- !query 23 schema
359360
struct<col_name:string,data_type:string,comment:string>
360361
-- !query 23 output
362+
# col_name data_type comment
361363
a string
362364
b int
363365
c string
364366
d string
365367

366368
# Detailed Table Information
367-
Table `default`.`v`
368-
Created[removed by SQLQueryTestSuite]
369-
Last Access[removed by SQLQueryTestSuite]
369+
Database default
370+
Table v
371+
Created [not included in comparison]
372+
Last Access [not included in comparison]
370373
Type VIEW
371374
View Text SELECT * FROM t
372375
View Default Database default
373376
View Query Output Columns [a, b, c, d]
374-
Properties [view.query.out.col.3=d, view.query.out.col.0=a, view.query.out.numCols=4, view.default.database=default, view.query.out.col.1=b, view.query.out.col.2=c]
375-
Schema root
376-
|-- a: string (nullable = true)
377-
|-- b: integer (nullable = true)
378-
|-- c: string (nullable = true)
379-
|-- d: string (nullable = true)
377+
Properties [view.query.out.col.3=d, view.query.out.col.0=a, view.query.out.numCols=4, view.default.database=default, view.query.out.col.1=b, view.query.out.col.2=c]
380378

381379

382380
-- !query 24

0 commit comments

Comments
 (0)