fix: SQLDeleteStatement.accept0 missing from/using children (#6563)#6642
Open
daguimu wants to merge 1 commit into
Open
fix: SQLDeleteStatement.accept0 missing from/using children (#6563)#6642daguimu wants to merge 1 commit into
daguimu wants to merge 1 commit into
Conversation
…6563) The base SQLDeleteStatement.accept0 walked only with/tableSource/where, silently skipping the from and using sub-trees. Dialects that fall back to the base implementation (DB2, Snowflake, etc.) therefore could not be fully traversed by visitors that rely on the default tree walk - any identifier reachable only through `DELETE ... FROM <ts>` or `DELETE ... USING <ts>` was invisible to AST consumers. `getChildren()` had the same omission, and `setUsing` did not wire the parent pointer (`setFrom` already did), breaking parent-chain traversal for that branch. This commit walks `from` and `using` in accept0, includes them in getChildren, and sets the parent in setUsing - matching the behaviour already present in MySqlDeleteStatement.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The base
SQLDeleteStatement.accept0walked onlywith/tableSource/where, silently skipping thefromandusingsub-trees. As a result, dialects that fall back to the base implementation (DB2, Snowflake, etc.) cannot be fully traversed by visitors that rely on the default tree walk - any AST node reachable only viaDELETE ... FROM <ts>orDELETE ... USING <ts>was invisible to AST consumers.getChildren()had the same omission, andsetUsing()failed to wire the parent pointer (setFromalready does), breaking parent-chain traversal for that branch.Reported in #6563 (DELETE statement visitor cannot reach the FROM sub-tree when modifying table names).
Root Cause
Compare with
MySqlDeleteStatement.accept0, which correctly walkswith,tableSource,where,from,using,orderBy,limit. The base class - used directly by Snowflake, DB2 and any future dialect that does not override - was missingfromandusing. Snowflake and PG/Oscar parsers populate theusingslot viasetUsing(), but no parent was assigned, so even reverse-traversal would not work.Fix
In
SQLDeleteStatement:accept0: walkfromandusingin addition to the previously-visited children.getChildren: includefromandusing.setUsing: wire the parent pointer, mirroringsetFrom.No changes to dialect-specific subclasses - they already override
accept0and were unaffected.Tests Added
core/src/test/java/com/alibaba/druid/sql/issues/Issue6563.java:test_snowflake_delete_using_visited- parsesDELETE FROM t1 USING t_using_only WHERE ..., walks the AST with a generic identifier collector, and assertst_using_only(referenced ONLY through the USING clause) is reached.test_db2_delete_from_visited- parsesDELETE FROM t FROM t_from_only WHERE ...for DB2, assertst_from_only(reachable only through the secondary FROM) is visited.test_getChildren_includes_from_and_using- structural test on the AST API.test_setUsing_sets_parent- verifies the parent pointer is wired so reverse traversal works.All four tests fail on master (4 failures, no errors) and pass with the fix.
Full
mvn testfor thecoremodule: 4222 tests, 0 failures, 0 errors.Fixes #6563