fix: allow reserved keywords on variables names #6572
Merged
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.
Description
Issue: The
DEFINE/UNDEFINE
statements do not allow variables names that matches the symbolic names found inSqlBase.g4
. For instancedefine topic = 't1';
fails becausetopic
is a reserved keyword. However, these should not be a problem for variables names. We should allow any variable name.The
SqlBase.g4
has a rule fornonReservedKeyword
which I used initially, but this is not scalable. There are several missing keywords in that rule, and not all statements allow the same keywords as non-reserved. To scale this rule, I added an extra validation to the parser error listener to check if a syntax error is caused by a keyword being used as variable name. If so, then it returns silently without throwing any error, thus allowing thedefine
andundefine
statements to continue.i.e.
This fix allowed me to removed the undesired keywords from the error message.
The validator is on
SyntaxErrorValidator
, which is used as an error listener for the parsers. I just copied thesyntaxError
implementation fromDefaultKsqlParser
to this class. We can add more validators in the future if we find another error that should be valid and is difficult to add as rule inSqlBase.g4
. We can also add validators to format the error messages for a better user experience.Testing done
Added unit tests
Verified manually
Reviewer checklist