micromegas_analytics/lakehouse/
catalog.rs1use super::view_factory::ViewFactory;
9use anyhow::Result;
10use datafusion::arrow::datatypes::Schema;
11use std::sync::Arc;
12
13#[derive(Debug, Clone)]
15pub struct ViewSetInfo {
16 pub view_set_name: String,
17 pub current_schema_hash: Vec<u8>,
18 pub schema: String,
19 pub has_view_maker: bool,
20 pub global_instance_available: bool,
21 pub description: Option<Arc<str>>,
22 pub columns: String,
24 pub sort_order: Option<Vec<String>>,
27}
28
29fn format_columns(schema: &Schema) -> String {
30 schema
31 .fields()
32 .iter()
33 .map(|f| format!("{}: {}", f.name(), f.data_type()))
34 .collect::<Vec<_>>()
35 .join("\n")
36}
37
38pub fn list_view_sets(view_factory: &ViewFactory) -> Result<Vec<ViewSetInfo>> {
40 let mut schema_infos = Vec::new();
41 let mut processed_view_sets = std::collections::HashSet::new();
42
43 for global_view in view_factory.get_global_views() {
44 let view_set_name = global_view.get_view_set_name().to_string();
45
46 if processed_view_sets.contains(&view_set_name) {
47 continue;
48 }
49 processed_view_sets.insert(view_set_name.clone());
50
51 let current_schema_hash = global_view.get_file_schema_hash();
52 let schema = format!("{:?}", global_view.get_file_schema());
53
54 let has_view_maker = view_factory.get_view_sets().contains_key(&view_set_name);
56
57 let columns = format_columns(&global_view.get_file_schema());
58 let sort_order = global_view.get_reported_sort_order();
59
60 let description = view_factory.get_description(&view_set_name);
61 schema_infos.push(ViewSetInfo {
62 view_set_name,
63 current_schema_hash,
64 schema,
65 has_view_maker,
66 global_instance_available: true,
67 description,
68 columns,
69 sort_order,
70 });
71 }
72
73 for (view_set_name, view_maker) in view_factory.get_view_sets() {
75 if processed_view_sets.contains(view_set_name) {
77 continue;
78 }
79
80 let current_schema_hash = view_maker.get_schema_hash();
82 let schema = format!("{:?}", view_maker.get_schema());
83
84 schema_infos.push(ViewSetInfo {
85 view_set_name: view_set_name.clone(),
86 current_schema_hash,
87 schema,
88 has_view_maker: true,
89 global_instance_available: false,
90 description: view_factory.get_description(view_set_name),
91 columns: format_columns(&view_maker.get_schema()),
92 sort_order: view_maker.get_scan_output_ordering().sort_columns(),
93 });
94 }
95
96 Ok(schema_infos)
97}