Skip to content

Commit 37db4a7

Browse files
wangyumGitHub Enterprise
authored andcommitted
[CARMEL-7530][CARMEL-4232] Support list all tables AND their size in a specific HDM (apache#299)
1 parent 9e4f499 commit 37db4a7

18 files changed

Lines changed: 729 additions & 91 deletions

File tree

sql/api/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBaseParser.g4

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ statement
8989
SET locationSpec #setNamespaceLocation
9090
| DROP namespace (IF EXISTS)? identifierReference
9191
(RESTRICT | CASCADE)? #dropNamespace
92-
| SHOW namespaces ((FROM | IN) multipartIdentifier)?
93-
(LIKE? pattern=stringLit)? #showNamespaces
92+
| informationQuery #infoQuery
9493
| createTableHeader (LEFT_PAREN createOrReplaceTableColTypeList RIGHT_PAREN)? tableProvider?
9594
createTableClauses
9695
(AS? query)? #createTable
@@ -171,19 +170,6 @@ statement
171170
| DROP TEMPORARY? FUNCTION (IF EXISTS)? identifierReference #dropFunction
172171
| EXPLAIN (LOGICAL | FORMATTED | EXTENDED | CODEGEN | COST | OPTIMIZE)?
173172
statement #explain
174-
| SHOW TABLES ((FROM | IN) identifierReference)?
175-
(LIKE? pattern=stringLit)? #showTables
176-
| SHOW TABLE EXTENDED ((FROM | IN) ns=identifierReference)?
177-
LIKE pattern=stringLit partitionSpec? #showTableExtended
178-
| SHOW TBLPROPERTIES table=identifierReference
179-
(LEFT_PAREN key=propertyKey RIGHT_PAREN)? #showTblProperties
180-
| SHOW COLUMNS (FROM | IN) table=identifierReference
181-
((FROM | IN) ns=multipartIdentifier)? #showColumns
182-
| SHOW VIEWS ((FROM | IN) identifierReference)?
183-
(LIKE? pattern=stringLit)? #showViews
184-
| SHOW PARTITIONS identifierReference partitionSpec? #showPartitions
185-
| SHOW identifier? FUNCTIONS ((FROM | IN) ns=identifierReference)?
186-
(LIKE? (legacy=multipartIdentifier | pattern=stringLit))? #showFunctions
187173
| SHOW CREATE TABLE identifierReference (AS SERDE)? #showCreateTable
188174
| SHOW CURRENT namespace #showCurrentNamespace
189175
| SHOW CATALOGS (LIKE? pattern=stringLit)? #showCatalogs
@@ -444,8 +430,26 @@ ctes
444430
: WITH RECURSIVE? namedQuery (COMMA namedQuery)*
445431
;
446432

433+
informationQuery
434+
: SHOW namespaces ((FROM | IN) multipartIdentifier)?
435+
(LIKE? pattern=stringLit)? #showNamespaces
436+
| SHOW TABLES ((FROM | IN) identifierReference)?
437+
(LIKE? pattern=stringLit)? #showTables
438+
| SHOW TABLE EXTENDED ((FROM | IN) ns=identifierReference)?
439+
LIKE pattern=stringLit partitionSpec? #showTableExtended
440+
| SHOW TBLPROPERTIES table=identifierReference
441+
(LEFT_PAREN key=propertyKey RIGHT_PAREN)? #showTblProperties
442+
| SHOW COLUMNS (FROM | IN) table=identifierReference
443+
((FROM | IN) ns=multipartIdentifier)? #showColumns
444+
| SHOW VIEWS ((FROM | IN) identifierReference)?
445+
(LIKE? pattern=stringLit)? #showViews
446+
| SHOW PARTITIONS identifierReference partitionSpec? #showPartitions
447+
| SHOW identifier? FUNCTIONS ((FROM | IN) ns=identifierReference)?
448+
(LIKE? (legacy=multipartIdentifier | pattern=stringLit))? #showFunctions
449+
;
450+
447451
namedQuery
448-
: name=errorCapturingIdentifier (columnAliases=identifierList)? AS? LEFT_PAREN query RIGHT_PAREN
452+
: name=errorCapturingIdentifier (columnAliases=identifierList)? AS? LEFT_PAREN (query | informationQuery) RIGHT_PAREN
449453
;
450454

451455
tableProvider

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/parser/AstBuilder.scala

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,28 @@ class AstBuilder extends DataTypeAstBuilder with SQLConfHelper with Logging {
240240
* This is only used for Common Table Expressions.
241241
*/
242242
override def visitNamedQuery(ctx: NamedQueryContext): SubqueryAlias = withOrigin(ctx) {
243-
val subQuery: LogicalPlan = plan(ctx.query).optionalMap(ctx.columnAliases)(
243+
val logicalPlan = Option(ctx.query).map(plan).orElse(
244+
Option(ctx.informationQuery).map(plan)).get
245+
val subQuery: LogicalPlan = logicalPlan.optionalMap(ctx.columnAliases)(
244246
(columnAliases, plan) =>
245247
UnresolvedSubqueryColumnAliases(visitIdentifierList(columnAliases), plan)
246248
)
247249
SubqueryAlias(ctx.name.getText, subQuery)
248250
}
249251

252+
override def visitInfoQuery(ctx: InfoQueryContext): LogicalPlan = withOrigin(ctx) {
253+
ctx.informationQuery match {
254+
case namespaces: ShowNamespacesContext => visitShowNamespaces(namespaces)
255+
case tables: ShowTablesContext => visitShowTables(tables)
256+
case tableExtended: ShowTableExtendedContext => visitShowTableExtended(tableExtended)
257+
case tblProperties: ShowTblPropertiesContext => visitShowTblProperties(tblProperties)
258+
case columns: ShowColumnsContext => visitShowColumns(columns)
259+
case views: ShowViewsContext => visitShowViews(views)
260+
case partitions: ShowPartitionsContext => visitShowPartitions(partitions)
261+
case functions: ShowFunctionsContext => visitShowFunctions(functions)
262+
}
263+
}
264+
250265
/**
251266
* Create a logical plan which allows for multiple inserts using one 'from' statement. These
252267
* queries have the following SQL form:

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/v2Commands.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ object ShowTableExtended {
903903
AttributeReference("namespace", StringType, nullable = false)(),
904904
AttributeReference("tableName", StringType, nullable = false)(),
905905
AttributeReference("isTemporary", BooleanType, nullable = false)(),
906-
AttributeReference("information", StringType, nullable = false)())
906+
AttributeReference("information", MapType(StringType, StringType), nullable = false)())
907907
}
908908

909909
/**

sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/parser/ParserUtilsSuite.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ class ParserUtilsSuite extends SparkFunSuite {
3333
}
3434

3535
val showFuncContext = buildContext("show functions foo.bar") { parser =>
36-
parser.statement().asInstanceOf[ShowFunctionsContext]
36+
parser.statement().getChild(0).asInstanceOf[ShowFunctionsContext]
3737
}
3838

3939
val descFuncContext = buildContext("describe function extended bar") { parser =>
4040
parser.statement().asInstanceOf[DescribeFunctionContext]
4141
}
4242

4343
val showDbsContext = buildContext("show databases like 'identifier_with_wildcards'") { parser =>
44-
parser.statement().asInstanceOf[ShowNamespacesContext]
44+
parser.statement().getChild(0).asInstanceOf[ShowNamespacesContext]
4545
}
4646

4747
val createDbContext = buildContext(

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,8 +1199,8 @@ case class ShowTablesCommand(
11991199
val tableName = tableIdent.table
12001200
val isTemp = catalog.isTempView(tableIdent) || catalog.tempTableExists(tableIdent)
12011201
if (isExtended) {
1202-
val information = catalog.getTempViewOrPermanentTableMetadata(tableIdent).simpleString
1203-
Row(database, tableName, isTemp, s"$information\n")
1202+
val information = catalog.getTempViewOrPermanentTableMetadata(tableIdent)
1203+
Row(database, tableName, isTemp, information.toLinkedHashMap)
12041204
} else {
12051205
Row(database, tableName, isTemp)
12061206
}
@@ -1224,8 +1224,7 @@ case class ShowTablesCommand(
12241224
val database = tableIdent.database.getOrElse("")
12251225
val tableName = tableIdent.table
12261226
val isTemp = catalog.isTempView(tableIdent)
1227-
val information = partition.simpleString
1228-
Seq(Row(database, tableName, isTemp, s"$information\n"))
1227+
Seq(Row(database, tableName, isTemp, partition.toLinkedHashMap))
12291228
}
12301229
}
12311230
}

0 commit comments

Comments
 (0)