Skip to content

Commit

Permalink
working for importing a table
Browse files Browse the repository at this point in the history
  • Loading branch information
callicles committed Feb 23, 2025
1 parent 4e77236 commit 39730b5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
51 changes: 47 additions & 4 deletions apps/framework-cli/src/cli/local_webserver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,13 +1334,22 @@ fn find_table_definition<'a>(

if discrepancies
.unmapped_tables
.contains(&table_name.to_string())
.iter()
.any(|table| table.name == table_name)
{
debug!(
"Table {} is unmapped, looking for its definition",
table_name
);
// Look for added tables
// First try to find it in unmapped_tables
if let Some(table) = discrepancies
.unmapped_tables
.iter()
.find(|table| table.name == table_name)
{
return Some(table.clone());
}
// If not found in unmapped_tables, look for added tables
discrepancies
.mismatched_tables
.iter()
Expand Down Expand Up @@ -1411,6 +1420,14 @@ async fn update_inframap_tables(
}
} else {
debug!("No changes needed for table {}", table_name);
// Check if this table is in unmapped_tables
if let Some(table) = discrepancies.unmapped_tables.iter().find(|t| t.name == table_name) {
debug!("Found unmapped table {}, adding to inframap", table_name);
infra_map.tables.insert(table.id(), table.clone());
updated_tables.push(table_name);
} else {
debug!("Table {} is not unmapped", table_name);
}
}
}
}
Expand Down Expand Up @@ -1615,7 +1632,7 @@ mod tests {
async fn test_find_table_definition() {
let table = create_test_table("test_table");
let discrepancies = InfraDiscrepancies {
unmapped_tables: vec!["test_table".to_string()],
unmapped_tables: vec![table.clone()],
missing_tables: vec![],
mismatched_tables: vec![OlapChange::Table(TableChange::Added(table.clone()))],
};
Expand All @@ -1631,7 +1648,7 @@ mod tests {
let test_table = create_test_table(table_name);

let discrepancies = InfraDiscrepancies {
unmapped_tables: vec![table_name.to_string()],
unmapped_tables: vec![test_table.clone()],
missing_tables: vec![],
mismatched_tables: vec![OlapChange::Table(TableChange::Added(test_table.clone()))],
};
Expand All @@ -1646,4 +1663,30 @@ mod tests {
assert_eq!(updated_tables[0], table_name);
assert!(infra_map.tables.contains_key(table_name));
}

#[tokio::test]
async fn test_update_inframap_tables_unmapped() {
let table_name = "unmapped_table";
let test_table = create_test_table(table_name);

let discrepancies = InfraDiscrepancies {
unmapped_tables: vec![test_table.clone()],
missing_tables: vec![],
mismatched_tables: vec![OlapChange::Table(TableChange::Added(test_table.clone()))],
};

let mut infra_map = create_test_infra_map();

let tables_to_update = vec![table_name.to_string()];
let updated_tables =
update_inframap_tables(tables_to_update, &discrepancies, &mut infra_map).await;

assert_eq!(updated_tables.len(), 1);
assert_eq!(updated_tables[0], table_name);
assert!(infra_map.tables.contains_key(&test_table.id()));
assert_eq!(
infra_map.tables.get(&test_table.id()).unwrap().name,
table_name
);
}
}
11 changes: 6 additions & 5 deletions apps/framework-cli/src/framework/core/infra_reality_checker.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{
framework::core::infrastructure::table::Table,
framework::core::infrastructure_map::{InfrastructureMap, OlapChange},
infrastructure::olap::{OlapChangesError, OlapOperations},
project::Project,
Expand All @@ -22,7 +23,7 @@ pub enum RealityCheckError {
#[derive(Debug)]
pub struct InfraDiscrepancies {
/// Tables that exist in reality but are not in the map
pub unmapped_tables: Vec<String>,
pub unmapped_tables: Vec<Table>,
/// Tables that are in the map but don't exist in reality
pub missing_tables: Vec<String>,
/// Tables that exist in both but have structural differences
Expand Down Expand Up @@ -103,9 +104,9 @@ impl<T: OlapOperations> InfraRealityChecker<T> {
);

// Find unmapped tables (exist in reality but not in map)
let unmapped_tables: Vec<String> = actual_table_map
.keys()
.filter(|name| !mapped_table_map.contains_key(*name))
let unmapped_tables: Vec<Table> = actual_table_map
.values()
.filter(|table| !mapped_table_map.contains_key(&table.name))
.cloned()
.collect();
debug!(
Expand Down Expand Up @@ -296,7 +297,7 @@ mod tests {

// Should find one unmapped table
assert_eq!(discrepancies.unmapped_tables.len(), 1);
assert_eq!(discrepancies.unmapped_tables[0], "test_table");
assert_eq!(discrepancies.unmapped_tables[0].name, "test_table");
assert!(discrepancies.missing_tables.is_empty());
assert!(discrepancies.mismatched_tables.is_empty());

Expand Down

0 comments on commit 39730b5

Please sign in to comment.