mirror of https://github.com/buster-so/buster.git
empty chat title and databricks query fix
This commit is contained in:
parent
72fb9089e5
commit
5e3f67eb7d
|
@ -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()
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -12,19 +12,12 @@ pub async fn databricks_query(
|
|||
query: String,
|
||||
limit: Option<i64>,
|
||||
) -> Result<Vec<IndexMap<std::string::String, DataType>>, 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<IndexMap<String, DataType>> = Vec::with_capacity(limit_value as usize);
|
||||
let mut result: Vec<IndexMap<String, DataType>> = 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<String, DataType> = IndexMap::with_capacity(columns.len());
|
||||
|
||||
for (i, column) in columns.iter().enumerate() {
|
||||
|
|
Loading…
Reference in New Issue