A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: sql formatting and remove extensions from catalog references (#2862)
Myles Scolnick25b51758cb8e
diff --git a/frontend/src/core/codemirror/language/__tests__/sql.test.ts b/frontend/src/core/codemirror/language/__tests__/sql.test.tsindex 01e5c91718..e1c040e50f 100644--- a/frontend/src/core/codemirror/language/__tests__/sql.test.ts+++ b/frontend/src/core/codemirror/language/__tests__/sql.test.ts@@ -140,7 +140,8 @@ describe("SQLLanguageAdapter", () => {"my_df = mo.sql(f"""SELECT * FROM table- """, output=False+ """,+ output=False,)"`);expect(offset).toBe(26);diff --git a/frontend/src/core/codemirror/language/sql.ts b/frontend/src/core/codemirror/language/sql.tsindex 97a1386a2b..2c77b81875 100644--- a/frontend/src/core/codemirror/language/sql.ts+++ b/frontend/src/core/codemirror/language/sql.ts@@ -101,7 +101,7 @@ export class SQLLanguageAdapter implements LanguageAdapter {// Multiline codeconst start = `${this.dataframeName} = mo.sql(\n ${prefix}"""\n`;const escapedCode = code.replaceAll('"""', String.raw`\"""`);- const end = `\n """${this.showOutput ? "" : ", output=False"}\n)`;+ const end = `\n """${this.showOutput ? "" : ",\n output=False,"}\n)`;return [start + indentOneTab(escapedCode) + end, start.length + 1];}diff --git a/marimo/_ast/sql_visitor.py b/marimo/_ast/sql_visitor.pyindex f870d5d962..9ad3a62e3b 100644--- a/marimo/_ast/sql_visitor.py+++ b/marimo/_ast/sql_visitor.py@@ -264,8 +264,13 @@ def find_sql_defs(sql_statement: str) -> SQLDefs:token_extractor.token_str(i))if "." in catalog_name:+ # e.g. "db.sqlite"# strip the extension from the namecatalog_name = catalog_name.split(".")[0]+ if ":" in catalog_name:+ # e.g. "md:my_db"+ # split on ":" and take the second part+ catalog_name = catalog_name.split(":")[1]if i + 1 < len(tokens) and token_extractor.is_keyword(i + 1, "as"):# Skip over database-path 'AS'i += 2diff --git a/tests/_ast/test_sql_visitor.py b/tests/_ast/test_sql_visitor.pyindex 3ab2c766b1..51e461daa8 100644--- a/tests/_ast/test_sql_visitor.py+++ b/tests/_ast/test_sql_visitor.py@@ -366,6 +366,13 @@ class TestFindSQLDefs:catalogs=["my_db"],)+ @staticmethod+ def test_find_sql_defs_attach_with_colon() -> None:+ sql = "ATTACH 'md:my_db'"+ assert find_sql_defs(sql) == SQLDefs(+ catalogs=["my_db"],+ )+@staticmethoddef test_find_sql_defs_with_catalog() -> None:sql = """