Skip to content

Conversation

@kesmit13
Copy link
Collaborator

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.

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>
Copy link

Copilot AI left a 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 BackendExtensionsMixin with variable/show accessors and new methods for storage info, workload metrics, table optimization, and statistics
  • Adds TableExtensionsMixin with 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
Copy link

Copilot AI Jan 27, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +185 to +193
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())
Copy link

Copilot AI Jan 27, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +40 to +42
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)
Copy link

Copilot AI Jan 27, 2026

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.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +82
import ibis.expr.types as ir
from ibis.backends.singlestoredb import Backend
Copy link

Copilot AI Jan 27, 2026

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.

Suggested change
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

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants