Skip to content

Preserve quotedness in QualifiedName#19752

Closed
imjalpreet wants to merge 1 commit into
prestodb:masterfrom
imjalpreet:preserveQuotedness
Closed

Preserve quotedness in QualifiedName#19752
imjalpreet wants to merge 1 commit into
prestodb:masterfrom
imjalpreet:preserveQuotedness

Conversation

@imjalpreet

Copy link
Copy Markdown
Member

Presto doesn't maintain the quotedness of an identifier when using SqlQueryFormatter so it results in throwing parsing error if quoted table name is a reserved word

Test plan

Before this PR, presto throws an error when using a reserved keyword in a prepared statement or while creating a view.

presto:imjalpreet> create view group_view security invoker as select * from imjalpreet."group";

Query 20230530_141710_00001_fxwah failed: Formatted query does not parse: Query{queryBody=QuerySpecification{select=Select{distinct=false, selectItems=[*]}, from=Optional[Table{imjalpreet.group}], where=null, groupBy=Optional.empty, having=null, orderBy=Optional.empty, offset=null, limit=null}, orderBy=Optional.empty}

presto:imjalpreet> PREPARE stmt0 FROM select * from imjalpreet."group";

Query 20230530_142117_00003_fxwah failed: Formatted query does not parse: Query{queryBody=QuerySpecification{select=Select{distinct=false, selectItems=[*]}, from=Optional[Table{imjalpreet.group}], where=null, groupBy=Optional.empty, having=null, orderBy=Optional.empty, offset=null, limit=null}, orderBy=Optional.empty}

After this PR, queries runs successfully.

presto:imjalpreet> create view group_view security invoker as select * from imjalpreet."group";
CREATE VIEW

presto:imjalpreet> PREPARE stmt0 FROM select * from imjalpreet."group";
PREPARE
== RELEASE NOTES ==

General Changes
* Preserve table name quoting in the output of ``SHOW CREATE VIEW``.
* Fix failure when preparing statements or creating views that contain a quoted reserved word as a table name.

@imjalpreet imjalpreet requested a review from a team as a code owner May 30, 2023 21:27
@agrawalreetika

Copy link
Copy Markdown
Member

Thank you for the PR @imjalpreet
Can we add tests for show create view and prepare for the fix-related scenarios

@imjalpreet imjalpreet force-pushed the preserveQuotedness branch from f417a31 to 2300eb2 Compare June 8, 2023 14:55
Cherry-pick of trinodb/trino#80

Presto doesn't maintain the quotedness of an identifier when
using SqlQueryFormatter so it results in throwing parsing error
if quoted table name is a reserved word
Co-authored-by: praveenkrishna <praveenkrishna@tutanota.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants