cloud-fan commented on code in PR #55441:
URL: https://github.com/apache/spark/pull/55441#discussion_r3440165703
##########
sql/core/src/main/scala/org/apache/spark/sql/execution/SparkSqlParser.scala:
##########
@@ -1480,6 +1480,33 @@ class SparkSqlAstBuilder extends AstBuilder {
}
}
+ /**
+ * A command for users to list the partition names of a table. If partition
spec is specified,
+ * only partitions that match the spec are returned. Otherwise all
partitions are returned.
+ *
+ * Without `AS JSON`, this creates a [[ShowPartitions]] logical plan (one
row per partition).
+ * With `AS JSON`, this creates a [[ShowPartitionsJsonCommand]] that returns
a single JSON
+ * document.
+ *
+ * The syntax of using this command in SQL is:
+ * {{{
+ * SHOW PARTITIONS multi_part_name [partition_spec] [AS JSON];
+ * }}}
+ */
+ override def visitShowPartitions(ctx: ShowPartitionsContext): LogicalPlan =
withOrigin(ctx) {
Review Comment:
Nice — restoring `AstBuilder.visitShowPartitions` and reverting the
`ShowPartitionsParserSuite` / `AnalysisExceptionPositionSuite` changes
addresses the bulk of the earlier note. One piece remains for full consistency
with `visitShowTables`: this override still rebuilds the non-JSON plan inline
(`ShowPartitions(relation, partitionKeys)` below), duplicating the now-restored
base impl. `visitShowTables` instead delegates the non-JSON case to `super` and
handles only the JSON branch:
```scala
override def visitShowPartitions(ctx: ShowPartitionsContext): LogicalPlan =
withOrigin(ctx) {
if (ctx.JSON == null) return super.visitShowPartitions(ctx)
val relation = createUnresolvedTable(ctx.identifierReference, "SHOW
PARTITIONS AS JSON")
val partitionKeys = Option(ctx.partitionSpec).map { specCtx =>
UnresolvedPartitionSpec(visitNonOptionalPartitionSpec(specCtx), None)
}
ShowPartitionsJsonCommand(relation, partitionKeys.map(_.spec))
}
```
That keeps a single source for the non-JSON plan (no drift between the
`CatalystSqlParser` and `SparkSqlParser` paths). Still non-blocking/optional.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]