Skip to content

Commit f770d0a

Browse files
Merge pull request #66 from linkml/feature/dremio-introspection-and-sql
Add schema introspection and raw SQL support for Dremio adapters
2 parents a738f4b + 96e8d8b commit f770d0a

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)