The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Bump sqlglot 28.6.0 -> 30.20.0 (#83343)
Chris Truter4aa3c15d492d
diff --git a/resources/python-sources/pyproject.toml b/resources/python-sources/pyproject.tomlindex 61fd7d2790b..1b63e93d411 100644--- a/resources/python-sources/pyproject.toml+++ b/resources/python-sources/pyproject.toml@@ -4,5 +4,5 @@ version = "0.1.0"requires-python = ">=3.11"dependencies = [# Keep these in the format "library==X.Y.Z", we parse it with a regex.- "sqlglot==28.6.0",+ "sqlglot==30.20.0",]diff --git a/src/metabase/sql_parsing/core.clj b/src/metabase/sql_parsing/core.cljindex 23614b417bc..5d6c351d9cb 100644--- a/src/metabase/sql_parsing/core.clj+++ b/src/metabase/sql_parsing/core.clj@@ -68,6 +68,9 @@(-> detail(str/replace-first #"^sqlglot call failed: " "")(str/replace #" for <class '[^']*'>" "")+ ;; sqlglot >=29 represents end-of-input as a SENTINEL token rather than `None`; the `but got+ ;; None` case below is kept for whichever internal form the caller's sqlglot happens to use.+ (str/replace #"<Token token_type: TokenType\.SENTINEL,[^>]*>" "the end of the query")(str/replace #"<Token [^>]*?text: ([^,>]*),[^>]*>" "'$1'")(str/replace #"but got None\b" "but got the end of the query")))diff --git a/test/metabase/source_swap/native_test.clj b/test/metabase/source_swap/native_test.cljindex 4b9a0c4ed69..517650fe6cb 100644--- a/test/metabase/source_swap/native_test.clj+++ b/test/metabase/source_swap/native_test.clj@@ -266,7 +266,13 @@"SELECT * FROM\n-- /*]]*/ \nORDERS LIMIT 5""ORDERS" "NEW_ORDERS")](is (str/includes? result "NEW_ORDERS"))- (is (str/includes? result "/*]]*/") "Comment with bracket marker should be preserved"))))+ ;; sqlglot regenerates comments rather than preserving their source text, and versions differ on how they+ ;; escape a comment-terminator-like sequence inside comment content (sqlglot >=30.17 inserts spaces, e.g.+ ;; "/*]]*/" -> "/* / *]]* / */", to keep the regenerated SQL valid). A plain substring check for "]]" would+ ;; pass even if the marker leaked out of the comment into live SQL, so this checks it's still bracketed by+ ;; some /* ... */ span instead.+ (is (re-find #"(?s)/\*.*?\]\].*?\*/" result)+ "Bracket marker should stay inside a comment, not leak into executable SQL"))));;; ------------------------------------------------ Schema-Qualified Native SQL Tests ------------------------------------------------diff --git a/test/metabase/sql_parsing/test_cases/parse_error_message.edn b/test/metabase/sql_parsing/test_cases/parse_error_message.ednindex 514d2bccedf..f179e70a27e 100644--- a/test/metabase/sql_parsing/test_cases/parse_error_message.edn+++ b/test/metabase/sql_parsing/test_cases/parse_error_message.edn@@ -2,7 +2,7 @@[{:name "a keyword the parser was still waiting for":dialect "postgres":sql "SELECT !!!"- :internals "<class 'sqlglot.expressions.Not'>"+ :internals "<class 'sqlglot.expressions.core.Not'>":diagnostic "ParseError: Required keyword: 'this' missing. Line 1, Col: 10.\n SELECT !!!\n ^"}{:name "a token where a table name belonged"@@ -14,7 +14,7 @@{:name "the end of the query where a table name belonged":dialect "postgres":sql "SELECT * FROM a JOIN"- :internals "but got None"+ :internals "<Token token_type: TokenType.SENTINEL":diagnostic "ParseError: Expected table name but got the end of the query. Line 1, Col: 20.\n SELECT * FROM a JOIN\n ^^^^"}{:name "a query that is not SQL at all"diff --git a/test/metabase/sql_parsing/test_cases/referenced_fields.edn b/test/metabase/sql_parsing/test_cases/referenced_fields.ednindex cce6ac25656..eec7e0491e1 100644--- a/test/metabase/sql_parsing/test_cases/referenced_fields.edn+++ b/test/metabase/sql_parsing/test_cases/referenced_fields.edn@@ -207,9 +207,14 @@{:name "update-with-join":sql "UPDATE users SET last_purchase = t.max_date FROM (SELECT user_id, MAX(created_at) as max_date FROM transactions GROUP BY user_id) t WHERE users.id = t.user_id":dialect "postgres"- :expected []}+ :expected [["transactions" "created_at"] ["transactions" "user_id"]]}{:name "delete-with-subquery":sql "DELETE FROM users WHERE id IN (SELECT user_id FROM transactions WHERE total < 10)":dialect "postgres"- :expected [["transactions" "total"] ["transactions" "user_id"]]}]}+ :expected [["transactions" "total"] ["transactions" "user_id"]]}++ {:name "clickhouse-backtick-quoted-function-name"+ :sql "SELECT `parseDateTimeBestEffort`(ts) FROM events"+ :dialect "clickhouse"+ :expected [["events" "ts"]]}]}diff --git a/test/metabase/sql_parsing/test_cases/referenced_tables.edn b/test/metabase/sql_parsing/test_cases/referenced_tables.ednindex 00dc7a4868e..1640d7356d7 100644--- a/test/metabase/sql_parsing/test_cases/referenced_tables.edn+++ b/test/metabase/sql_parsing/test_cases/referenced_tables.edn@@ -197,4 +197,9 @@{:name "a trailing comma the engine would refuse still names its table":dialect "clickhouse":sql "SELECT id, FROM customers"- :tables [[nil nil "customers"]]}]}+ :tables [[nil nil "customers"]]}++ {:name "a star with an EXCLUDE list still names its table"+ :dialect "redshift"+ :sql "SELECT * EXCLUDE (id) FROM products"+ :tables [[nil nil "products"]]}]}diff --git a/test/metabase/sql_parsing/test_cases/validate_query.edn b/test/metabase/sql_parsing/test_cases/validate_query.ednindex 5aaad5f9d21..83ac66a70cf 100644--- a/test/metabase/sql_parsing/test_cases/validate_query.edn+++ b/test/metabase/sql_parsing/test_cases/validate_query.edn@@ -68,4 +68,17 @@:sql "SELECT * FROM nonexistent":default-schema "PUBLIC":schema :products+ :expected {:status "ok"}}++ {:name "snowflake ILIKE against another column, not a literal pattern"+ :dialect "snowflake"+ :sql "SELECT * FROM products WHERE title ILIKE category"+ :default-schema "PUBLIC"+ :schema :products+ :expected {:status "ok"}}++ {:name "postgres NOT LIKE still resolves its column"+ :sql "SELECT * FROM products WHERE title NOT LIKE '%deluxe%'"+ :default-schema "PUBLIC"+ :schema :products:expected {:status "ok"}}]}