fix(parser): parse COMMENT ON ... IS NULL as comment removal (#2562) - #2563
Open
sundongkim-dev wants to merge 1 commit into
Open
fix(parser): parse COMMENT ON ... IS NULL as comment removal (#2562)#2563sundongkim-dev wants to merge 1 commit into
sundongkim-dev wants to merge 1 commit into
Conversation
…ser#2562) PostgreSQL removes a comment by writing NULL in place of the text string, but the Comment() production required a string literal after IS. Accept NULL as an alternative: the Comment's comment field stays null and toString() deparses it back as IS NULL.
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.
What
Parse
COMMENT ON TABLE/COLUMN/VIEW ... IS NULL, PostgreSQL's syntax for removing a comment. For such statementsComment.getComment()returnsnull, andComment.toString()deparses back toIS NULL.Why
Fixes #2562. Per the PostgreSQL
COMMENTdocs: "To remove a comment, write NULL in place of the text string." Today this throws aParseException, so DDL streams that drop comments cannot be processed.How
The
Comment()production required<S_CHAR_LITERAL>after<K_IS>; it is now a two-token choice<S_CHAR_LITERAL> | <K_NULL>(disjoint terminals, LL(1), no lookahead needed). ForNULLthecommentfield simply staysnull.Comment.toString()now printsNULLwhen no comment string is set. This is required for the deparse round-trip and also changesnew Comment().toString()fromCOMMENT ON IS null(string-concatenated Javanull) toCOMMENT ON IS NULL; the existingtestToStringexpectation is updated accordingly.Note for downstream consumers: a successfully parsed
Commentcould previously never havegetComment() == null; after this change it can (exactly forIS NULLstatements). All in-repo visitors (deparser,TablesNamesFinder, validators, feature visitor) are already null-safe here.Testing
CommentTest:TABLE/COLUMN/VIEWIS NULLparse + deparse round-trip, plus a lowercaseis nullsample../gradlew testpasses.spotlessJavaCheckreports 2 violations in files not touched by this PR (BytecodeSizeTest.java,CCJSqlParserTest.java), reproduced identically on pristine master.IS $$...$$) andCOMMENT ONobject types other than TABLE/COLUMN/VIEW still don't parse;IS NULLsupport is complete for the object types the grammar supports.