Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(starrocks): handle empty external databases

zipg9dbb2ef72f1f
diff --git a/crates/dbx-core/src/db/starrocks.rs b/crates/dbx-core/src/db/starrocks.rs
index fd179c9074..803b1f56e5 100644
--- a/crates/dbx-core/src/db/starrocks.rs
+++ b/crates/dbx-core/src/db/starrocks.rs
@@ -12,9 +12,35 @@ use super::mysql::{
pub use super::mysql_compatible::{
get_columns_show_from as get_catalog_columns, list_catalog_indexes, list_catalogs,
list_databases_show_from as list_catalog_databases, list_indexes_with_ddl_fallback as list_indexes,
- list_tables_show_from as list_catalog_tables, show_create_table_ddl_from as get_catalog_table_ddl,
+ show_create_table_ddl_from as get_catalog_table_ddl,
};
+pub async fn list_catalog_tables(pool: &MySqlPool, catalog: &str, database: &str) -> Result<Vec<TableInfo>, String> {
+ match super::mysql_compatible::list_tables_show_from(pool, catalog, database).await {
+ Ok(tables) => Ok(tables),
+ Err(error) if should_retry_catalog_table_listing(&error) => {
+ match super::mysql_compatible::list_databases_show_from(pool, catalog).await {
+ Ok(databases) if catalog_database_exists(&databases, database) => {
+ log::debug!(
+ "Treating StarRocks external database `{catalog}`.`{database}` as empty after its qualified table lookup failed: {error}"
+ );
+ Ok(Vec::new())
+ }
+ _ => Err(error),
+ }
+ }
+ Err(error) => Err(error),
+ }
+}
+
+fn should_retry_catalog_table_listing(error: &str) -> bool {
+ error.to_ascii_lowercase().contains("unknown database")
+}
+
+fn catalog_database_exists(databases: &[crate::types::DatabaseInfo], database: &str) -> bool {
+ databases.iter().any(|candidate| candidate.name == database)
+}
+
pub fn is_config(config: &ConnectionConfig) -> bool {
is_profile(&config.db_type, config.driver_profile.as_deref())
}
@@ -133,6 +159,24 @@ mod tests {
assert!(!is_profile(&DatabaseType::Postgres, Some("starrocks")));
}
+ #[test]
+ fn catalog_table_listing_retries_only_unknown_database_errors() {
+ assert!(should_retry_catalog_table_listing(
+ "ERROR 5501 (3F000): Getting analyzing error. Detail message: Unknown database 'edw_dwt'."
+ ));
+ assert!(!should_retry_catalog_table_listing("Access denied on database edw_dwt"));
+ assert!(!should_retry_catalog_table_listing("Connection timed out"));
+ }
+
+ #[test]
+ fn catalog_database_existence_requires_an_exact_name_match() {
+ let databases = vec![crate::types::DatabaseInfo { name: "edw_dwt".to_string(), ..Default::default() }];
+
+ assert!(catalog_database_exists(&databases, "edw_dwt"));
+ assert!(!catalog_database_exists(&databases, "EDW_DWT"));
+ assert!(!catalog_database_exists(&databases, "missing"));
+ }
+
#[test]
fn materialized_views_are_classified_without_duplicates() {
let mut tables = vec![table("orders", "BASE TABLE"), table("orders_view", "VIEW"), table("orders_mv", "VIEW")];