Skip to content

Commit 96e8d8b

Browse files
cmungallclaude
andcommitted
Add schema introspection and raw SQL support for Dremio adapters
Dremio Adapter Enhancements: - Add FK introspection via pg_catalog for PostgreSQL sources - Add table/column comments via pg_description - Add nested type introspection via LIMIT 0 queries - Add ADBC Flight SQL driver support (faster queries) - Fix table path quoting for schemas with hyphens/spaces - Add _qualify_table_names() for automatic table qualification New Features: - Add supports_sql property and execute_sql() to Database base class - Add --sql flag to CLI query command for raw SQL execution - Add execute_sql() to DuckDB adapter The Dremio adapters now support: - Schema introspection with FK relationships from PostgreSQL sources - Raw SQL queries via CLI: linkml-store -d dremio://... query --sql '...' - Automatic table name qualification when schema is configured - Proper quoting of source names containing hyphens/spaces Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent a738f4b commit 96e8d8b

File tree

6 files changed

+1202
-32
lines changed

6 files changed

+1202
-32
lines changed

src/linkml_store/api/database.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,48 @@ def query(self, query: Query, **kwargs) -> QueryResult:
441441
else:
442442
raise NotImplementedError(f"Querying without a table is not supported in {self.__class__.__name__}")
443443

444+
@property
445+
def supports_sql(self) -> bool:
446+
"""
447+
Return whether this database supports raw SQL queries.
448+
449+
Backends like DuckDB, PostgreSQL, Dremio support SQL.
450+
Backends like MongoDB, filesystem do not.
451+
452+
:return: True if raw SQL is supported
453+
"""
454+
return False
455+
456+
def execute_sql(self, sql: str, **kwargs) -> QueryResult:
457+
"""
458+
Execute a raw SQL query against the database.
459+
460+
This method allows direct SQL execution on SQL-capable backends,
461+
bypassing the linkml-store query abstraction layer.
462+
463+
:param sql: SQL query string
464+
:param kwargs: Additional arguments
465+
:return: QueryResult containing the results
466+
:raises NotImplementedError: If this backend does not support SQL
467+
468+
Examples
469+
--------
470+
>>> from linkml_store.api.client import Client
471+
>>> client = Client()
472+
>>> db = client.attach_database("duckdb", alias="test", recreate_if_exists=True)
473+
>>> collection = db.create_collection("Person")
474+
>>> collection.insert([{"id": "P1", "name": "John"}, {"id": "P2", "name": "Alice"}])
475+
>>> result = db.execute_sql("SELECT * FROM Person WHERE name = 'John'")
476+
>>> len(result.rows)
477+
1
478+
>>> result.rows[0]["name"]
479+
'John'
480+
"""
481+
raise NotImplementedError(
482+
f"Raw SQL queries are not supported by {self.__class__.__name__}. "
483+
f"Use collection.find() or collection.query() instead."
484+
)
485+
444486
@property
445487
def schema_view(self) -> SchemaView:
446488
"""

0 commit comments

Comments
 (0)