-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Feat: Add starrocks catalog support #8856
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
Changes from all commits
81c7672
f5da6fc
34f70e7
227f305
f8310c0
0c95ead
aeead7b
d87ce6d
a4b11d2
fe0226c
9de8ec3
e6d52ba
df32d78
2884c49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -124,6 +124,7 @@ def _quote_identifier(self, identifier: str) -> str: | |||||||||||||||||||||||||||||||||||||||
| """Quote an identifier based on the SQL dialect's quoting rules.""" | ||||||||||||||||||||||||||||||||||||||||
| dialect_quoting: dict[str, tuple[re.Pattern[str], str, str]] = { | ||||||||||||||||||||||||||||||||||||||||
| "snowflake": (_SNOWFLAKE_NEEDS_QUOTING_RE, '"', '"'), | ||||||||||||||||||||||||||||||||||||||||
| "starrocks": (_SNOWFLAKE_NEEDS_QUOTING_RE, "`", "`"), | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| if self.dialect not in dialect_quoting: | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -160,6 +161,7 @@ def _get_inspector(self, database: str) -> Iterator[Optional[Inspector]]: | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| _use_database_dialect_command: dict[str, str] = { | ||||||||||||||||||||||||||||||||||||||||
| "snowflake": f"USE DATABASE {self._quote_identifier(database)}", | ||||||||||||||||||||||||||||||||||||||||
| "starrocks": f"SET CATALOG {self._quote_identifier(database)}", | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
| dialect_command = _use_database_dialect_command.get(self.dialect) | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
|
@@ -257,6 +259,7 @@ def get_default_database(self) -> Optional[str]: | |||||||||||||||||||||||||||||||||||||||
| "postgresql": "SELECT current_database()", | ||||||||||||||||||||||||||||||||||||||||
| "mssql": "SELECT DB_NAME()", | ||||||||||||||||||||||||||||||||||||||||
| "timeplus": "SELECT current_database()", | ||||||||||||||||||||||||||||||||||||||||
| "starrocks": "SELECT CATALOG()", | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| # Try to get the database name by querying the database directly | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -350,6 +353,18 @@ def _get_snowflake_database_names(self) -> list[str]: | |||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return database_names | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| def _get_starrocks_database_names(self) -> list[str]: | ||||||||||||||||||||||||||||||||||||||||
| """Get catalog names for StarRocks via 'SHOW CATALOGS'. | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| StarRocks uses a three-level hierarchy (Catalog → Database → Table) | ||||||||||||||||||||||||||||||||||||||||
| which maps to marimo's (Database → Schema → Table). | ||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+356
to
+361
|
||||||||||||||||||||||||||||||||||||||||
| from sqlalchemy import text | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| with self._connection.connect() as connection: | ||||||||||||||||||||||||||||||||||||||||
| result = connection.execute(text("SHOW CATALOGS")) | ||||||||||||||||||||||||||||||||||||||||
| return [str(row[0]) for row in result.fetchall()] | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+366
to
+367
|
||||||||||||||||||||||||||||||||||||||||
| return [str(row[0]) for row in result.fetchall()] | |
| columns = list(result.keys()) | |
| # StarRocks generally returns a "Catalog" column for SHOW CATALOGS, | |
| # but we defensively support a few plausible variants. | |
| candidate_columns = ("Catalog", "catalog_name", "name") | |
| name_col_index: Optional[int] = None | |
| for col_name in candidate_columns: | |
| if col_name in columns: | |
| name_col_index = columns.index(col_name) | |
| break | |
| if name_col_index is None: | |
| raise RuntimeError( | |
| "Unexpected SHOW CATALOGS result: expected one of " | |
| f"{candidate_columns!r} columns, but got {columns!r}" | |
| ) | |
| return [str(row[name_col_index]) for row in result.fetchall()] |
Copilot
AI
Apr 1, 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 StarRocks-specific paths (SET CATALOG in _get_inspector, SHOW CATALOGS discovery, and the starrocks branch in _get_database_names) aren’t covered by existing SQLAlchemyEngine tests. Since this file already has unit tests (including Snowflake mocking), consider adding a mocked StarRocks test to assert the emitted SQL and that the discovery branch is exercised.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -77,7 +77,7 @@ def sql( | |||||
| break | ||||||
| else: | ||||||
| raise ValueError( | ||||||
| "Unsupported engine. Must be a SQLAlchemy, Ibis, Clickhouse, DuckDB, Redshift or DBAPI 2.0 compatible engine." | ||||||
| "Unsupported engine. Must be a SQLAlchemy, Ibis, Clickhouse, DuckDB, Redshift, StarRocks or DBAPI 2.0 compatible engine." | ||||||
|
||||||
| "Unsupported engine. Must be a SQLAlchemy, Ibis, Clickhouse, DuckDB, Redshift, StarRocks or DBAPI 2.0 compatible engine." | |
| "Unsupported engine. Must be a SQLAlchemy (including StarRocks dialect), Ibis, Clickhouse, DuckDB, Redshift, or DBAPI 2.0 compatible engine." |
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -182,6 +182,8 @@ test-optional = [ | |||
| "chdb>=3; platform_system != 'Windows'", # there is no suitable wheel for windows | ||||
| "clickhouse-connect>=0.8.18", | ||||
| "redshift-connector[full]>=2.1.7", | ||||
| # For testing starrocks | ||||
| "starrocks>=1.3.0", | ||||
|
||||
| "starrocks>=1.3.0", |
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.
DependencyManager.starrocksis introduced but appears unused (no references in the repo). If StarRocks isn’t being explicitly dependency-gated anywhere, consider removing this entry; otherwise, add the correspondingrequire_many/feature checks so this dependency record has an effect.