Validate parsed SQL statements against Calcite's SqlKind.QUERY set
before planning, rejecting DML (INSERT, DELETE, UPDATE, MERGE) and DDL
statements. This brings the unified path in line with the legacy
grammar's parser-level restriction to read-only queries.
Whitelist: SqlKind.QUERY (SELECT, UNION, INTERSECT, EXCEPT, VALUES,
WITH, ORDER_BY, EXPLICIT_TABLE).
Note: EXPLAIN is also blocked because Calcite's SqlToRelConverter does
not handle SqlExplain in convertQueryRecursive. Supporting EXPLAIN
requires unwrapping the inner query and formatting the plan separately.
Signed-off-by: Chen Dai <daichen@amazon.com>
Description
The unified SQL path uses Calcite's
SqlParser.parseQuery()which, despite its name, accepts any SQL statement type including DML and DDL. The SQL V2 grammar restricts input toSELECT/SHOW/DESCRIBEat the parser level, but the unified path had no equivalent protection.Changes
Validate the parsed
SqlNodeagainstSqlKind.QUERYinCalciteNativeStrategy.plan()before proceeding to planning. Non-query statements are rejected withUnsupportedOperationException./_explainpathRelated Issues
Part of #5248
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.