Skip to content

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.

Add ADBC DB-API engine for SQL connections (#7664)

Matt Corley3c457a6433f9
diff --git a/frontend/src/components/databases/display.tsx b/frontend/src/components/databases/display.tsx
index 4fc0f58857..8b74c5e735 100644
--- a/frontend/src/components/databases/display.tsx
+++ b/frontend/src/components/databases/display.tsx
@@ -15,6 +15,7 @@ export function dbDisplayName(name: string) {
case "mariadb":
return "MariaDB";
case "mssql":
+ case "microsoft sql server":
return "Microsoft SQL Server";
case "oracle":
return "Oracle";
diff --git a/frontend/src/components/datasources/utils.ts b/frontend/src/components/datasources/utils.ts
index 92c23429af..dbd9d86785 100644
--- a/frontend/src/components/datasources/utils.ts
+++ b/frontend/src/components/datasources/utils.ts
@@ -47,6 +47,7 @@ function getFormatter(dialect: string): SqlCodeFormatter {
}
case "mssql":
case "sqlserver":
+ case "microsoft sql server":
return {
formatTableName: defaultFormatter.formatTableName,
formatSelectClause: (columnName: string, tableName: string) =>
@@ -86,6 +87,8 @@ function getFormatter(dialect: string): SqlCodeFormatter {
case "spark":
case "trino":
case "singlestoredb":
+ case "databricks":
+ case "datafusion":
return defaultFormatter;
default:
logNever(dialect);
diff --git a/frontend/src/core/codemirror/format.ts b/frontend/src/core/codemirror/format.ts
index eae909dd41..800ecf21a3 100644
--- a/frontend/src/core/codemirror/format.ts
+++ b/frontend/src/core/codemirror/format.ts
@@ -195,6 +195,7 @@ async function getSqlFormatterDialect(
return duckdb;
case "mssql":
case "sqlserver":
+ case "microsoft sql server":
return transactsql;
case "athena":
case "awsathena":
@@ -203,7 +204,10 @@ async function getSqlFormatterDialect(
case "flink":
case "mongodb":
case "timescaledb":
+ case "datafusion":
return sql;
+ case "databricks":
+ return spark;
default:
logNever(sqlDialect);
return defaultDialect;
diff --git a/frontend/src/core/codemirror/language/languages/sql/sql.ts b/frontend/src/core/codemirror/language/languages/sql/sql.ts
index e2621cbd4c..7acfce8283 100644
--- a/frontend/src/core/codemirror/language/languages/sql/sql.ts
+++ b/frontend/src/core/codemirror/language/languages/sql/sql.ts
@@ -373,6 +373,7 @@ function connectionNameToParserDialect(
return "Sqlite";
case "mssql":
case "sqlserver":
+ case "microsoft sql server":
return "TransactSQL";
case "duckdb":
return "DuckDB";
@@ -404,6 +405,8 @@ function connectionNameToParserDialect(
case "tidb":
case "singlestoredb":
case "spark":
+ case "databricks":
+ case "datafusion":
Logger.debug("Unsupported dialect", { dialect });
return null;
default:
diff --git a/frontend/src/core/codemirror/language/languages/sql/utils.ts b/frontend/src/core/codemirror/language/languages/sql/utils.ts
index 7549339b96..19763a402d 100644
--- a/frontend/src/core/codemirror/language/languages/sql/utils.ts
+++ b/frontend/src/core/codemirror/language/languages/sql/utils.ts
@@ -49,6 +49,9 @@ const KNOWN_DIALECTS_ARRAY = [
"oracledb",
"singlestoredb",
"timescaledb",
+ "databricks",
+ "datafusion",
+ "microsoft sql server",
] as const;
const KNOWN_DIALECTS: ReadonlySet<string> = new Set(KNOWN_DIALECTS_ARRAY);
type KnownDialect = (typeof KNOWN_DIALECTS_ARRAY)[number];
@@ -80,6 +83,7 @@ export function guessDialect(
return SQLite;
case "mssql":
case "sqlserver":
+ case "microsoft sql server":
return MSSQL;
case "duckdb":
return DuckDBDialect;
@@ -109,6 +113,8 @@ export function guessDialect(
case "tidb":
case "singlestoredb":
case "spark":
+ case "databricks":
+ case "datafusion":
Logger.debug("Unsupported dialect", { dialect });
return ModifiedStandardSQL;
default:
diff --git a/marimo/_sql/engines/adbc.py b/marimo/_sql/engines/adbc.py
new file mode 100644
index 0000000000..385bb7c8de
--- /dev/null
+++ b/marimo/_sql/engines/adbc.py
@@ -0,0 +1,532 @@
+# Copyright 2026 Marimo. All rights reserved.
+from __future__ import annotations
+
+from types import ModuleType
+from typing import TYPE_CHECKING, Any, Literal, Optional, Protocol, Union, cast
+
+from marimo import _loggers
+from marimo._data.models import (
+ Database,
+ DataTable,
+ DataTableColumn,
+ DataTableType,
+ DataType,
+ Schema,
+)
+from marimo._sql.engines.types import InferenceConfig, SQLConnection
+from marimo._sql.utils import CHEAP_DISCOVERY_DATABASES, convert_to_output
+from marimo._types.ids import VariableName
+
+LOGGER = _loggers.marimo_logger()
+
+if TYPE_CHECKING:
+ from collections.abc import Sequence
+
+ import pandas as pd
+ import polars as pl
+ import pyarrow as pa
+
+AdbcGetObjectsDepth = Literal[
+ "all", "catalogs", "db_schemas", "tables", "columns"
+]
+
+
+class AdbcDbApiCursor(Protocol):
+ description: Any
+
+ def execute(
+ self, query: str, parameters: Sequence[Any] = ...
+ ) -> AdbcDbApiCursor: ...
+
+ def fetch_arrow_table(self) -> pa.Table: ...
+
+ def close(self) -> None: ...
+
+
+class AdbcDbApiConnection(Protocol):
+ """ADBC DB-API wrapper connection.
+
+ For the canonical DB-API types/signatures, see:
+ https://arrow.apache.org/adbc/current/python/api/adbc_driver_manager.html#adbc_driver_manager.dbapi.Connection
+ """
+
+ def cursor(self) -> AdbcDbApiCursor: ...
+
+ def commit(self) -> None: ...
+
+ def rollback(self) -> None: ...
+
+ def close(self) -> None: ...
+
+ adbc_current_catalog: str
+ adbc_current_db_schema: str
+
+ def adbc_get_objects(
+ self,
+ *,
+ depth: AdbcGetObjectsDepth = "all",
+ catalog_filter: str | None = None,
+ db_schema_filter: str | None = None,
+ table_name_filter: str | None = None,
+ table_types_filter: list[str] | None = None,
+ column_name_filter: str | None = None,
+ ) -> pa.RecordBatchReader: ...
+
+ def adbc_get_table_schema(
+ self, table_name: str, *, db_schema_filter: str | None = None
+ ) -> pa.Schema: ...
+
+ def adbc_get_info(self) -> dict[str | int, Any]: ...
+
+
+def _resolve_table_type(table_type: str) -> DataTableType:
+ if "view" in table_type.lower():
+ return "view"
+ return "table"
+
+
+def _adbc_info_to_dialect(*, info: dict[str | int, Any]) -> str:
+ """Infer marimo's dialect identifier from ADBC metadata.
+
+ Notes:
+ ADBC DB-API wrappers expose driver/database metadata via ``adbc_get_info()``,
+ including a ``vendor_name`` and ``driver_name`` (see ADBC quickstart:
+ https://arrow.apache.org/adbc/current/python/quickstart.html).
+
+ In marimo, ``engine.dialect`` is used primarily for editor/formatter dialect
+ selection and for display in the UI.
+ """
+
+ vendor_name = info.get("vendor_name")
+ vendor = vendor_name if isinstance(vendor_name, str) else None
+
+ if vendor is not None and vendor.strip():
+ return vendor.strip().lower()
+
+ return "sql"
+
+
+def _schema_field_to_data_type(external_type: str) -> DataType:
+ """Map an Arrow-like dtype string to marimo DataType."""
+ t = external_type.lower()
+ if "bool" in t:
+ return "boolean"
+ if "int" in t or "uint" in t:
+ return "integer"
+ if "float" in t or "double" in t or "decimal" in t:
+ return "number"
+ if "timestamp" in t:
+ return "datetime"
+ if t.startswith("date") or " date" in t:
+ return "date"
+ if t.startswith("time") or " time" in t:
+ return "time"
+ return "string"
+
+
+class AdbcConnectionCatalog:
+ """Catalog implementation backed by ADBC DB-API wrapper extensions."""
+
+ def __init__(
+ self,
+ *,
+ adbc_connection: AdbcDbApiConnection,
+ dialect: str,
+ engine_name: Optional[VariableName],
+ ) -> None:
+ self._adbc_connection = adbc_connection
+ self._dialect = dialect
+ self._engine_name = engine_name
+
+ def get_default_database(self) -> Optional[str]:
+ try:
+ return self._adbc_connection.adbc_current_catalog
+ except Exception:
+ # Some drivers (like arrow-adbc-driver-sqlite) do not support the standardized option for current
+ # catalog/schema; treat as unavailable.
+ LOGGER.debug("Failed to read ADBC current catalog", exc_info=True)
+ return None
+
+ def get_default_schema(self) -> Optional[str]:
+ try:
+ return self._adbc_connection.adbc_current_db_schema
+ except Exception:
+ LOGGER.debug("Failed to read ADBC current schema", exc_info=True)
+ return None
+
+ def _resolve_should_auto_discover(
+ self, value: Union[bool, Literal["auto"]]
+ ) -> bool:
+ if value == "auto":
+ return self._dialect.lower() in CHEAP_DISCOVERY_DATABASES
+ return value
+
+ def get_databases(
+ self,
+ *,
+ include_schemas: Union[bool, Literal["auto"]],
+ include_tables: Union[bool, Literal["auto"]],
+ include_table_details: Union[bool, Literal["auto"]],
+ ) -> list[Database]:
+ databases: list[Database] = []
+ include_schemas_bool = self._resolve_should_auto_discover(
+ include_schemas
+ )
+ include_tables_bool = self._resolve_should_auto_discover(
+ include_tables
+ )
+ include_table_details_bool = self._resolve_should_auto_discover(
+ include_table_details
+ )
+ if not include_schemas_bool:
+ include_tables_bool = False
+ if not include_tables_bool:
+ include_table_details_bool = False
+
+ depth: AdbcGetObjectsDepth
+ if not include_schemas_bool:
+ depth = "catalogs"
+ elif not include_tables_bool:
+ depth = "db_schemas"
+ else:
+ depth = "tables"
+
+ objects_pylist = (
+ self._adbc_connection.adbc_get_objects(depth=depth)
+ .read_all()
+ .to_pylist()
+ )
+
+ for catalog_row in objects_pylist:
+ catalog_name_obj = catalog_row.get("catalog_name")
+ catalog_name = (
+ "" if catalog_name_obj is None else str(catalog_name_obj)
+ )
+
+ schemas: list[Schema] = []
+ if include_schemas_bool:
+ schema_rows = catalog_row.get("catalog_db_schemas") or []
+ for schema_row in schema_rows:
+ schema_name_obj = schema_row.get("db_schema_name")
+ schema_name = (
+ "" if schema_name_obj is None else str(schema_name_obj)
+ )
+
+ tables: list[DataTable] = []
+ if include_tables_bool:
+ table_rows = schema_row.get("db_schema_tables") or []
+ for table_row in table_rows:
+ table_name_obj = table_row.get("table_name")
+ if table_name_obj is None:
+ continue
+ table_name = str(table_name_obj)
+ table_type_obj = (
+ table_row.get("table_type") or "TABLE"
+ )
+ table_type = str(table_type_obj)
+
+ if include_table_details_bool:
+ details = self.get_table_details(
+ table_name=table_name,
+ schema_name=schema_name,
+ database_name=catalog_name,
+ )
+ if details is not None:
+ details.type = _resolve_table_type(
+ table_type
+ )
+ tables.append(details)
+ else:
+ tables.append(
+ DataTable(
+ source_type="connection",
+ source=self._dialect,
+ name=table_name,
+ num_rows=None,
+ num_columns=None,
+ variable_name=None,
+ engine=self._engine_name,
+ type=_resolve_table_type(table_type),
+ columns=[],
+ primary_keys=[],
+ indexes=[],
+ )
+ )
+
+ schemas.append(Schema(name=schema_name, tables=tables))
+
+ databases.append(
+ Database(
+ name=catalog_name,
+ dialect=self._dialect,
+ schemas=schemas,
+ engine=self._engine_name,
+ )
+ )
+
+ return databases
+
+ def get_tables_in_schema(
+ self, *, schema: str, database: str, include_table_details: bool
+ ) -> list[DataTable]:
+ tables: list[DataTable] = []
+ objects_pylist = (
+ self._adbc_connection.adbc_get_objects(
+ depth="tables",
+ catalog_filter=database or None,
+ db_schema_filter=schema or None,
+ )
+ .read_all()
+ .to_pylist()
+ )
+
+ for catalog_row in objects_pylist:
+ schema_rows = catalog_row.get("catalog_db_schemas") or []
+ for schema_row in schema_rows:
+ table_rows = schema_row.get("db_schema_tables") or []
+ for table_row in table_rows:
+ table_name_obj = table_row.get("table_name")
+ if table_name_obj is None:
+ continue
+ table_name = str(table_name_obj)
+ table_type_obj = table_row.get("table_type") or "TABLE"
+ table_type = str(table_type_obj)
+
+ if include_table_details:
+ details = self.get_table_details(
+ table_name=table_name,
+ schema_name=schema,
+ database_name=database,
+ )
+ if details is not None:
+ details.type = _resolve_table_type(table_type)
+ tables.append(details)
+ else:
+ tables.append(
+ DataTable(
+ source_type="connection",
+ source=self._dialect,
+ name=table_name,
+ num_rows=None,
+ num_columns=None,
+ variable_name=None,
+ engine=self._engine_name,
+ type=_resolve_table_type(table_type),
+ columns=[],
+ primary_keys=[],
+ indexes=[],
+ )
+ )
+ return tables
+
+ def get_table_details(
+ self, *, table_name: str, schema_name: str, database_name: str
+ ) -> Optional[DataTable]:
+ _ = database_name
+ try:
+ schema = self._adbc_connection.adbc_get_table_schema(
+ table_name, db_schema_filter=schema_name or None
+ )
+ except Exception:
+ LOGGER.warning(
+ "Failed to get table schema for %s.%s.%s",
+ database_name,
+ schema_name,
+ table_name,
+ exc_info=True,
+ )
+ return None
+
+ cols: list[DataTableColumn] = []
+ try:
+ for field in cast(Any, schema):
+ external_type = str(getattr(field, "type", "string"))
+ cols.append(
+ DataTableColumn(
+ name=str(getattr(field, "name", "")),
+ type=_schema_field_to_data_type(external_type),
+ external_type=external_type,
+ sample_values=[],
+ )
+ )
+ except Exception:
+ LOGGER.warning("Failed to parse ADBC table schema", exc_info=True)
+ cols = []
+
+ return DataTable(
+ source_type="connection",
+ source=self._dialect,
+ name=table_name,
+ num_rows=None,
+ num_columns=len(cols) if cols else None,
+ variable_name=None,
+ engine=self._engine_name,
+ columns=cols,
+ primary_keys=[],
+ indexes=[],
+ )
+
+
+class AdbcDBAPIEngine(SQLConnection[AdbcDbApiConnection]):
+ """ADBC DB-API wrapper connection."""
+
+ def __init__(
+ self,
+ connection: AdbcDbApiConnection,
+ engine_name: Optional[VariableName] = None,
+ ) -> None:
+ super().__init__(connection, engine_name)
+ self._catalog = AdbcConnectionCatalog(
+ adbc_connection=self._connection,
+ dialect=self.dialect,
+ engine_name=self._engine_name,
+ )
+
+ @property
+ def source(self) -> str:
+ return "adbc"
+
+ @property
+ def dialect(self) -> str:
+ try:
+ info = self._connection.adbc_get_info()
+ if isinstance(info, dict):
+ return _adbc_info_to_dialect(info=info)
+ except Exception:
+ LOGGER.debug("Failed to read ADBC driver metadata", exc_info=True)
+ return "sql"
+
+ @staticmethod
+ def is_compatible(var: Any) -> bool:
+ if isinstance(var, ModuleType):
+ return False
+
+ try:
+ # First, validate the connection-level surface area to avoid
+ # accidentally classifying regular DB-API connections as ADBC.
+ required_connection_methods = (
+ "cursor",
+ "commit",
+ "rollback",
+ "close",
+ # ADBC DB-API extension methods.
+ "adbc_get_objects",
+ "adbc_get_table_schema",
+ "adbc_get_info",
+ )
+ if not all(
+ callable(getattr(var, method, None))
+ for method in required_connection_methods
+ ):
+ return False
+
+ # Then, validate the cursor shape (ADBC-specific).
+ # We do not execute queries; we also best-effort close the cursor
+ # to avoid leaking resources during compatibility checks.
+ cursor = var.cursor()
+ try:
+ required_cursor_methods = ("execute", "fetch_arrow_table")
+ return all(
+ callable(getattr(cursor, method, None))
+ for method in required_cursor_methods
+ )
+ finally:
+ # Never fail compatibility checks due to close errors
+ try:
+ cursor.close()
+ except Exception:
+ LOGGER.debug(
+ "Failed to close cursor during ADBC compatibility check",
+ exc_info=True,
+ )
+ except Exception:
+ LOGGER.debug("ADBC compatibility check failed", exc_info=True)
+ return False
+
+ @property
+ def inference_config(self) -> InferenceConfig:
+ return InferenceConfig(
+ auto_discover_schemas=True,
+ auto_discover_tables="auto",
+ auto_discover_columns=False,
+ )
+
+ def get_default_database(self) -> Optional[str]:
+ return self._catalog.get_default_database()
+
+ def get_default_schema(self) -> Optional[str]:
+ return self._catalog.get_default_schema()
+
+ def get_databases(
+ self,
+ *,
+ include_schemas: Union[bool, Literal["auto"]],
+ include_tables: Union[bool, Literal["auto"]],
+ include_table_details: Union[bool, Literal["auto"]],
+ ) -> list[Database]:
+ return self._catalog.get_databases(
+ include_schemas=include_schemas,
+ include_tables=include_tables,
+ include_table_details=include_table_details,
+ )
+
+ def get_tables_in_schema(
+ self, *, schema: str, database: str, include_table_details: bool
+ ) -> list[DataTable]:
+ return self._catalog.get_tables_in_schema(
+ schema=schema,
+ database=database,
+ include_table_details=include_table_details,
+ )
+
+ def get_table_details(
+ self, *, table_name: str, schema_name: str, database_name: str
+ ) -> Optional[DataTable]:
+ return self._catalog.get_table_details(
+ table_name=table_name,
+ schema_name=schema_name,
+ database_name=database_name,
+ )
+
+ def execute(
+ self, query: str, parameters: Optional[Sequence[Any]] = None
+ ) -> Any:
+ sql_output_format = self.sql_output_format()
+ cursor = self._connection.cursor()
+
+ def _try_commit() -> None:
+ try:
+ self._connection.commit()
+ except Exception:
+ LOGGER.info("Unable to commit transaction", exc_info=True)
+
+ try:
+ cursor.execute(query, parameters or ())
+
+ if not getattr(cursor, "description", None):
+ _try_commit()
+ return None
+
+ arrow_table = cursor.fetch_arrow_table()
+
+ def convert_to_polars() -> pl.DataFrame | pl.Series:
+ import polars as pl
+
+ return pl.from_arrow(arrow_table)
+
+ def convert_to_pandas() -> pd.DataFrame:
+ return arrow_table.to_pandas()
+
+ result = convert_to_output(
+ sql_output_format=sql_output_format,
+ to_polars=convert_to_polars,
+ to_pandas=convert_to_pandas,
+ to_native=lambda: arrow_table,
+ )
+ _try_commit()
+ return result
+ finally:
+ try:
+ cursor.close()
+ except Exception:
+ LOGGER.info("Failed to close cursor", exc_info=True)
diff --git a/marimo/_sql/engines/doc.md b/marimo/_sql/engines/doc.md
index 13cbb58fcb..ed2e25bcbc 100644
--- a/marimo/_sql/engines/doc.md
+++ b/marimo/_sql/engines/doc.md
@@ -49,6 +49,7 @@ Examples of just the query operations:
Examples of both catalog and query operations:
+- Any Arrow Database Connectivity (ADBC) DB-API Driver
- SQLAlchemy/SQLModel
- DuckDB
- Clickhouse
diff --git a/marimo/_sql/get_engines.py b/marimo/_sql/get_engines.py
index 713a699d8f..7ddcdb23e9 100644
--- a/marimo/_sql/get_engines.py
+++ b/marimo/_sql/get_engines.py
@@ -11,6 +11,7 @@ from marimo._runtime.context.types import (
ContextNotInitializedError,
get_context,
)
+from marimo._sql.engines.adbc import AdbcDBAPIEngine
from marimo._sql.engines.clickhouse import (
ClickhouseEmbedded,
ClickhouseServer,
@@ -39,6 +40,7 @@ SUPPORTED_ENGINES: list[type[BaseEngine[Any]]] = [
ClickhouseServer,
PyIcebergEngine,
RedshiftEngine,
+ AdbcDBAPIEngine,
DBAPIEngine,
]
diff --git a/marimo/_sql/sql.py b/marimo/_sql/sql.py
index 957db5d00d..a600aaf95f 100644
--- a/marimo/_sql/sql.py
+++ b/marimo/_sql/sql.py
@@ -40,14 +40,17 @@ def sql(
By default, this uses duckdb to execute the query. Any dataframes in the global
namespace can be used inside the query.
- You can also pass a custom engine to execute queries against other databases. The custom engine must be a DBAPI 2.0 compatible engine.
+ You can also pass a custom engine to execute queries against other databases.
+ The custom engine can be a DB-API 2.0 compatible connection (PEP 249), including
+ DB-API wrappers provided by ADBC drivers.
The result of the query is displayed in the UI if output is True.
Args:
query: The SQL query to execute.
output: Whether to display the result in the UI. Defaults to True.
- engine: Optional SQL engine to use. Can be a SQLAlchemy, DuckDB, Clickhouse, Redshift, Ibis, or DBAPI 2.0 compatible engine.
+ engine: Optional SQL engine to use. Can be a SQLAlchemy, DuckDB, Clickhouse,
+ Redshift, Ibis, or DB-API 2.0 compatible connection (including ADBC drivers).
If None, uses DuckDB.
Returns:
diff --git a/pixi.lock b/pixi.lock
index 44423a7696..4b5ee84fb9 100644
--- a/pixi.lock
+++ b/pixi.lock
@@ -1133,7 +1133,7 @@ packages:
- pypi: ./
name: marimo
version: 0.18.4
- sha256: 64534d3c58bd4c81fc84e6f6b7afb039e1d1eee5b8e3ae047b9421d3be87363a
+ sha256: 00d04a9c700e085afe77f6f44d2455742a7247499a2022ef89fe8f9c04858e5d
requires_dist:
- click>=8.0,<9
- jedi>=0.18.0
@@ -1166,7 +1166,6 @@ packages:
- mcp>=1.0.0 ; extra == 'mcp'
- pydantic>2 ; extra == 'mcp'
requires_python: '>=3.10'
- editable: true
- pypi: https://files.pythonhosted.org/packages/70/81/54e3ce63502cd085a0c556652a4e1b919c45a446bd1e5300e10c44c8c521/markdown-3.10-py3-none-any.whl
name: markdown
version: '3.10'
diff --git a/pyproject.toml b/pyproject.toml
index ab8b50005f..10647b4497 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -117,6 +117,8 @@ dev = [
# For SQL
"duckdb>=1.0.0",
"sqlglot[rs]>=26.2.0",
+ # Stubs for optional dataframe backends
+ "pyarrow-stubs",
# For linting
"ruff>=0.13.2",
# For AI
@@ -200,6 +202,7 @@ dependencies = [
"mcp>=1.0.0",
# zeromq
"pyzmq>=27.1.0",
+ "pyarrow-stubs",
]
[tool.hatch.envs.typecheck.scripts]
@@ -232,6 +235,9 @@ test-narwhals = """
template = "test"
dependency-groups = ["dev", "test"]
extra-dependencies = [
+ # For testing ADBC driver-based SQL connections
+ "adbc_driver_manager",
+ "adbc_driver_sqlite",
"python-lsp-server>=1.10.0",
# For testing mo.ui.chart, table, ...
"vl-convert-python",
@@ -291,7 +297,7 @@ dependencies = [
"mkdocs-material==9.6.20",
"mkdocstrings[python]>=0.27.0",
"mkdocs-material-extensions>=1.3.1",
- "mkdocs-autorefs>=1.2.0",
+ "mkdocs-autorefs>=1.2.2",
"mkdocs-git-revision-date-localized-plugin>=1.3.0",
"mkdocs-minify-plugin>=0.8.0",
"mkdocs-glightbox>=0.4.0",
diff --git a/tests/_plugins/ui/_impl/test_table.py b/tests/_plugins/ui/_impl/test_table.py
index f2bb61e1e5..82d53d52f9 100644
--- a/tests/_plugins/ui/_impl/test_table.py
+++ b/tests/_plugins/ui/_impl/test_table.py
@@ -1284,6 +1284,14 @@ def test_download_as(df: Any) -> None:
import polars as pl
return pl.read_json(buffer)
+ elif DependencyManager.pyarrow.has():
+ import json
+
+ import pyarrow as pa
+
+ rows = json.loads(data_bytes)
+ assert isinstance(rows, list)
+ return pa.Table.from_pylist(rows)
elif format_type == "parquet":
if DependencyManager.pandas.has():
import pandas as pd
@@ -1293,6 +1301,10 @@ def test_download_as(df: Any) -> None:
import polars as pl
return pl.read_parquet(buffer)
+ elif DependencyManager.pyarrow.has():
+ import pyarrow.parquet as pq
+
+ return pq.read_table(buffer)
elif format_type == "csv":
if DependencyManager.pandas.has():
import pandas as pd
@@ -1302,6 +1314,10 @@ def test_download_as(df: Any) -> None:
import polars as pl
return pl.read_csv(buffer)
+ elif DependencyManager.pyarrow.has():
+ import pyarrow.csv as pacsv
+
+ return pacsv.read_csv(buffer)
raise ValueError(f"Unsupported format: {format_type}")
# Test base downloads (full data)
diff --git a/tests/_sql/test_adbc.py b/tests/_sql/test_adbc.py
new file mode 100644
index 0000000000..aa307fa7eb
--- /dev/null
+++ b/tests/_sql/test_adbc.py
@@ -0,0 +1,849 @@
+# Copyright 2026 Marimo. All rights reserved.
+from __future__ import annotations
+
+from dataclasses import dataclass
+from typing import TYPE_CHECKING, Any, cast
+
+import pytest
+
+from marimo._data.models import Database, DataTable, Schema
+from marimo._sql.engines.adbc import (
+ AdbcConnectionCatalog,
+ AdbcDBAPIEngine,
+ _adbc_info_to_dialect,
+)
+from marimo._sql.get_engines import get_engines_from_variables
+from marimo._types.ids import VariableName
+
+if TYPE_CHECKING:
+ from collections.abc import Iterator, Sequence
+
+ import pyarrow as pa
+
+
+@dataclass
+class FakeAdbcSchemaField:
+ name: str
+ type: str
+
+
+class FakeAdbcTableSchema:
+ def __init__(self, fields: list[FakeAdbcSchemaField]) -> None:
+ self._fields = fields
+
+ def __iter__(self) -> Iterator[FakeAdbcSchemaField]:
+ return iter(self._fields)
+
+
+class FakeAdbcObjectsTable:
+ def __init__(self, pylist: list[dict[str, Any]]) -> None:
+ self._pylist = pylist
+
+ def to_pylist(self) -> list[dict[str, Any]]:
+ return self._pylist
+
+
+class FakeAdbcObjectsReader:
+ def __init__(self, pylist: list[dict[str, Any]]) -> None:
+ self._table = FakeAdbcObjectsTable(pylist)
+
+ def read_all(self) -> FakeAdbcObjectsTable:
+ return self._table
+
+
+class FakeAdbcDbApiCursor:
+ def __init__(
+ self,
+ *,
+ description: list[tuple[str, Any]] | None,
+ arrow_table: pa.Table | None = None,
+ ) -> None:
+ self.description = description
+ self._arrow_table: pa.Table | None = arrow_table
+ self.did_execute = False
+ self.did_fetch_arrow = False
+ self.did_close = False
+
+ def execute(
+ self, query: str, parameters: Sequence[Any] = ()
+ ) -> FakeAdbcDbApiCursor:
+ _ = query, parameters
+ self.did_execute = True
+ return self
+
+ def fetch_arrow_table(self) -> pa.Table:
+ self.did_fetch_arrow = True
+ assert self._arrow_table is not None
+ return self._arrow_table
+
+ def close(self) -> None:
+ self.did_close = True
+
+
+class FakeAdbcDbApiConnection:
+ adbc_current_catalog: str
+ adbc_current_db_schema: str
+
+ def __init__(
+ self,
+ *,
+ cursor: FakeAdbcDbApiCursor,
+ objects_pylist: list[dict[str, Any]],
+ table_schema: FakeAdbcTableSchema,
+ ) -> None:
+ self._cursor = cursor
+ self._objects_pylist = objects_pylist
+ self._table_schema = table_schema
+ self.did_commit = False
+ self.did_rollback = False
+ self.did_close = False
+ self.dialect = "postgresql"
+ self.adbc_current_catalog = "db1"
+ self.adbc_current_db_schema = "public"
+ self.did_create_cursor = False
+ self.last_get_objects_kwargs: dict[str, Any] | None = None
+ self.adbc_get_info_calls = 0
+
+ def cursor(self) -> FakeAdbcDbApiCursor:
+ self.did_create_cursor = True
+ return self._cursor
+
+ def commit(self) -> None:
+ self.did_commit = True
+
+ def rollback(self) -> None:
+ self.did_rollback = True
+
+ def close(self) -> None:
+ self.did_close = True
+
+ # ADBC DB-API extension methods
+ def adbc_get_objects(
+ self,
+ *,
+ depth: str = "all",
+ catalog_filter: str | None = None,
+ db_schema_filter: str | None = None,
+ table_name_filter: str | None = None,
+ table_types_filter: list[str] | None = None,
+ column_name_filter: str | None = None,
+ ) -> pa.RecordBatchReader:
+ self.last_get_objects_kwargs = {
+ "depth": depth,
+ "catalog_filter": catalog_filter,
+ "db_schema_filter": db_schema_filter,
+ "table_name_filter": table_name_filter,
+ "table_types_filter": table_types_filter,
+ "column_name_filter": column_name_filter,
+ }
+
+ catalogs: list[dict[str, Any]] = []
+ for catalog_row in self._objects_pylist:
+ catalog_name_obj = catalog_row.get("catalog_name")
+ catalog_name = (
+ "" if catalog_name_obj is None else str(catalog_name_obj)
+ )
+ if catalog_filter is not None and catalog_name != catalog_filter:
+ continue
+
+ next_catalog_row: dict[str, Any] = dict(catalog_row)
+ if depth == "catalogs":
+ next_catalog_row["catalog_db_schemas"] = []
+ catalogs.append(next_catalog_row)
+ continue
+
+ schemas = catalog_row.get("catalog_db_schemas") or []
+ next_schemas: list[dict[str, Any]] = []
+ for schema_row in schemas:
+ schema_name_obj = schema_row.get("db_schema_name")
+ schema_name = (
+ "" if schema_name_obj is None else str(schema_name_obj)
+ )
+ if (
+ db_schema_filter is not None
+ and schema_name != db_schema_filter
+ ):
+ continue
+
+ next_schema_row: dict[str, Any] = dict(schema_row)
+ if depth == "db_schemas":
+ next_schema_row["db_schema_tables"] = []
+ next_schemas.append(next_schema_row)
+ continue
+
+ tables = schema_row.get("db_schema_tables") or []
+ next_tables: list[dict[str, Any]] = []
+ for table_row in tables:
+ table_name_obj = table_row.get("table_name")
+ if table_name_obj is None:
+ continue
+ table_name = str(table_name_obj)
+ if (
+ table_name_filter is not None
+ and table_name != table_name_filter
+ ):
+ continue
+
+ table_type_obj = table_row.get("table_type")
+ table_type = (
+ "" if table_type_obj is None else str(table_type_obj)
+ )
+ if (
+ table_types_filter is not None
+ and table_type not in table_types_filter
+ ):
+ continue
+
+ next_tables.append(dict(table_row))
+
+ next_schema_row["db_schema_tables"] = next_tables
+ next_schemas.append(next_schema_row)
+
+ next_catalog_row["catalog_db_schemas"] = next_schemas
+ catalogs.append(next_catalog_row)
+
+ # ADBC DB-API wrapper returns a pyarrow.RecordBatchReader; our fake
+ # emulates the reader's `read_all().to_pylist()` interface.
+ return cast(Any, FakeAdbcObjectsReader(catalogs))
+
+ def adbc_get_table_schema(
+ self, table_name: str, *, db_schema_filter: str | None = None
+ ) -> pa.Schema:
+ _ = table_name, db_schema_filter
+ return cast(Any, self._table_schema)
+
+ def adbc_get_info(self) -> dict[str | int, Any]:
+ self.adbc_get_info_calls += 1
+ return cast(dict[str | int, Any], {"vendor_name": "PostgreSQL"})
+
+
+def test_adbc_info_to_dialect() -> None:
+ # Vendor string is lowercased (and stripped); driver_name is ignored.
+ assert (
+ _adbc_info_to_dialect(
+ info={"vendor_name": "PostgreSQL", "driver_name": "SQLite"}
+ )
+ == "postgresql"
+ )
+ assert (
+ _adbc_info_to_dialect(info={"vendor_name": "Microsoft SQL Server"})
+ == "microsoft sql server"
+ )
+
+ # Missing/blank/non-string vendor_name falls back to "sql".
+ assert _adbc_info_to_dialect(info={"vendor_name": " "}) == "sql"
+ assert _adbc_info_to_dialect(info={"vendor_name": 123}) == "sql"
+ assert _adbc_info_to_dialect(info={"driver_name": "AcmeDB"}) == "sql"
+ assert _adbc_info_to_dialect(info={}) == "sql"
+
+
+def test_get_engines_from_variables_prefers_adbc_dbapi_engine() -> None:
+ conn = FakeAdbcDbApiConnection(
+ cursor=FakeAdbcDbApiCursor(description=None),
+ objects_pylist=[],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+
+ engines = get_engines_from_variables([(VariableName("conn"), conn)])
+ assert len(engines) == 1
+ _, engine = engines[0]
+ assert isinstance(engine, AdbcDBAPIEngine)
+
+
+def test_adbc_catalog_parses_adbc_get_objects() -> None:
+ objects_pylist = [
+ {
+ "catalog_name": "db1",
+ "catalog_db_schemas": [
+ {
+ "db_schema_name": "public",
+ "db_schema_tables": [
+ {"table_name": "t1", "table_type": "TABLE"},
+ {"table_name": "v1", "table_type": "VIEW"},
+ ],
+ }
+ ],
+ }
+ ]
+ conn = FakeAdbcDbApiConnection(
+ cursor=FakeAdbcDbApiCursor(description=None),
+ objects_pylist=objects_pylist,
+ table_schema=FakeAdbcTableSchema(
+ [
+ FakeAdbcSchemaField(name="id", type="int64"),
+ FakeAdbcSchemaField(name="name", type="utf8"),
+ ]
+ ),
+ )
+
+ engine = AdbcDBAPIEngine(conn, engine_name=VariableName("adbc_conn"))
+ databases = engine.get_databases(
+ include_schemas=True,
+ include_tables=True,
+ include_table_details=False,
+ )
+ assert conn.last_get_objects_kwargs is not None
+ assert conn.last_get_objects_kwargs["depth"] == "tables"
+
+ assert databases == [
+ Database(
+ name="db1",
+ dialect="postgresql",
+ engine=VariableName("adbc_conn"),
+ schemas=[
+ Schema(
+ name="public",
+ tables=[
+ DataTable(
+ source_type="connection",
+ source="postgresql",
+ name="t1",
+ num_rows=None,
+ num_columns=None,
+ variable_name=None,
+ engine=VariableName("adbc_conn"),
+ type="table",
+ columns=[],
+ primary_keys=[],
+ indexes=[],
+ ),
+ DataTable(
+ source_type="connection",
+ source="postgresql",
+ name="v1",
+ num_rows=None,
+ num_columns=None,
+ variable_name=None,
+ engine=VariableName("adbc_conn"),
+ type="view",
+ columns=[],
+ primary_keys=[],
+ indexes=[],
+ ),
+ ],
+ )
+ ],
+ )
+ ]
+
+
+def test_adbc_execute_prefers_arrow_fetch(monkeypatch) -> None:
+ sentinel_result = object()
+
+ def fake_convert_to_output(*args: Any, **kwargs: Any) -> Any:
+ _ = args, kwargs
+ return sentinel_result
+
+ monkeypatch.setattr(
+ "marimo._sql.engines.adbc.convert_to_output", fake_convert_to_output
+ )
+
+ cursor = FakeAdbcDbApiCursor(
+ description=[("col", None)],
+ arrow_table=cast("pa.Table", object()),
+ )
+ conn = FakeAdbcDbApiConnection(
+ cursor=cursor,
+ objects_pylist=[],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+ engine = AdbcDBAPIEngine(conn)
+
+ monkeypatch.setattr(engine, "sql_output_format", lambda: "auto")
+ result = engine.execute("SELECT 1")
+
+ assert result is sentinel_result
+ assert cursor.did_fetch_arrow is True
+ assert conn.did_commit is True
+ assert cursor.did_close is True
+
+
+def test_adbc_execute_native_returns_arrow_table(monkeypatch) -> None:
+ arrow_table = cast("pa.Table", object())
+ cursor = FakeAdbcDbApiCursor(
+ description=[("col", None)], arrow_table=arrow_table
+ )
+ conn = FakeAdbcDbApiConnection(
+ cursor=cursor,
+ objects_pylist=[],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+ engine = AdbcDBAPIEngine(conn)
+
+ monkeypatch.setattr(engine, "sql_output_format", lambda: "native")
+ result = engine.execute("SELECT 1")
+
+ assert result is arrow_table
+ assert cursor.did_execute is True
+ assert cursor.did_fetch_arrow is True
+ assert conn.did_commit is True
+ assert cursor.did_close is True
+
+
+def test_adbc_is_compatible_does_not_create_cursor() -> None:
+ conn = FakeAdbcDbApiConnection(
+ cursor=FakeAdbcDbApiCursor(description=None),
+ objects_pylist=[],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+ # is_compatible() validates cursor shape; it should not execute or fetch.
+ assert AdbcDBAPIEngine.is_compatible(conn) is True
+ assert conn.did_create_cursor is True
+ assert conn._cursor.did_execute is False # type: ignore[attr-defined]
+ assert conn._cursor.did_fetch_arrow is False # type: ignore[attr-defined]
+ assert conn._cursor.did_close is True # type: ignore[attr-defined]
+
+
+def test_adbc_catalog_auto_discovery_uses_cheap_dialect_heuristic() -> None:
+ conn = FakeAdbcDbApiConnection(
+ cursor=FakeAdbcDbApiCursor(description=None),
+ objects_pylist=[],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+ cheap = AdbcConnectionCatalog(
+ adbc_connection=conn,
+ dialect="sqlite",
+ engine_name=None,
+ )
+ assert cheap._resolve_should_auto_discover("auto") is True
+ assert cheap._resolve_should_auto_discover(True) is True
+ assert cheap._resolve_should_auto_discover(False) is False
+
+ expensive = AdbcConnectionCatalog(
+ adbc_connection=conn,
+ dialect="snowflake",
+ engine_name=None,
+ )
+ assert expensive._resolve_should_auto_discover("auto") is False
+
+
+def test_adbc_catalog_get_databases_uses_depth_catalogs_when_no_schemas() -> (
+ None
+):
+ conn = FakeAdbcDbApiConnection(
+ cursor=FakeAdbcDbApiCursor(description=None),
+ objects_pylist=[
+ {
+ "catalog_name": "db1",
+ "catalog_db_schemas": [
+ {"db_schema_name": "public", "db_schema_tables": []}
+ ],
+ },
+ {"catalog_name": "db2", "catalog_db_schemas": []},
+ ],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+ engine = AdbcDBAPIEngine(conn)
+ databases = engine.get_databases(
+ include_schemas=False,
+ include_tables=True,
+ include_table_details=True,
+ )
+ assert conn.last_get_objects_kwargs is not None
+ assert conn.last_get_objects_kwargs["depth"] == "catalogs"
+ assert [db.name for db in databases] == ["db1", "db2"]
+ assert [db.schemas for db in databases] == [[], []]
+
+
+def test_adbc_catalog_get_databases_uses_depth_db_schemas_when_no_tables() -> (
+ None
+):
+ conn = FakeAdbcDbApiConnection(
+ cursor=FakeAdbcDbApiCursor(description=None),
+ objects_pylist=[
+ {
+ "catalog_name": "db1",
+ "catalog_db_schemas": [
+ {"db_schema_name": "public", "db_schema_tables": []},
+ {"db_schema_name": "empty", "db_schema_tables": []},
+ ],
+ }
+ ],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+ engine = AdbcDBAPIEngine(conn)
+ databases = engine.get_databases(
+ include_schemas=True,
+ include_tables=False,
+ include_table_details=False,
+ )
+ assert conn.last_get_objects_kwargs is not None
+ assert conn.last_get_objects_kwargs["depth"] == "db_schemas"
+ assert [s.name for s in databases[0].schemas] == ["public", "empty"]
+ assert [s.tables for s in databases[0].schemas] == [[], []]
+
+
+def test_adbc_get_tables_in_schema_passes_filters() -> None:
+ conn = FakeAdbcDbApiConnection(
+ cursor=FakeAdbcDbApiCursor(description=None),
+ objects_pylist=[
+ {
+ "catalog_name": "db1",
+ "catalog_db_schemas": [
+ {
+ "db_schema_name": "public",
+ "db_schema_tables": [
+ {"table_name": "t1", "table_type": "TABLE"}
+ ],
+ },
+ {
+ "db_schema_name": "other",
+ "db_schema_tables": [
+ {"table_name": "t2", "table_type": "TABLE"}
+ ],
+ },
+ ],
+ },
+ {
+ "catalog_name": "db2",
+ "catalog_db_schemas": [
+ {
+ "db_schema_name": "public",
+ "db_schema_tables": [
+ {"table_name": "t3", "table_type": "TABLE"}
+ ],
+ }
+ ],
+ },
+ ],
+ table_schema=FakeAdbcTableSchema([]),
+ )
+ engine = AdbcDBAPIEngine(conn)
+ tables = engine.get_tables_in_schema(
+ schema="public", database="db1", include_table_details=False
+ )
+ assert conn.last_get_objects_kwargs is not None
+ assert conn.last_get_objects_kwargs["depth"] == "tables"
+ assert conn.last_get_objects_kwargs["catalog_filter"] == "db1"
+ assert conn.last_get_objects_kwargs["db_schema_filter"] == "public"
+ assert [t.name for t in tables] == ["t1"]
+
+
+def _find_table_location(
+ *, databases: list[Any], table_name: str
+) -> tuple[str, str]:
+ for db in databases:
+ for schema in db.schemas:
+ for table in schema.tables:
+ if table.name == table_name:
+ return db.name, schema.name
+ raise AssertionError(f"Did not find table {table_name!r} in catalog")
+
+
+def _table_summary(table: DataTable) -> dict[str, Any]:
+ """Return a stable representation of a DataTable for assertions."""
+ return {
+ "name": table.name,
+ "type": table.type,
+ "num_columns": table.num_columns,
+ "column_names": [c.name for c in table.columns],
+ "column_types": {c.name: c.type for c in table.columns},
+ }
+
+
+def test_adbc_sqlite_driver_catalog_interface() -> None:
+ """Smoke test marimo ADBC catalog interface against the real SQLite driver."""
+ pytest.importorskip(
+ "pyarrow", reason="ADBC DBAPI wrapper requires PyArrow"
+ )
+ adbc_sqlite_dbapi = pytest.importorskip("adbc_driver_sqlite.dbapi")
+
+ # Explicitly use a fresh in-memory database per test run.
+ conn: Any = adbc_sqlite_dbapi.connect(":memory:")
+ try:
+
+ def get_table(
+ *,
+ databases: list[Any],
+ database_name: str,
+ schema_name: str,
+ table_name: str,
+ ) -> DataTable:
+ for db in databases:
+ if getattr(db, "name", None) != database_name:
+ continue
+ for schema in getattr(db, "schemas", []):
+ if getattr(schema, "name", None) != schema_name:
+ continue
+ for table in getattr(schema, "tables", []):
+ if getattr(table, "name", None) == table_name:
+ return cast(DataTable, table)
+ raise AssertionError(
+ f"Did not find table {table_name!r} "
+ f"in {database_name!r}.{schema_name!r}"
+ )
+
+ def sorted_table_summaries(
+ tables: list[DataTable],
+ ) -> list[dict[str, Any]]:
+ return sorted(
+ (_table_summary(t) for t in tables),
+ key=lambda d: str(d["name"]),
+ )
+
+ engine = AdbcDBAPIEngine(conn)
+ assert engine.source == "adbc"
+ assert engine.dialect == "sqlite"
+ assert AdbcDBAPIEngine.is_compatible(conn) is True
+
+ # Minimal schema for catalog discovery.
+ cursor = conn.cursor()
+ try:
+ cursor.execute("CREATE TABLE t (id INTEGER, name TEXT)")
+ cursor.execute("CREATE TABLE t2 (x REAL)")
+ # NOTE: The SQLite ADBC driver infers Arrow types from observed data.
+ # Without any rows, some declared TEXT columns can come back as int64.
+ # Insert at least one row to make schema inference deterministic.
+ cursor.execute("INSERT INTO t VALUES (1, 'hello')")
+ cursor.execute("INSERT INTO t2 VALUES (1.5)")
+ cursor.execute(
+ """
+ CREATE TABLE t_types (
+ int_col INTEGER,
+ real_col REAL,
+ text_col TEXT,
+ blob_col BLOB,
+ bool_col BOOLEAN,
+ date_col DATE,
+ time_col TIME,
+ ts_col TIMESTAMP,
+ numeric_col NUMERIC
+ )
+ """
+ )
+ cursor.execute(
+ """
+ INSERT INTO t_types (
+ int_col,
+ real_col,
+ text_col,
+ blob_col,
+ bool_col,
+ date_col,
+ time_col,
+ ts_col,
+ numeric_col
+ ) VALUES (
+ 1,
+ 1.5,
+ 'hello',
+ X'0001',
+ 1,
+ '2026-01-04',
+ '12:34:56',
+ '2026-01-04 12:34:56',
+ 123.45
+ )
+ """
+ )
+ conn.commit()
+ finally:
+ cursor.close()
+
+ # Default database/schema should be readable (may be None on SQLite).
+ _ = engine.get_default_database()
+ _ = engine.get_default_schema()
+
+ # When schemas are excluded, we should not return any schema information.
+ dbs = engine.get_databases(
+ include_schemas=False,
+ include_tables=True,
+ include_table_details=True,
+ )
+ assert all(db.schemas == [] for db in dbs)
+
+ # When tables are excluded, we should not return any tables.
+ dbs = engine.get_databases(
+ include_schemas=True,
+ include_tables=False,
+ include_table_details=True,
+ )
+ assert all(
+ all(schema.tables == [] for schema in db.schemas) for db in dbs
+ )
+
+ # When table details are excluded, tables should have no columns.
+ dbs_without_details = engine.get_databases(
+ include_schemas=True,
+ include_tables=True,
+ include_table_details=False,
+ )
+ db_name, schema_name = _find_table_location(
+ databases=dbs_without_details, table_name="t"
+ )
+ db_name_types, schema_name_types = _find_table_location(
+ databases=dbs_without_details, table_name="t_types"
+ )
+ assert _table_summary(
+ get_table(
+ databases=dbs_without_details,
+ database_name=db_name,
+ schema_name=schema_name,
+ table_name="t",
+ )
+ ) == {
+ "name": "t",
+ "type": "table",
+ "num_columns": None,
+ "column_names": [],
+ "column_types": {},
+ }
+ assert _table_summary(
+ get_table(
+ databases=dbs_without_details,
+ database_name=db_name_types,
+ schema_name=schema_name_types,
+ table_name="t_types",
+ )
+ ) == {
+ "name": "t_types",
+ "type": "table",
+ "num_columns": None,
+ "column_names": [],
+ "column_types": {},
+ }
+
+ # With details enabled, columns should be populated.
+ dbs_with_details = engine.get_databases(
+ include_schemas=True,
+ include_tables=True,
+ include_table_details=True,
+ )
+ assert _table_summary(
+ get_table(
+ databases=dbs_with_details,
+ database_name=db_name,
+ schema_name=schema_name,
+ table_name="t",
+ )
+ ) == {
+ "name": "t",
+ "type": "table",
+ "num_columns": 2,
+ "column_names": ["id", "name"],
+ "column_types": {"id": "integer", "name": "string"},
+ }
+
+ types_summary = _table_summary(
+ get_table(
+ databases=dbs_with_details,
+ database_name=db_name_types,
+ schema_name=schema_name_types,
+ table_name="t_types",
+ )
+ )
+ assert types_summary == {
+ "name": "t_types",
+ "type": "table",
+ "num_columns": 9,
+ "column_names": [
+ "int_col",
+ "real_col",
+ "text_col",
+ "blob_col",
+ "bool_col",
+ "date_col",
+ "time_col",
+ "ts_col",
+ "numeric_col",
+ ],
+ "column_types": {
+ "int_col": "integer",
+ "real_col": "number",
+ "text_col": "string",
+ "blob_col": "string",
+ "bool_col": "integer",
+ "date_col": "string",
+ "time_col": "string",
+ "ts_col": "string",
+ "numeric_col": "number",
+ },
+ }
+
+ tables = engine.get_tables_in_schema(
+ schema=schema_name, database=db_name, include_table_details=False
+ )
+ assert sorted_table_summaries(tables) == [
+ {
+ "name": "t",
+ "type": "table",
+ "num_columns": None,
+ "column_names": [],
+ "column_types": {},
+ },
+ {
+ "name": "t2",
+ "type": "table",
+ "num_columns": None,
+ "column_names": [],
+ "column_types": {},
+ },
+ {
+ "name": "t_types",
+ "type": "table",
+ "num_columns": None,
+ "column_names": [],
+ "column_types": {},
+ },
+ ]
+
+ tables_with_details = engine.get_tables_in_schema(
+ schema=schema_name, database=db_name, include_table_details=True
+ )
+ assert sorted_table_summaries(tables_with_details) == [
+ {
+ "name": "t",
+ "type": "table",
+ "num_columns": 2,
+ "column_names": ["id", "name"],
+ "column_types": {"id": "integer", "name": "string"},
+ },
+ {
+ "name": "t2",
+ "type": "table",
+ "num_columns": 1,
+ "column_names": ["x"],
+ "column_types": {"x": "number"},
+ },
+ types_summary,
+ ]
+ finally:
+ conn.close()
+
+
+def test_adbc_sqlite_driver_execute_polars(monkeypatch) -> None:
+ """Smoke test marimo ADBC engine against the real ADBC SQLite driver."""
+ pytest.importorskip(
+ "pyarrow", reason="ADBC DBAPI wrapper requires PyArrow"
+ )
+ pl = pytest.importorskip("polars")
+ adbc_sqlite_dbapi = pytest.importorskip("adbc_driver_sqlite.dbapi")
+
+ # Explicitly use a fresh in-memory database per test run.
+ conn: Any = adbc_sqlite_dbapi.connect(":memory:")
+ try:
+ engine = AdbcDBAPIEngine(conn)
+ assert engine.source == "adbc"
+ assert engine.dialect == "sqlite"
+ assert AdbcDBAPIEngine.is_compatible(conn) is True
+
+ engine.execute("CREATE TABLE t (id INTEGER)")
+ engine.execute("INSERT INTO t VALUES (1), (2)")
+
+ from marimo._sql.get_engines import engine_to_data_source_connection
+
+ # Ensure we can produce a DataSourceConnection for the UI/kernel message path.
+ connection = engine_to_data_source_connection(
+ VariableName("adbc_sqlite"), engine
+ )
+ assert connection.source == "adbc"
+ assert connection.dialect == "sqlite"
+ assert connection.name == "adbc_sqlite"
+ assert "sqlite" in connection.display_name.lower()
+
+ monkeypatch.setattr(engine, "sql_output_format", lambda: "polars")
+ df = engine.execute("SELECT id FROM t ORDER BY id")
+ assert isinstance(df, pl.DataFrame)
+ assert df.to_dicts() == [{"id": 1}, {"id": 2}]
+ finally:
+ conn.close()
diff --git a/tests/_sql/test_get_engines.py b/tests/_sql/test_get_engines.py
index 6efb8534b1..2feb0ae292 100644
--- a/tests/_sql/test_get_engines.py
+++ b/tests/_sql/test_get_engines.py
@@ -12,12 +12,10 @@ from marimo._data.models import (
Schema,
)
from marimo._dependencies.dependencies import DependencyManager
+from marimo._sql.engines.adbc import AdbcDBAPIEngine
from marimo._sql.engines.clickhouse import ClickhouseEmbedded
from marimo._sql.engines.dbapi import DBAPIEngine
-from marimo._sql.engines.duckdb import (
- INTERNAL_DUCKDB_ENGINE,
- DuckDBEngine,
-)
+from marimo._sql.engines.duckdb import INTERNAL_DUCKDB_ENGINE, DuckDBEngine
from marimo._sql.engines.ibis import IbisEngine
from marimo._sql.engines.redshift import RedshiftEngine
from marimo._sql.engines.sqlalchemy import SQLAlchemyEngine
@@ -33,6 +31,7 @@ HAS_IBIS = DependencyManager.ibis.has()
HAS_DUCKDB = DependencyManager.duckdb.has()
HAS_CLICKHOUSE = DependencyManager.chdb.has()
HAS_REDSHIFT = DependencyManager.redshift_connector.has()
+HAS_PYARROW = DependencyManager.pyarrow.has()
@pytest.mark.skipif(not HAS_SQLALCHEMY, reason="SQLAlchemy not installed")
@@ -285,6 +284,45 @@ def test_get_engines_dbapi_databases():
assert connection.dialect == "sql"
+ not HAS_PYARROW, reason="pyarrow is required for ADBC sqlite driver"
+)
+def test_get_engines_from_variables_adbc_sqlite() -> None:
+ adbc_sqlite_dbapi = pytest.importorskip("adbc_driver_sqlite.dbapi")
+
+ # Explicitly use a fresh in-memory database per test run.
+ conn = adbc_sqlite_dbapi.connect(":memory:")
+ try:
+ variables: list[tuple[str, object]] = [("adbc_sqlite", conn)]
+ engines = get_engines_from_variables(variables)
+
+ assert len(engines) == 1
+ var_name, engine = engines[0]
+ assert var_name == "adbc_sqlite"
+ assert isinstance(engine, AdbcDBAPIEngine)
+ assert engine.source == "adbc"
+ assert engine.dialect == "sqlite"
+ finally:
+ conn.close()
+
+
+def test_get_engines_from_variables_sqlite3_is_not_adbc() -> None:
+ import sqlite3
+
+ conn = sqlite3.connect(":memory:")
+ try:
+ variables: list[tuple[str, object]] = [("sqlite3_conn", conn)]
+ engines = get_engines_from_variables(variables)
+
+ assert len(engines) == 1
+ var_name, engine = engines[0]
+ assert var_name == "sqlite3_conn"
+ assert isinstance(engine, DBAPIEngine)
+ assert not isinstance(engine, AdbcDBAPIEngine)
+ finally:
+ conn.close()
+
+
@pytest.mark.skipif(not HAS_DUCKDB, reason="DuckDB not installed")
def test_get_engines_duckdb_databases() -> None:
duckdb_engine = DuckDBEngine(None)