From 7182222bf085f313caeda1b883b5b0d69f9949c1 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 18 Feb 2025 14:04:29 -0700 Subject: [PATCH] ok capture data type from valiation --- .../rest/routes/datasets/deploy_datasets.rs | 55 +++++++++++++------ 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/api/src/routes/rest/routes/datasets/deploy_datasets.rs b/api/src/routes/rest/routes/datasets/deploy_datasets.rs index 217d1dbe8..b2b5277a3 100644 --- a/api/src/routes/rest/routes/datasets/deploy_datasets.rs +++ b/api/src/routes/rest/routes/datasets/deploy_datasets.rs @@ -541,27 +541,46 @@ async fn deploy_datasets_handler( } }; + // Create a map of column name to type from ds_columns for easier lookup + let ds_column_types: HashMap = dataset_columns_map + .get(&req.name) + .map(|cols| { + cols.iter() + .map(|col| (col.name.to_lowercase(), col.type_.clone())) + .collect() + }) + .unwrap_or_default(); + let columns: Vec = req .columns .iter() - .map(|col| DatasetColumn { - id: Uuid::new_v4(), - dataset_id, - name: col.name.clone(), - type_: col.type_.clone().unwrap_or_else(|| "text".to_string()), - description: Some(col.description.clone()), - nullable: true, - created_at: now, - updated_at: now, - deleted_at: None, - stored_values: None, - stored_values_status: None, - stored_values_error: None, - stored_values_count: None, - stored_values_last_synced: None, - semantic_type: col.semantic_type.clone(), - dim_type: col.type_.clone(), - expr: col.expr.clone(), + .map(|col| { + // Look up the type from ds_columns, fallback to request type or "text" + let column_type = ds_column_types + .get(&col.name.to_lowercase()) + .cloned() + .or_else(|| col.type_.clone()) + .unwrap_or_else(|| "text".to_string()); + + DatasetColumn { + id: Uuid::new_v4(), + dataset_id, + name: col.name.clone(), + type_: column_type, // Use the type from ds_columns + description: Some(col.description.clone()), + nullable: true, + created_at: now, + updated_at: now, + deleted_at: None, + stored_values: None, + stored_values_status: None, + stored_values_error: None, + stored_values_count: None, + stored_values_last_synced: None, + semantic_type: col.semantic_type.clone(), + dim_type: col.type_.clone(), + expr: col.expr.clone(), + } }) .collect();