Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix syntax error when delimited column alias is used without preceding whitespace #2512

Conversation

Anikait143
Copy link
Contributor

Description

1. Issue

When the alias is directly adjacent to a keyword (like END) or a non-delimited column name, the error message mentions AS, even though there is no AS keyword in the query.

2. Changes made to fix the issue

  • This bug is caused by ANTLR rewriting, we have added an extra space before 'AS' keyword when rewriting the query which which doesn't explicitly has 'AS' keyword before alias.
# Input
SELECT CASE WHEN 1=1  THEN 1 ELSE 0 END[c]
# previous output (wrong output)               
Msg 33557097, Level 16, State 1, Server persist-rcv-07mar-16-2-0-9, Line 1
syntax error at or near "ENDAS"
# current output (correct output)
~~START~~
int
1
~~END~~
# previous output (wrong output)
SELECT 1c;

Msg 33557097, Level 16, State 1, Server persist-rcv-07mar-16-2-0-9, Line 1
trailing junk after numeric literal at or near "1A"
# current output (correct output)
SELECT 1c;

~~START~~
int
1
~~END~~
  • Added Test Cases for this issue

4_X PR: #2504

Task: BABEL-4863
Authored-by: Anikait Agrawal [email protected]
Signed-off-by: Anikait Agrawal [email protected]

Test Scenarios Covered

  • Use case based - BABEL-4863-vu-*

  • Boundary conditions -

  • Arbitrary inputs -

  • Negative test cases -

  • Minor version upgrade tests -

  • Major version upgrade tests -

  • Performance tests -

  • Tooling impact -

  • Memory tests -

  • Client tests -

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Anikait Agrawal added 4 commits April 18, 2024 09:02
Signed-off-by: Anikait Agrawal <[email protected]>
Signed-off-by: Anikait Agrawal <[email protected]>
@Anikait143 Anikait143 requested a review from robverschoor April 18, 2024 09:57
Copy link
Contributor

@jsudrik jsudrik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved based on the other reviews.

@jsudrik jsudrik merged commit 0efbb15 into babelfish-for-postgresql:BABEL_2_X_DEV Apr 18, 2024
29 checks passed
@Anikait143 Anikait143 deleted the JIRA-BABEL-4863-2x branch April 18, 2024 14:33
Anikait143 added a commit to amazon-aurora/babelfish_extensions that referenced this pull request Apr 18, 2024
…g whitespace (babelfish-for-postgresql#2512)

When the alias is directly adjacent to a keyword (like END) or a non-delimited column name, the error message mentions AS, even though there is no AS keyword in the query.

This bug is caused by ANTLR rewriting, we have added an extra space before 'AS' keyword when rewriting the query which which doesn't explicitly has 'AS' keyword before alias.

SELECT CASE WHEN 1=1  THEN 1 ELSE 0 END[c]

Msg 33557097, Level 16, State 1, Server persist-rcv-07mar-16-2-0-9, Line 1
syntax error at or near "ENDAS"

~~START~~
int
1
~~END~~

SELECT 1c;

Msg 33557097, Level 16, State 1, Server persist-rcv-07mar-16-2-0-9, Line 1
trailing junk after numeric literal at or near "1A"

SELECT 1c;

~~START~~
int
1
~~END~~

    Added Test Cases for this issue

4_X PR: babelfish-for-postgresql#2504

Task: BABEL-4863

Authored-by: Anikait Agrawal [email protected]
Signed-off-by: Anikait Agrawal <[email protected]>
Co-authored-by: Anikait Agrawal <[email protected]>
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.

4 participants