-
Notifications
You must be signed in to change notification settings - Fork 22
Add ibis_extras package with SingleStoreDB Ibis backend extensions #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Add mixin classes that extend the Ibis SingleStoreDB backend and ir.Table with SingleStoreDB-specific functionality: - BackendExtensionsMixin: variable/show accessors (globals, locals, cluster_globals, cluster_locals, vars, cluster_vars, show), plus get_storage_info(), get_workload_metrics(), optimize_table(), and get_table_stats() methods - TableExtensionsMixin: optimize(), get_stats(), and get_column_statistics() methods for SingleStoreDB tables The mixins are automatically registered on import via dynamic base class injection. Protocol classes are used for type checking to satisfy mypy while keeping runtime behavior unchanged. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds a new ibis_extras package that extends the Ibis SingleStoreDB backend with SingleStoreDB-specific functionality through mixin classes that are automatically injected into the backend and table classes at import time.
Changes:
- Adds
BackendExtensionsMixinwith variable/show accessors and new methods for storage info, workload metrics, table optimization, and statistics - Adds
TableExtensionsMixinwith table-specific methods for optimization, statistics, and column statistics - Implements automatic mixin registration via dynamic base class modification
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| singlestoredb/ibis_extras/mixins.py | Defines mixin classes with SingleStoreDB-specific extensions for backend and table operations, including SQL helper functions for identifier quoting and string escaping |
| singlestoredb/ibis_extras/init.py | Implements automatic registration mechanism that modifies base classes at import time, with collision detection for existing methods/properties |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from typing import Protocol | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import sqlglot as sg |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The module imports sqlglot (line 8) but this dependency is not listed in the project's dependencies or optional-dependencies in pyproject.toml. If sqlglot is provided by ibis (which seems likely), this should be documented. Otherwise, sqlglot should be added to the optional dependencies for the ibis extras feature.
| def optimize(self) -> None: | ||
| """Optimize this table (SingleStoreDB only).""" | ||
| backend = _get_singlestore_backend(self) | ||
| backend.optimize_table(self.get_name()) | ||
|
|
||
| def get_stats(self) -> dict[str, Any]: | ||
| """Get statistics for this table (SingleStoreDB only).""" | ||
| backend = _get_singlestore_backend(self) | ||
| return backend.get_table_stats(self.get_name()) |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The table methods in TableExtensionsMixin assume the table belongs to the current database, which may not be true. When calling backend.optimize_table(self.get_name()) or backend.get_table_stats(self.get_name()), these methods default to using backend.current_database. However, the table object might reference a table in a different database (e.g., via a fully-qualified table name or when the current database has changed since the table was created). Consider extracting the database from the table's metadata if available, or documenting this limitation.
| def _quote_identifier(name: str) -> str: | ||
| """Quote an identifier (table, database, column name) for safe SQL usage.""" | ||
| return sg.to_identifier(name, quoted=True).sql(_DIALECT) |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent identifier quoting approach with the rest of the codebase. The existing quote_identifier function in connection.py:324 uses backticks directly (`identifier`), while this implementation uses sqlglot. While both approaches produce backticks for SingleStoreDB, using sqlglot adds an external dependency and differs from the established pattern. Consider using the same backtick-based approach for consistency with singlestoredb/connection.py:324-326.
| import ibis.expr.types as ir | ||
| from ibis.backends.singlestoredb import Backend |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing error handling for when ibis or ibis.backends.singlestoredb are not available. The imports on lines 81-82 will raise ImportError if ibis is not installed or if the singlestoredb backend is not available. Since this is an optional feature (per pyproject.toml line 39, ibis is in optional-dependencies), consider wrapping these imports in a try-except block and providing a helpful error message if the required packages are not installed.
| import ibis.expr.types as ir | |
| from ibis.backends.singlestoredb import Backend | |
| try: | |
| import ibis.expr.types as ir | |
| from ibis.backends.singlestoredb import Backend | |
| except ImportError as exc: | |
| raise ImportError( | |
| "ibis and the 'ibis.backends.singlestoredb' backend are required " | |
| "to use 'singlestoredb.ibis_extras'. " | |
| "Install the appropriate optional 'ibis' dependencies for " | |
| "singlestoredb to enable these extensions." | |
| ) from exc |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Add mixin classes that extend the Ibis SingleStoreDB backend and ir.Table with SingleStoreDB-specific functionality:
BackendExtensionsMixin: variable/show accessors (globals, locals, cluster_globals, cluster_locals, vars, cluster_vars, show), plus get_storage_info(), get_workload_metrics(), optimize_table(), and get_table_stats() methods
TableExtensionsMixin: optimize(), get_stats(), and get_column_statistics() methods for SingleStoreDB tables
The mixins are automatically registered on import via dynamic base class injection. Protocol classes are used for type checking to satisfy mypy while keeping runtime behavior unchanged.