-
Notifications
You must be signed in to change notification settings - Fork 16.3k
fix(sqlglot): use Athena dialect for awsathena parsing #36747
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
base: master
Are you sure you want to change the base?
fix(sqlglot): use Athena dialect for awsathena parsing #36747
Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Code Review Agent Run #0b9f57Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Nitpicks 🔍
|
| @@ -58,7 +58,7 @@ | |||
| SQLGLOT_DIALECTS = { | |||
| "base": Dialects.DIALECT, | |||
| "ascend": Dialects.HIVE, | |||
| "awsathena": Dialects.PRESTO, | |||
| "awsathena": Dialects.ATHENA, | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: Compatibility with older sqlglot versions: directly referencing Dialects.ATHENA may raise an AttributeError if the installed sqlglot version lacks the ATHENA dialect; use a safe fallback (e.g. PRESTO) via getattr to avoid runtime attribute errors and ensure parsing still proceeds. [possible bug]
Severity Level: Critical 🚨
| "awsathena": Dialects.ATHENA, | |
| "awsathena": getattr(Dialects, "ATHENA", Dialects.PRESTO), |
Why it matters? ⭐
Using getattr(Dialects, "ATHENA", Dialects.PRESTO) guards against environments with older sqlglot that lack an ATHENA entry and avoids an import-time AttributeError. The fallback to PRESTO is a reasonable defensive choice when ATHENA isn't available.
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** superset/sql/parse.py
**Line:** 61:61
**Comment:**
*Possible Bug: Compatibility with older sqlglot versions: directly referencing `Dialects.ATHENA` may raise an AttributeError if the installed sqlglot version lacks the ATHENA dialect; use a safe fallback (e.g. PRESTO) via getattr to avoid runtime attribute errors and ensure parsing still proceeds.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.| ) | ||
| statement = SQLStatement(sql, engine="awsathena") | ||
|
|
||
| # Should parse without errors using Athena dialect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The test calls statement.format() but contains no assertion that the parsed statement is a SELECT (or otherwise valid); add an explicit assertion like assert statement.is_select() to ensure the SQL is parsed as the expected statement type rather than silently passing without verification. [logic error]
Severity Level: Minor
| # Should parse without errors using Athena dialect | |
| # Ensure the parsed statement is a SELECT (verifies parsing result) | |
| assert statement.is_select() | |
Why it matters? ⭐
Reasonable and useful: asserting statement.is_select() makes the test explicit
about the expected kind of parsed AST instead of silently passing because
format() didn't raise. It's a low-risk, high-signal assertion that improves test quality.
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** tests/unit_tests/sql/parse_tests.py
**Line:** 2904:2904
**Comment:**
*Logic Error: The test calls `statement.format()` but contains no assertion that the parsed statement is a SELECT (or otherwise valid); add an explicit assertion like `assert statement.is_select()` to ensure the SQL is parsed as the expected statement type rather than silently passing without verification.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.|
CodeAnt AI finished reviewing your PR. |
User description
SUMMARY
This PR updates the SQLGlot dialect mapping for AWS Athena from
PRESTOtoATHENA.Athena-specific SQL syntax (e.g.,
USING EXTERNAL FUNCTION) now parses correctly in Superset, preventing “Unable to parse SQL” errors for queries that are valid in Athena but not in Presto.Related Issue
Fixes #36717
Changes
awsathenainsuperset/sql/parse.pytests/unit_tests/sql/parse_tests.pycovering Athena-specific SQL parsingUSING EXTERNAL FUNCTIONconstructsBEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A
TESTING INSTRUCTIONS
Unit tests
Local Superset setup with Athena
Configure Athena database connection locally in Superset.
Execute a query using USING EXTERNAL FUNCTION, e.g.:
USING EXTERNAL FUNCTION decrypt(data varbinary) RETURNS VARCHAR LAMBDA 'arn:aws:lambda:ap-south-1:123456789111:function:lambda-test' SELECT 1Verify parsing succeeds and no Superset errors occur.
ADDITIONAL INFORMATION
CodeAnt-AI Description
Use Athena dialect for awsathena so Athena-specific SQL parses correctly
What Changed
Impact
✅ Fewer Athena parse failures for valid queries✅ Clearer parsing for queries using Athena-specific syntax✅ Prevents "Unable to parse SQL" errors for awsathena connections💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.