fix(starrocks): expose materialized views in sidebar
This commit is contained in:
4 files changed
+262
-24
No files matched your search
@@ -2411,6 +2411,29 @@ fn starrocks_materialized_views_sql(database: &str) -> String {
|
||||
)
|
||||
}
|
||||
|
||||
/// Fallback DDL source for StarRocks materialized views when `SHOW CREATE
|
||||
/// MATERIALIZED VIEW` fails (e.g. on versions predating starrocks/starrocks#73396,
|
||||
/// merged 2026-05-19, which reject the statement for sync MVs with "Table not
|
||||
/// found" because sync MVs are not registered as separate Tables).
|
||||
///
|
||||
/// `information_schema.materialized_views` is documented as the authoritative
|
||||
/// list of all materialized views, with a column distinguishing SYNC from
|
||||
/// ASYNC. See
|
||||
/// https://docs.starrocks.io/docs/sql-reference/information_schema/materialized_views/.
|
||||
///
|
||||
/// Made `pub(super)` so the dispatch site in `schema::mysql_object_source` can
|
||||
/// rely on it without rewriting the escape convention.
|
||||
pub(crate) fn mysql_materialized_view_definition_sql(database: &str, name: &str) -> String {
|
||||
format!(
|
||||
"SELECT MATERIALIZED_VIEW_DEFINITION \
|
||||
FROM information_schema.materialized_views \
|
||||
WHERE TABLE_SCHEMA = {} AND TABLE_NAME = {} \
|
||||
LIMIT 1",
|
||||
quote_value(database),
|
||||
quote_value(name)
|
||||
)
|
||||
}
|
||||
|
||||
async fn list_starrocks_materialized_view_names(pool: &MySqlPool, database: &str) -> Result<HashSet<String>, String> {
|
||||
let sql = starrocks_materialized_views_sql(database);
|
||||
let mut conn = get_conn_with_timeout(pool, super::connection_timeout()).await?;
|
||||
@@ -2425,8 +2448,8 @@ async fn list_starrocks_materialized_view_names(pool: &MySqlPool, database: &str
|
||||
.collect())
|
||||
}
|
||||
|
||||
fn classify_starrocks_materialized_views(
|
||||
tables: &mut [TableInfo],
|
||||
fn merge_starrocks_materialized_views(
|
||||
tables: &mut Vec<TableInfo>,
|
||||
materialized_view_names: Result<HashSet<String>, String>,
|
||||
database: &str,
|
||||
) {
|
||||
@@ -2440,11 +2463,38 @@ fn classify_starrocks_materialized_views(
|
||||
}
|
||||
};
|
||||
|
||||
for table in tables {
|
||||
if table.table_type.eq_ignore_ascii_case("VIEW") && materialized_view_names.contains(&table.name) {
|
||||
// Snapshot the names already returned by SHOW FULL TABLES so the second pass can
|
||||
// append MVs that are absent from SHOW FULL TABLES without duplicating rows.
|
||||
let known_names: HashSet<String> = tables.iter().map(|table| table.name.clone()).collect();
|
||||
|
||||
// Step 1 — reclassify: rows whose name appears in `information_schema.materialized_views`
|
||||
// are MVs even when SHOW FULL TABLES labeled them as VIEW (sync MVs) or BASE TABLE
|
||||
// (async MVs). See https://docs.starrocks.io/docs/sql-reference/information_schema/materialized_views/
|
||||
// for the authoritative distinction between the two MV kinds.
|
||||
for table in tables.iter_mut() {
|
||||
if materialized_view_names.contains(&table.name) {
|
||||
table.table_type = "MATERIALIZED_VIEW".to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Step 2 — union: on StarRocks versions predating starrocks/starrocks#73396 (merged
|
||||
// 2026-05-19), sync MVs "are not registered as separate Tables" so SHOW FULL TABLES
|
||||
// omits them entirely. Append those rows from the system view so they appear in the
|
||||
// sidebar and the DDL source path has something to resolve. Sort names so that
|
||||
// the resulting table order is deterministic across runs.
|
||||
let mut materialized_view_names_sorted: Vec<&String> = materialized_view_names.iter().collect();
|
||||
materialized_view_names_sorted.sort();
|
||||
for name in materialized_view_names_sorted {
|
||||
if !known_names.contains(name.as_str()) {
|
||||
tables.push(TableInfo {
|
||||
name: name.clone(),
|
||||
table_type: "MATERIALIZED_VIEW".to_string(),
|
||||
comment: None,
|
||||
parent_schema: None,
|
||||
parent_name: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async fn list_starrocks_tables_with_status(
|
||||
@@ -2456,7 +2506,7 @@ async fn list_starrocks_tables_with_status(
|
||||
list_starrocks_materialized_view_names(pool, database)
|
||||
);
|
||||
let (mut tables, status) = tables?;
|
||||
classify_starrocks_materialized_views(&mut tables, materialized_view_names, database);
|
||||
merge_starrocks_materialized_views(&mut tables, materialized_view_names, database);
|
||||
Ok((tables, status))
|
||||
}
|
||||
|
||||
@@ -4399,7 +4449,7 @@ mod tests {
|
||||
];
|
||||
let materialized_views = HashSet::from(["orders_mv".to_string(), "orders_mv".to_string()]);
|
||||
|
||||
classify_starrocks_materialized_views(&mut tables, Ok(materialized_views), "analytics");
|
||||
merge_starrocks_materialized_views(&mut tables, Ok(materialized_views), "analytics");
|
||||
|
||||
assert_eq!(tables.len(), 3);
|
||||
assert_eq!(
|
||||
@@ -4408,6 +4458,37 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starrocks_async_materialized_views_reported_as_base_table_are_reclassified() {
|
||||
// Async materialized views (StarRocks >= 2.5) appear as `BASE TABLE` in
|
||||
// `SHOW FULL TABLES`. Classification must trust the
|
||||
// `information_schema.materialized_views` source.
|
||||
let mut tables = vec![
|
||||
TableInfo {
|
||||
name: "orders".to_string(),
|
||||
table_type: "BASE TABLE".to_string(),
|
||||
comment: None,
|
||||
parent_schema: None,
|
||||
parent_name: None,
|
||||
},
|
||||
TableInfo {
|
||||
name: "orders_async_mv".to_string(),
|
||||
table_type: "BASE TABLE".to_string(),
|
||||
comment: None,
|
||||
parent_schema: None,
|
||||
parent_name: None,
|
||||
},
|
||||
];
|
||||
let materialized_views = HashSet::from(["orders_async_mv".to_string()]);
|
||||
|
||||
merge_starrocks_materialized_views(&mut tables, Ok(materialized_views), "analytics");
|
||||
|
||||
assert_eq!(
|
||||
tables.iter().map(|table| (table.name.as_str(), table.table_type.as_str())).collect::<Vec<_>>(),
|
||||
vec![("orders", "BASE TABLE"), ("orders_async_mv", "MATERIALIZED_VIEW")]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starrocks_materialized_view_lookup_failure_keeps_base_types() {
|
||||
let mut tables = vec![TableInfo {
|
||||
@@ -4418,11 +4499,43 @@ mod tests {
|
||||
parent_name: None,
|
||||
}];
|
||||
|
||||
classify_starrocks_materialized_views(&mut tables, Err("permission denied".to_string()), "analytics");
|
||||
merge_starrocks_materialized_views(&mut tables, Err("permission denied".to_string()), "analytics");
|
||||
|
||||
assert_eq!(tables[0].table_type, "VIEW");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starrocks_sync_mv_absent_from_show_full_tables_is_appended_from_information_schema() {
|
||||
// StarRocks versions predating starrocks/starrocks#73396 (merged
|
||||
// 2026-05-19) report sync MVs as "not registered as separate Tables",
|
||||
// so SHOW FULL TABLES omits them. The merger must union names from
|
||||
// information_schema.materialized_views so the sidebar and DDL path
|
||||
// still resolve them.
|
||||
let mut tables = vec![TableInfo {
|
||||
name: "orders".to_string(),
|
||||
table_type: "BASE TABLE".to_string(),
|
||||
comment: None,
|
||||
parent_schema: None,
|
||||
parent_name: None,
|
||||
}];
|
||||
let materialized_views = HashSet::from([
|
||||
"orders_mv".to_string(), // already present (reclassify path)
|
||||
"daily_orders_mv".to_string(), // absent from SHOW FULL TABLES (union path)
|
||||
]);
|
||||
|
||||
merge_starrocks_materialized_views(&mut tables, Ok(materialized_views), "analytics");
|
||||
|
||||
assert_eq!(tables.len(), 3);
|
||||
assert_eq!(
|
||||
tables.iter().map(|table| (table.name.as_str(), table.table_type.as_str())).collect::<Vec<_>>(),
|
||||
vec![
|
||||
("orders", "BASE TABLE"),
|
||||
("daily_orders_mv", "MATERIALIZED_VIEW"),
|
||||
("orders_mv", "MATERIALIZED_VIEW"),
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starrocks_materialized_view_query_is_scoped_to_database() {
|
||||
let sql = starrocks_materialized_views_sql("tenant's analytics");
|
||||
@@ -4433,6 +4546,24 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mysql_materialized_view_definition_fallback_is_scoped_to_db_and_name() {
|
||||
// StarRocks predating PR 73396 (merged 2026-05-19) rejects
|
||||
// `SHOW CREATE MATERIALIZED VIEW` for sync MVs with "Table not found"
|
||||
// because sync MVs are not registered as separate Tables. The fallback
|
||||
// path queries information_schema.materialized_views directly. The
|
||||
// regression guards the SQL shape and the value escaping used by that
|
||||
// fallback so the wire format isn't accidentally regressed.
|
||||
assert_eq!(
|
||||
mysql_materialized_view_definition_sql("shop", "daily_sales_mv"),
|
||||
"SELECT MATERIALIZED_VIEW_DEFINITION FROM information_schema.materialized_views WHERE TABLE_SCHEMA = 'shop' AND TABLE_NAME = 'daily_sales_mv' LIMIT 1"
|
||||
);
|
||||
assert_eq!(
|
||||
mysql_materialized_view_definition_sql("tenant's analytics", "weird'name"),
|
||||
"SELECT MATERIALIZED_VIEW_DEFINITION FROM information_schema.materialized_views WHERE TABLE_SCHEMA = 'tenant\\'s analytics' AND TABLE_NAME = 'weird\\'name' LIMIT 1"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn starrocks_object_conversion_preserves_table_view_and_materialized_view_types() {
|
||||
let tables = vec![
|
||||
|
||||
Reference in new issue
Block a user