ayushbilala opened a new pull request, #59235:
URL: https://github.com/apache/spark/pull/59235

   ### What changes were proposed in this pull request?
   Support SHOW VIEWS ... [AS JSON] to optionally return the view listing as a 
single-row JSON document.
   
   The AS JSON variant is built directly by SparkSqlAstBuilder as a runnable 
ShowViewsJsonCommand, following SHOW TABLES AS JSON and SHOW PARTITIONS AS 
JSON. Both the session catalog and v2 ViewCatalog catalogs are supported, 
matching the coverage of the tabular output.
   
   SQL syntax:
   `SHOW VIEWS [(IN|FROM) database_name] [LIKE pattern] [AS JSON]`
   
   Output: json_metadata: String
   SHOW VIEWS AS JSON: 
`{"views":[{"namespace":["db"],"viewName":"v1","isTemporary":false}]}`
   
   
   ### Why are the changes needed?
   The existing text-based output of SHOW VIEWS requires fragile string parsing 
for programmatic consumption. A structured JSON format provides a stable, 
machine-readable contract for tooling and automation.
   
   Unlike SHOW TABLES and SHOW PARTITIONS, SHOW VIEWS already has a real v2 
ViewCatalog execution path on master. AS JSON needed to cover both the session 
catalog and ViewCatalog-backed catalogs from the start, otherwise it would be a 
capability regression relative to the existing tabular command.
   
   
   ### Does this PR introduce _any_ user-facing change?
   Yes. One new SQL syntax variant that returns JSON output. The existing SHOW 
VIEWS without AS JSON is unaffected.
   
   
   ### How was this patch tested?
   
   - Parser tests in `ShowViewsParserSuite` for all AS JSON variants (no 
namespace, IN, FROM, LIKE pattern, multi-part catalog namespace).
   - Execution tests in `ShowViewsSuiteBase` (shared v1 + v2) covering JSON 
schema validation, LIKE filtering, non-view exclusion, duplicate safety, empty 
results, and JSON/tabular parity.
   - v1-only tests for local and global temp views (including JSON/tabular 
parity), resolving the current namespace without IN/FROM, and error parity with 
the tabular command for a nested namespace and a missing namespace.
   - v2-only tests for the ViewCatalog execution path and rejection on a 
non-ViewCatalog catalog, for both the plain and AS JSON forms.
   - Manual verification in spark-shell
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   No
   


-- 
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]

Reply via email to