From 5e3f67eb7d510ecdd92db65d87e8f44a71b1412c Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 1 Apr 2025 13:43:10 -0600 Subject: [PATCH] empty chat title and databricks query fix --- .../handlers/src/chats/post_chat_handler.rs | 23 ++++++++----------- .../databricks_query.rs | 22 ++++++++---------- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/api/libs/handlers/src/chats/post_chat_handler.rs b/api/libs/handlers/src/chats/post_chat_handler.rs index 9c9a4144e..9891d9889 100644 --- a/api/libs/handlers/src/chats/post_chat_handler.rs +++ b/api/libs/handlers/src/chats/post_chat_handler.rs @@ -2033,20 +2033,17 @@ async fn initialize_chat( ) -> Result<(Uuid, Uuid, ChatWithMessages)> { let message_id = request.message_id.unwrap_or_else(Uuid::new_v4); - // Get a default title for chats with optional prompt - let default_title = match request.prompt { - Some(ref prompt) => prompt.clone(), - None => { - // Try to derive title from asset if available - let (asset_id, asset_type) = normalize_asset_fields(request); - if let (Some(asset_id), Some(asset_type)) = (asset_id, asset_type) { - match fetch_asset_details(asset_id, asset_type).await { - Ok(details) => format!("View {}", details.name), - Err(_) => "New Chat".to_string(), - } - } else { - "New Chat".to_string() + // Get a default title for chats + let default_title = { + // Try to derive title from asset if available + let (asset_id, asset_type) = normalize_asset_fields(request); + if let (Some(asset_id), Some(asset_type)) = (asset_id, asset_type) { + match fetch_asset_details(asset_id, asset_type).await { + Ok(details) => format!("View {}", details.name), + Err(_) => "New Chat".to_string(), } + } else { + "".to_string() } }; diff --git a/api/libs/query_engine/src/data_source_query_routes/databricks_query.rs b/api/libs/query_engine/src/data_source_query_routes/databricks_query.rs index 29945e374..7c100b7e5 100644 --- a/api/libs/query_engine/src/data_source_query_routes/databricks_query.rs +++ b/api/libs/query_engine/src/data_source_query_routes/databricks_query.rs @@ -12,19 +12,12 @@ pub async fn databricks_query( query: String, limit: Option, ) -> Result>, Error> { - // Apply the limit directly at the database level + // Get the limit value, defaulting to 5000 if not specified let default_limit = 5000; - let limit_value = limit.unwrap_or(default_limit); + let limit_value = limit.unwrap_or(default_limit) as usize; - // Append LIMIT to the query if it doesn't already contain a LIMIT clause - let sql_with_limit = if !query.to_lowercase().contains("limit") { - format!("{} LIMIT {}", query, limit_value) - } else { - query - }; - - // Execute the query with the limit - let results = match databricks_client.query(sql_with_limit).await { + // Execute the query without appending a LIMIT + let results = match databricks_client.query(query).await { Ok(results) => results, Err(e) => { tracing::error!("Error executing Databricks query: {}", e); @@ -33,7 +26,7 @@ pub async fn databricks_query( }; // Create vector with estimated capacity - let mut result: Vec> = Vec::with_capacity(limit_value as usize); + let mut result: Vec> = Vec::with_capacity(limit_value); // Get rows from results let rows = match results.result.data_array { @@ -45,6 +38,11 @@ pub async fn databricks_query( // Process rows with optimized type conversions for row in rows { + // Stop processing if we've reached the limit + if result.len() >= limit_value { + break; + } + let mut row_map: IndexMap = IndexMap::with_capacity(columns.len()); for (i, column) in columns.iter().enumerate() {