fix: use Snowflake dialect for sqlglot SQL parsing#173
Open
elipollak wants to merge 1 commit intoSnowflake-Labs:mainfrom
Open
fix: use Snowflake dialect for sqlglot SQL parsing#173elipollak wants to merge 1 commit intoSnowflake-Labs:mainfrom
elipollak wants to merge 1 commit intoSnowflake-Labs:mainfrom
Conversation
718bd35 to
12a93c7
Compare
Without dialect="snowflake", sqlglot fails to parse valid Snowflake syntax (colon-path notation like f.value:key, COPY INTO, etc.), classifying those statements as "Unknown" instead of their actual type. Fixes Snowflake-Labs#161
12a93c7 to
77273d6
Compare
|
Oooo, would this also separate SHOW out to its own setting option instead of bucketing it under command?!! If so, PLEASE APPROVE |
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.
Summary
get_statement_type()inquery_manager/tools.pycallssqlglot.parse_one(sql_string)without specifyingdialect="snowflake". This causes sqlglot to use its generic SQL parser, which fails on valid Snowflake-specific syntax:f.value:key::STRING) — used with LATERAL FLATTEN to extract nested fieldsWhen parsing fails, the statement is classified as
Unknown, which is rejected unless users addUnknown: trueto their permissions config — defeating the purpose of statement-type filtering.Fix
One-line change:
sqlglot.parse_one(sql_string, dialect="snowflake")This was independently identified and fixed by @atvaccaro in the Notion fork:
makenotion/snowflake-mcp@3d0192d, which also includes comprehensive test coverage for Snowflake-specific syntax parsing. Those tests would be a good addition here as well.Verification
Adding the dialect parameter does not change classification of any standard statement types:
SELECTDROP TABLEDELETEINSERTUPDATETRUNCATEALTER TABLECREATE TABLEMERGEGRANTUNIONSELECT ... value:keyCOPY INTO @stageFixes #161