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
feat: add pyspark, datafusion and some fixes for db (#4719)
Shahmir Varqha763c6a3da504
diff --git a/docs/guides/working_with_data/sql.md b/docs/guides/working_with_data/sql.mdindex 1f3a579e04..2f9a343ce3 100644--- a/docs/guides/working_with_data/sql.md+++ b/docs/guides/working_with_data/sql.md@@ -274,7 +274,7 @@ catalog = RestCatalog()```-Catalogs will appear in the Datasources panel, but they cannot be used as an engine in SQL cells. However, you can still load the table into one cell and use it in subsequent Python or SQL cells.+Catalogs will appear in the Datasources panel, but they cannot be used as an engine in SQL cells. However, you can still load the table and use it in subsequent Python or SQL cells.```pythondf = catalog.load_table(("my-namespace", "my-table")).to_polars()diff --git a/frontend/src/components/databases/icon.tsx b/frontend/src/components/databases/icon.tsxindex 6ffda606ac..61dfef8656 100644--- a/frontend/src/components/databases/icon.tsx+++ b/frontend/src/components/databases/icon.tsx@@ -11,6 +11,8 @@ import TimeplusIcon from "./icons/timeplus.svg";import GoogleBigQueryIcon from "./icons/googlebigquery.svg";import TrinoIcon from "./icons/trino.svg";import IcebergIcon from "./icons/iceberg.png";+import DataFusionIcon from "./icons/datafusion.png";+import PySparkIcon from "./icons/spark.svg";import { cn } from "@/utils/cn";export type DBLogoName =@@ -25,7 +27,9 @@ export type DBLogoName =| "timeplus"| "bigquery"| "trino"- | "iceberg";+ | "iceberg"+ | "datafusion"+ | "pyspark";/*** Icons are from https://simpleicons.org/@@ -49,6 +53,8 @@ const URLS: Record<DBLogoName, string | undefined> = {bigquery: GoogleBigQueryIcon,trino: TrinoIcon,iceberg: IcebergIcon,+ datafusion: DataFusionIcon,+ pyspark: PySparkIcon,};export const DatabaseLogo: FC<DatabaseLogoProps> = ({ name, className }) => {diff --git a/frontend/src/components/databases/icons/datafusion.png b/frontend/src/components/databases/icons/datafusion.pngnew file mode 100644index 0000000000..55035f1855Binary files /dev/null and b/frontend/src/components/databases/icons/datafusion.png differdiff --git a/frontend/src/components/databases/icons/spark.svg b/frontend/src/components/databases/icons/spark.svgnew file mode 100644index 0000000000..d7c62df8be--- /dev/null+++ b/frontend/src/components/databases/icons/spark.svg@@ -0,0 +1 @@+<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><title>Apache Spark</title><path d="M10.812 0c-.425.013-.845.215-1.196.605a3.593 3.593 0 00-.493.722c-.355.667-.425 1.415-.556 2.143a551.9 551.9 0 00-.726 4.087c-.027.16-.096.227-.244.273C5.83 8.386 4.06 8.94 2.3 9.514c-.387.125-.773.289-1.114.506-1.042.665-1.196 1.753-.415 2.71.346.422.79.715 1.284.936 1.1.49 2.202.976 3.3 1.47.019.01.036.013.053.019h-.004l1.306.535c0 .023.002.045 0 .073-.2 2.03-.39 4.063-.58 6.095-.04.419-.012.831.134 1.23.317.87 1.065 1.148 1.881.701.372-.204.666-.497.937-.818 1.372-1.623 2.746-3.244 4.113-4.872.111-.133.205-.15.363-.098.349.117.697.231 1.045.347h.001c.02.012.045.02.073.03l.142.042c1.248.416 2.68.775 3.929 1.19.4.132.622.164 1.045.098.311-.048.592-.062.828-.236.602-.33.995-.957.988-1.682-.005-.427-.154-.813-.35-1.186-.82-1.556-1.637-3.113-2.461-4.666-.078-.148-.076-.243.037-.375 1.381-1.615 2.756-3.236 4.133-4.855.272-.32.513-.658.653-1.058.308-.878-.09-1.57-1-1.741a2.783 2.783 0 00-1.235.069c-1.974.521-3.947 1.041-5.918 1.57-.175.047-.26.015-.355-.144a353.08 353.08 0 00-2.421-4.018 4.61 4.61 0 00-.652-.849c-.371-.37-.802-.549-1.227-.536zm.172 3.703a.592.592 0 01.189.211c.87 1.446 1.742 2.89 2.609 4.338.07.118.135.16.277.121 1.525-.41 3.052-.813 4.579-1.217.367-.098.735-.193 1.103-.289a.399.399 0 01-.1.2c-1.259 1.48-2.516 2.962-3.779 4.438-.11.13-.12.22-.04.37.937 1.803 1.768 3.309 2.498 4.76l-3.696-1.019c-.538-.18-1.077-.358-1.615-.539-.163-.055-.25-.03-.36.1-1.248 1.488-2.504 2.97-3.759 4.454a.398.398 0 01-.18.132c.035-.378.068-.757.104-1.136.149-1.572.297-3.144.451-4.716-.03-.318.117-.405-.322-.545-1.493-.593-3.346-1.321-4.816-1.905a.595.595 0 01.24-.134c1.797-.57 3.595-1.14 5.394-1.705.127-.04.199-.092.211-.233.013-.148.05-.294.076-.441.241-1.363.483-2.726.726-4.088.068-.386.14-.771.21-1.157z"/></svg>\ No newline at end of filediff --git a/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap b/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snapindex 986f74017d..ab5be1d1ff 100644--- a/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap+++ b/frontend/src/components/editor/database/__tests__/__snapshots__/as-code.test.ts.snap@@ -28,6 +28,24 @@ engine = clickhouse_connect.get_client()"`;+exports[`generateDatabaseCode > basic connections > datafusion 1`] = `+"from datafusion import SessionContext+import ibis++con = ibis.datafusion.connect()"+`;++exports[`generateDatabaseCode > basic connections > datafusion with session 1`] = `+"from datafusion import SessionContext+import ibis++ctx = SessionContext()+# Sample table+_ = ctx.from_pydict({"a": [1, 2, 3]}, "my_table")++con = ibis.datafusion.connect(ctx)"+`;+exports[`generateDatabaseCode > basic connections > duckdb 1`] = `"import duckdb@@ -133,6 +151,21 @@ DATABASE_URL = f"postgresql://user:{_password}@localhost:5432/test"engine = sqlmodel.create_engine(DATABASE_URL, connect_args={'sslmode': 'require'})"`;+exports[`generateDatabaseCode > basic connections > pyspark 1`] = `+"from pyspark.sql import SparkSession+import ibis++con = ibis.pyspark.connect()"+`;++exports[`generateDatabaseCode > basic connections > pyspark with session 1`] = `+"from pyspark.sql import SparkSession+import ibis++session = SparkSession.builder.remote(f"user://localhost:15002").getOrCreate()+con = ibis.pyspark.connect(session)"+`;+exports[`generateDatabaseCode > basic connections > snowflake 1`] = `"from snowflake.sqlalchemy import URLimport osdiff --git a/frontend/src/components/editor/database/__tests__/as-code.test.ts b/frontend/src/components/editor/database/__tests__/as-code.test.tsindex 45e7352955..e705be5b6e 100644--- a/frontend/src/components/editor/database/__tests__/as-code.test.ts+++ b/frontend/src/components/editor/database/__tests__/as-code.test.ts@@ -92,7 +92,7 @@ describe("generateDatabaseCode", () => {type: "iceberg",name: "my_catalog",catalog: {- type: "rest",+ type: "REST",uri: "http://localhost:8181",warehouse: "/path/to/warehouse",},@@ -102,7 +102,7 @@ describe("generateDatabaseCode", () => {type: "iceberg",name: "my_catalog",catalog: {- type: "sql",+ type: "SQL",uri: "postgresql://localhost:5432/iceberg",warehouse: "/path/to/warehouse",},@@ -112,7 +112,7 @@ describe("generateDatabaseCode", () => {type: "iceberg",name: "my_catalog",catalog: {- type: "hive",+ type: "Hive",uri: "thrift://localhost:9083",warehouse: "/path/to/warehouse",},@@ -122,7 +122,7 @@ describe("generateDatabaseCode", () => {type: "iceberg",name: "my_catalog",catalog: {- type: "glue",+ type: "Glue",warehouse: "/path/to/warehouse",},};@@ -131,7 +131,7 @@ describe("generateDatabaseCode", () => {type: "iceberg",name: "my_catalog",catalog: {- type: "dynamodb",+ type: "DynamoDB","dynamodb.profile-name": "my_profile","dynamodb.region": "us-east-1","dynamodb.access-key-id": "my_access_key_id",@@ -140,8 +140,29 @@ describe("generateDatabaseCode", () => {},};+ const datafusionConnection: DatabaseConnection = {+ type: "datafusion",+ sessionContext: false,+ };++ const datafusionConnSession: DatabaseConnection = {+ type: "datafusion",+ sessionContext: true,+ };++ const pysparkConnection: DatabaseConnection = {+ type: "pyspark",+ };++ const pysparkConnSession: DatabaseConnection = {+ type: "pyspark",+ username: "user",+ host: "localhost",+ port: 15_002,+ };+describe("basic connections", () => {- it.each([+ const testCases: Array<[string, DatabaseConnection, ConnectionLibrary]> = [["postgres with SQLModel", basePostgres, "sqlmodel"],["postgres with SQLAlchemy", basePostgres, "sqlalchemy"],["mysql with SQLModel", baseMysql, "sqlmodel"],@@ -159,10 +180,14 @@ describe("generateDatabaseCode", () => {["iceberg hive", icebergHiveConnection, "pyiceberg"],["iceberg glue", icebergGlueConnection, "pyiceberg"],["iceberg dynamodb", icebergDynamoDBConnection, "pyiceberg"],- ])("%s", (name, connection, orm) => {- expect(- generateDatabaseCode(connection, orm as ConnectionLibrary),- ).toMatchSnapshot();+ ["datafusion", datafusionConnection, "ibis"],+ ["datafusion with session", datafusionConnSession, "ibis"],+ ["pyspark", pysparkConnection, "ibis"],+ ["pyspark with session", pysparkConnSession, "ibis"],+ ];++ it.each(testCases)("%s", (name, connection, orm) => {+ expect(generateDatabaseCode(connection, orm)).toMatchSnapshot();});});diff --git a/frontend/src/components/editor/database/add-database-form.tsx b/frontend/src/components/editor/database/add-database-form.tsxindex 9775786bc2..c60962abf7 100644--- a/frontend/src/components/editor/database/add-database-form.tsx+++ b/frontend/src/components/editor/database/add-database-form.tsx@@ -18,6 +18,8 @@ import {ChdbConnectionSchema,TrinoConnectionSchema,IcebergConnectionSchema,+ DataFusionConnectionSchema,+ PySparkConnectionSchema,} from "./schemas";import {Dialog,@@ -165,6 +167,26 @@ const DATABASES = [preferred: "sqlalchemy",},},+ {+ name: "DataFusion",+ schema: DataFusionConnectionSchema,+ color: "#202A37",+ logo: "datafusion",+ connectionLibraries: {+ libraries: ["ibis"],+ preferred: "ibis",+ },+ },+ {+ name: "PySpark",+ schema: PySparkConnectionSchema,+ color: "#1C5162",+ logo: "pyspark",+ connectionLibraries: {+ libraries: ["ibis"],+ preferred: "ibis",+ },+ },] satisfies ConnectionSchema[];const DATA_CATALOGS = [@@ -230,7 +252,7 @@ const DatabaseForm: React.FC<{reValidateMode: "onChange",});- const connectionLibraries = DATABASES.find(+ const connectionLibraries = [...DATABASES, ...DATA_CATALOGS].find((s) => s.schema === schema,)?.connectionLibraries;const [preferredConnection, setPreferredConnection] =diff --git a/frontend/src/components/editor/database/as-code.ts b/frontend/src/components/editor/database/as-code.tsindex 603dfc1f14..76fa1dc44f 100644--- a/frontend/src/components/editor/database/as-code.ts+++ b/frontend/src/components/editor/database/as-code.ts@@ -11,7 +11,8 @@ export type ConnectionLibrary =| "duckdb"| "clickhouse_connect"| "chdb"- | "pyiceberg";+ | "pyiceberg"+ | "ibis";export const ConnectionDisplayNames: Record<ConnectionLibrary, string> = {sqlmodel: "SQLModel",@@ -20,6 +21,7 @@ export const ConnectionDisplayNames: Record<ConnectionLibrary, string> = {clickhouse_connect: "ClickHouse Connect",chdb: "chDB",pyiceberg: "PyIceberg",+ ibis: "Ibis",};abstract class CodeGenerator<T extends DatabaseConnection["type"]> {@@ -430,15 +432,15 @@ class TrinoGenerator extends CodeGenerator<"trino"> {class PyIcebergGenerator extends CodeGenerator<"iceberg"> {generateImports(): string[] {switch (this.connection.catalog.type) {- case "rest":+ case "REST":return ["from pyiceberg.catalog.rest import RestCatalog"];- case "sql":+ case "SQL":return ["from pyiceberg.catalog.sql import SqlCatalog"];- case "hive":+ case "Hive":return ["from pyiceberg.catalog.hive import HiveCatalog"];- case "glue":+ case "Glue":return ["from pyiceberg.catalog.glue import GlueCatalog"];- case "dynamodb":+ case "DynamoDB":return ["from pyiceberg.catalog.dynamodb import DynamoDBCatalog"];default:assertNever(this.connection.catalog);@@ -473,7 +475,7 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {const name = `"${this.connection.name}"`;switch (this.connection.catalog.type) {- case "rest":+ case "REST":return dedent(`catalog = RestCatalog(${name},@@ -481,7 +483,7 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {},)`);- case "sql":+ case "SQL":return dedent(`catalog = SqlCatalog(${name},@@ -489,7 +491,7 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {},)`);- case "hive":+ case "Hive":return dedent(`catalog = HiveCatalog(${name},@@ -497,7 +499,7 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {},)`);- case "glue":+ case "Glue":return dedent(`catalog = GlueCatalog(${name},@@ -505,7 +507,7 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {},)`);- case "dynamodb":+ case "DynamoDB":return dedent(`catalog = DynamoDBCatalog(${name},@@ -519,6 +521,56 @@ class PyIcebergGenerator extends CodeGenerator<"iceberg"> {}}+class DataFusionGenerator extends CodeGenerator<"datafusion"> {+ generateImports(): string[] {+ // To trigger installation of ibis-datafusion+ return ["import ibis", "from datafusion import SessionContext"];+ }++ generateConnectionCode(): string {+ if (this.connection.sessionContext) {+ return dedent(`+ ctx = SessionContext()+ # Sample table+ _ = ctx.from_pydict({"a": [1, 2, 3]}, "my_table")++ con = ibis.datafusion.connect(ctx)+ `);+ }+ return dedent(`+ con = ibis.datafusion.connect()+ `);+ }+}++class PySparkGenerator extends CodeGenerator<"pyspark"> {+ generateImports(): string[] {+ return ["import ibis", "from pyspark.sql import SparkSession"];+ }++ generateConnectionCode(): string {+ if (+ this.connection.username ||+ this.connection.host ||+ this.connection.port+ ) {+ const username = this.secrets.printInFString(+ "username",+ this.connection.username,+ );+ const host = this.secrets.printInFString("host", this.connection.host);+ const port = this.secrets.printInFString("port", this.connection.port);+ return dedent(`+ session = SparkSession.builder.remote(f"${username}://${host}:${port}").getOrCreate()+ con = ibis.pyspark.connect(session)+ `);+ }+ return dedent(`+ con = ibis.pyspark.connect()+ `);+ }+}+class CodeGeneratorFactory {public secrets = new SecretContainer();@@ -549,6 +601,10 @@ class CodeGeneratorFactory {return new TrinoGenerator(connection, orm, this.secrets);case "iceberg":return new PyIcebergGenerator(connection, orm, this.secrets);+ case "datafusion":+ return new DataFusionGenerator(connection, orm, this.secrets);+ case "pyspark":+ return new PySparkGenerator(connection, orm, this.secrets);default:assertNever(connection);}diff --git a/frontend/src/components/editor/database/schemas.ts b/frontend/src/components/editor/database/schemas.tsindex 759ce2e9e3..4f895a633a 100644--- a/frontend/src/components/editor/database/schemas.ts+++ b/frontend/src/components/editor/database/schemas.ts@@ -299,7 +299,7 @@ export const IcebergConnectionSchema = z.object({catalog: z.discriminatedUnion("type", [z.object({- type: z.literal("rest"),+ type: z.literal("REST"),warehouse: warehouseNameField(),uri: z.string()@@ -314,7 +314,7 @@ export const IcebergConnectionSchema = z.object({token: tokenField(),}),z.object({- type: z.literal("sql"),+ type: z.literal("SQL"),warehouse: warehouseNameField(),uri: z.string()@@ -328,17 +328,17 @@ export const IcebergConnectionSchema = z.object({),}),z.object({- type: z.literal("hive"),+ type: z.literal("Hive"),warehouse: warehouseNameField(),uri: uriField(),}),z.object({- type: z.literal("glue"),+ type: z.literal("Glue"),warehouse: warehouseNameField(),uri: uriField(),}),z.object({- type: z.literal("dynamodb"),+ type: z.literal("DynamoDB"),"dynamodb.profile-name": z.string().optional()@@ -374,6 +374,26 @@ export const IcebergConnectionSchema = z.object({.describe(FieldOptions.of({ special: "tabs" })),});+export const DataFusionConnectionSchema = z.object({+ type: z.literal("datafusion"),+ sessionContext: z+ .boolean()+ .optional()+ .describe(+ FieldOptions.of({+ label: "Use Session Context",+ }),+ ),+});++// Ideally, we can conditionally render the username, host, and port fields.+export const PySparkConnectionSchema = z.object({+ type: z.literal("pyspark"),+ username: usernameField().optional(),+ host: hostField().optional(),+ port: portField().optional(),+});+export const DatabaseConnectionSchema = z.discriminatedUnion("type", [PostgresConnectionSchema,MySQLConnectionSchema,@@ -386,6 +406,8 @@ export const DatabaseConnectionSchema = z.discriminatedUnion("type", [ChdbConnectionSchema,TrinoConnectionSchema,IcebergConnectionSchema,+ DataFusionConnectionSchema,+ PySparkConnectionSchema,]);export type DatabaseConnection = z.infer<typeof DatabaseConnectionSchema>;diff --git a/frontend/src/core/codemirror/language/panel.tsx b/frontend/src/core/codemirror/language/panel.tsxindex 99e4ac8a38..83b7c7f3fc 100644--- a/frontend/src/core/codemirror/language/panel.tsx+++ b/frontend/src/core/codemirror/language/panel.tsx@@ -296,7 +296,7 @@ const SQLEngineSelect: React.FC<SelectProps> = ({return connections.map((connection) => (<SelectItem key={connection.name} value={connection.name}><div className="flex items-center gap-1">- <DatabaseLogo className="h-3 w-3" name={connection.source} />+ <DatabaseLogo className="h-3 w-3" name={connection.dialect} /><span className="truncate">{transformDisplayName(connection.display_name)}</span>diff --git a/marimo/_smoke_tests/sql/ibis_backend.py b/marimo/_smoke_tests/sql/ibis_backend.pynew file mode 100644index 0000000000..70717e4f4d--- /dev/null+++ b/marimo/_smoke_tests/sql/ibis_backend.py@@ -0,0 +1,61 @@+# /// script+# requires-python = ">=3.12"+# dependencies = [+# "ibis-framework[datafusion,duckdb]==10.5.0",+# "marimo",+# "polars==1.28.1",+# "pyarrow==20.0.0",+# ]+# ///++import marimo++__generated_with = "0.13.2"+app = marimo.App(width="medium")+++def _():+ import marimo as mo+ import polars as pl+ import pyarrow as pa+ import ibis+ return ibis, mo, pa+++def _(ibis, pa):+ con = ibis.datafusion.connect()++ con.create_catalog("my_catalog", force=True)+ con.create_database("my_db", force=True)++ data = pa.table(+ {+ "id": [1, 2, 3],+ "name": ["Alice", "Bob", "Charlie"],+ "list": [[1, 2], [3, 4], [5, 6]],+ "dict": [+ {"name": "Alice", "age": 23},+ {"name": "Bob", "age": 45},+ {"name": "Charlie", "age": 4},+ ],+ }+ )+ con.create_table("my_data", obj=data, database="my_db", overwrite=True)+ return (con,)+++def _(con, mo):+ _df = mo.sql(+ f"""+ SELECT * FROM my_db.my_data+ """,+ engine=con+ )+ return+++if __name__ == "__main__":+ app.run()diff --git a/marimo/_smoke_tests/sql/iceberg_catalog.py b/marimo/_smoke_tests/sql/iceberg_catalog.pynew file mode 100644index 0000000000..a7249c7902--- /dev/null+++ b/marimo/_smoke_tests/sql/iceberg_catalog.py@@ -0,0 +1,77 @@+# /// script+# requires-python = ">=3.12"+# dependencies = [+# "marimo",+# "polars==1.28.1",+# "pyarrow==20.0.0",+# "pyiceberg[sql-sqlite]==0.9.0",+# ]+# ///++import marimo++__generated_with = "0.13.2"+app = marimo.App(width="medium")+++def _():+ import marimo as mo+ import pyarrow as pa+ from pyiceberg.catalog import load_catalog+ return load_catalog, pa+++def _(load_catalog):+ warehouse_path = "/tmp/"+ catalog = load_catalog(+ "default",+ **{+ "type": "sql",+ "uri": f"sqlite:///{warehouse_path}/pyiceberg_catalog.db",+ "warehouse": f"file://{warehouse_path}",+ },+ )+ return (catalog,)+++def _(catalog, pa):+ # Create default namespace+ catalog.create_namespace_if_not_exists("default")++ # Create simple PyArrow table+ df = pa.table(+ {+ "id": [1, 2, 3],+ "name": ["Alice", "Bob", "Charlie"],+ "list": [[1, 2], [3, 4], [5, 6]],+ "dict": [+ {"name": "Alice", "age": 23},+ {"name": "Bob", "age": 45},+ {"name": "Charlie", "age": 4},+ ],+ }+ )++ # Create an Iceberg table+ test_table = ("default", "my_table")+ # catalog.drop_table(test_table) # Drop table if exists++ table = catalog.create_table_if_not_exists(+ test_table,+ schema=df.schema,+ )+ table.overwrite(df)+ return (test_table,)+++def _(catalog, test_table):+ catalog.load_table(test_table).to_polars().collect()+ return+++if __name__ == "__main__":+ app.run()diff --git a/marimo/_sql/engines/clickhouse.py b/marimo/_sql/engines/clickhouse.pyindex ccd64abd00..dbfdfb5141 100644--- a/marimo/_sql/engines/clickhouse.py+++ b/marimo/_sql/engines/clickhouse.py@@ -14,6 +14,7 @@ from marimo._data.models import ()from marimo._dependencies.dependencies import DependencyManagerfrom marimo._sql.engines.types import (+ NO_SCHEMA_NAME,InferenceConfig,SQLEngine,register_engine,@@ -353,7 +354,7 @@ class ClickhouseServer(SQLEngine):tables = []else:tables = self.get_tables_in_schema(- schema="",+ schema=NO_SCHEMA_NAME,database=db,include_table_details=include_table_details,)@@ -363,7 +364,7 @@ class ClickhouseServer(SQLEngine):dialect=self.dialect,engine=self._engine_name,# ClickHouse does not have schemas- schemas=[Schema(name="", tables=tables)],+ schemas=[Schema(name=NO_SCHEMA_NAME, tables=tables)],))return databasesdiff --git a/marimo/_sql/engines/ibis.py b/marimo/_sql/engines/ibis.pyindex 22af37a2ca..0acb0e1c54 100644--- a/marimo/_sql/engines/ibis.py+++ b/marimo/_sql/engines/ibis.py@@ -1,3 +1,4 @@+# Copyright 2025 Marimo. All rights reserved.from __future__ import annotationsfrom typing import TYPE_CHECKING, Any, Literal, Optional, Union@@ -47,7 +48,6 @@ class IbisEngine(SQLEngine):@propertydef source(self) -> str:- # TODO should this be the backend name, the SQL dialect, or ibis?return "ibis"@propertydiff --git a/marimo/_sql/engines/pyiceberg.py b/marimo/_sql/engines/pyiceberg.pyindex a28f48cfd2..8f26919b3c 100644--- a/marimo/_sql/engines/pyiceberg.py+++ b/marimo/_sql/engines/pyiceberg.py@@ -12,6 +12,7 @@ from marimo._data.models import ()from marimo._dependencies.dependencies import DependencyManagerfrom marimo._sql.engines.types import (+ NO_SCHEMA_NAME,InferenceConfig,SQLEngine,register_engine,@@ -24,8 +25,6 @@ LOGGER = _loggers.marimo_logger()if TYPE_CHECKING:from pyiceberg.catalog import Catalog-NO_SCHEMA_NAME = ""-@register_engineclass PyIcebergEngine(SQLEngine):diff --git a/marimo/_sql/engines/sqlalchemy.py b/marimo/_sql/engines/sqlalchemy.pyindex f470558ee2..864764311b 100644--- a/marimo/_sql/engines/sqlalchemy.py+++ b/marimo/_sql/engines/sqlalchemy.py@@ -53,7 +53,7 @@ class SQLAlchemyEngine(SQLEngine):@propertydef source(self) -> str:- return str(self._engine.dialect.name)+ return "sqlalchemy"@propertydef dialect(self) -> str:diff --git a/marimo/_sql/engines/types.py b/marimo/_sql/engines/types.pyindex ffea18e1ac..3c7cf46492 100644--- a/marimo/_sql/engines/types.py+++ b/marimo/_sql/engines/types.py@@ -15,6 +15,7 @@ from marimo._runtime.context.types import ()ENGINE_REGISTRY: list[type[SQLEngine]] = []+NO_SCHEMA_NAME = ""def register_engine(cls: type[SQLEngine]) -> type[SQLEngine]:@@ -62,7 +63,7 @@ class SQLEngine(ABC):@property@abstractmethoddef source(self) -> str:- """Return the source of the engine."""+ """Return the source of the engine. Usually the name of the library used to connect to the database."""pass@propertydiff --git a/tests/_sql/test_engines.py b/tests/_sql/test_engines.pyindex 9fa09d37af..e807386292 100644--- a/tests/_sql/test_engines.py+++ b/tests/_sql/test_engines.py@@ -105,7 +105,7 @@ def test_sqlalchemy_source_and_dialect() -> None:sqlite_engine = sa.create_engine("sqlite:///:memory:")engine = SQLAlchemyEngine(sqlite_engine)- assert engine.source == "sqlite"+ assert engine.source == "sqlalchemy"assert engine.dialect == "sqlite"# We can test multiple dialects without mocking by creating different engines@@ -113,7 +113,7 @@ def test_sqlalchemy_source_and_dialect() -> None:mock_engine = MagicMock()mock_engine.dialect.name = "postgresql"pg_engine = SQLAlchemyEngine(mock_engine)- assert pg_engine.source == "postgresql"+ assert pg_engine.source == "sqlalchemy"assert pg_engine.dialect == "postgresql"diff --git a/tests/_sql/test_get_engines.py b/tests/_sql/test_get_engines.pyindex 4291fdc2c3..82ac93281d 100644--- a/tests/_sql/test_get_engines.py+++ b/tests/_sql/test_get_engines.py@@ -71,7 +71,7 @@ def test_engine_to_data_source_connection() -> None:"my_postgres", sqlalchemy_engine)assert isinstance(connection, DataSourceConnection)- assert connection.source == "postgresql"+ assert connection.source == "sqlalchemy"assert connection.dialect == "postgresql"assert connection.name == "my_postgres"assert connection.display_name == "postgresql (my_postgres)"@@ -274,7 +274,7 @@ def test_get_engines_sqlalchemy_databases() -> None:connection = engine_to_data_source_connection("sqlite", engine)assert isinstance(connection, DataSourceConnection)- assert connection.source == "sqlite"+ assert connection.source == "sqlalchemy"assert connection.dialect == "sqlite"assert connection.name == "sqlite"assert connection.display_name == "sqlite (sqlite)"diff --git a/tests/_sql/test_pyiceberg.py b/tests/_sql/test_pyiceberg.pyindex 6313dc5608..5d0ffd2e20 100644--- a/tests/_sql/test_pyiceberg.py+++ b/tests/_sql/test_pyiceberg.py@@ -10,6 +10,7 @@ import pytestfrom marimo._data.models import DataTable, DataTableColumnfrom marimo._dependencies.dependencies import DependencyManagerfrom marimo._sql.engines.pyiceberg import PyIcebergEngine+from marimo._sql.engines.types import NO_SCHEMA_NAMEfrom marimo._types.ids import VariableNameHAS_PYICEBERG = DependencyManager.pyiceberg.has()@@ -168,7 +169,9 @@ def test_pyiceberg_get_table_details(memory_catalog: Catalog) -> None:memory_catalog, engine_name=VariableName("my_iceberg"))table = engine.get_table_details(- table_name="table1", schema_name="", database_name="default"+ table_name="table1",+ schema_name=NO_SCHEMA_NAME,+ database_name="default",)assert table is not None@@ -234,12 +237,12 @@ def test_pyiceberg_get_databases(memory_catalog: Catalog) -> None:assert databases[0].name == "default"assert databases[0].dialect == "iceberg"assert len(databases[0].schemas) == 1- assert databases[0].schemas[0].name == ""+ assert databases[0].schemas[0].name == NO_SCHEMA_NAMEassert len(databases[0].schemas[0].tables) == 2assert databases[1].name == "test_namespace"assert len(databases[1].schemas) == 1- assert databases[1].schemas[0].name == ""+ assert databases[1].schemas[0].name == NO_SCHEMA_NAMEassert len(databases[1].schemas[0].tables) == 1# Test with include_tables=False@@ -251,12 +254,12 @@ def test_pyiceberg_get_databases(memory_catalog: Catalog) -> None:assert len(databases) == 2assert databases[0].name == "default"assert len(databases[0].schemas) == 1- assert databases[0].schemas[0].name == ""+ assert databases[0].schemas[0].name == NO_SCHEMA_NAMEassert len(databases[0].schemas[0].tables) == 0assert databases[1].name == "test_namespace"assert len(databases[1].schemas) == 1- assert databases[1].schemas[0].name == ""+ assert databases[1].schemas[0].name == NO_SCHEMA_NAMEassert len(databases[1].schemas[0].tables) == 0@@ -275,7 +278,7 @@ def test_pyiceberg_auto_discovery(memory_catalog: Catalog) -> None:assert isinstance(databases, list)assert len(databases) == 2- assert databases[0].schemas[0].name == ""+ assert databases[0].schemas[0].name == NO_SCHEMA_NAMEassert len(databases[0].schemas[0].tables) == 2# Test with _is_cheap_discovery mocked to return Falsediff --git a/tests/_sql/test_sqlalchemy.py b/tests/_sql/test_sqlalchemy.pyindex 682a322326..27373fa715 100644--- a/tests/_sql/test_sqlalchemy.py+++ b/tests/_sql/test_sqlalchemy.py@@ -206,6 +206,7 @@ def test_sqlalchemy_sql_types() -> None:assert len(tables) == 1table = tables[0]assert table.source == "sqlite"+ assert table.source_type == "connection"assert table.name == "all_types"assert table.num_columns == 6assert table.num_rows is None