From 960c89ab841116240a8fc6fb3fdbc52eb524bb67 Mon Sep 17 00:00:00 2001 From: dal Date: Tue, 4 Feb 2025 17:26:57 -0700 Subject: [PATCH] fix: janky check for values --- .../data_source_query_routes/snowflake_query.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/api/src/utils/query_engine/data_source_query_routes/snowflake_query.rs b/api/src/utils/query_engine/data_source_query_routes/snowflake_query.rs index 79787079e..25196d667 100644 --- a/api/src/utils/query_engine/data_source_query_routes/snowflake_query.rs +++ b/api/src/utils/query_engine/data_source_query_routes/snowflake_query.rs @@ -49,9 +49,12 @@ pub async fn snowflake_query( ) -> Result>, Error> { const MAX_ROWS: usize = 5_000; - // Wrap the original query in a limit clause - // let limited_query = format!("SELECT * FROM ({}) tmp_query LIMIT {}", query.replace(";", ""), MAX_ROWS); - let limited_query = query; + let query_no_semicolon = query.trim_end_matches(';'); + let limited_query = if !query_no_semicolon.to_lowercase().contains("limit") { + format!("{} FETCH FIRST {} ROWS ONLY", query_no_semicolon, MAX_ROWS) + } else { + query_no_semicolon.to_string() + }; let rows = match snowflake_client.exec(&limited_query).await { Ok(result) => match result {