micromegas_analytics/lakehouse/
catalog.rs

1//! Catalog utilities for discovering and managing view schemas.
2//!
3//! This module provides utilities for:
4//! - Discovering current schema versions from the ViewFactory
5//! - Comparing partition schema hashes with current versions
6//! - Finding outdated partitions across view sets
7
8use super::view_factory::ViewFactory;
9use anyhow::Result;
10
11/// Information about a view set's current schema
12#[derive(Debug, Clone)]
13pub struct ViewSetInfo {
14    pub view_set_name: String,
15    pub current_schema_hash: Vec<u8>,
16    pub schema: String,
17    pub has_view_maker: bool,
18    pub global_instance_available: bool,
19}
20
21/// List all view sets with their current schema information from the ViewFactory.
22pub fn list_view_sets(view_factory: &ViewFactory) -> Result<Vec<ViewSetInfo>> {
23    let mut schema_infos = Vec::new();
24    let mut processed_view_sets = std::collections::HashSet::new();
25
26    for global_view in view_factory.get_global_views() {
27        let view_set_name = global_view.get_view_set_name().to_string();
28
29        if processed_view_sets.contains(&view_set_name) {
30            continue;
31        }
32        processed_view_sets.insert(view_set_name.clone());
33
34        let current_schema_hash = global_view.get_file_schema_hash();
35        let schema = format!("{:?}", global_view.get_file_schema());
36
37        // Check if this view set has a ViewMaker (supports non-global instances)
38        let has_view_maker = view_factory.get_view_sets().contains_key(&view_set_name);
39
40        schema_infos.push(ViewSetInfo {
41            view_set_name,
42            current_schema_hash,
43            schema,
44            has_view_maker,
45            global_instance_available: true,
46        });
47    }
48
49    // Then, collect schema info from view sets that have ViewMakers but no global views
50    for (view_set_name, view_maker) in view_factory.get_view_sets() {
51        // Skip if we already processed this view set from global views
52        if processed_view_sets.contains(view_set_name) {
53            continue;
54        }
55
56        // Get schema information directly from the ViewMaker
57        let current_schema_hash = view_maker.get_schema_hash();
58        let schema = format!("{:?}", view_maker.get_schema());
59
60        schema_infos.push(ViewSetInfo {
61            view_set_name: view_set_name.clone(),
62            current_schema_hash,
63            schema,
64            has_view_maker: true,
65            global_instance_available: false,
66        });
67    }
68
69    Ok(schema_infos)
70}