Skip to content

Commit 4008fa5

Browse files
authored
Fix #227: handle multiple statements with hooks (#228)
* Fix #227: handle multiple statements with hooks * cargo fmt
1 parent 8e2e651 commit 4008fa5

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

datafusion-postgres/src/handlers.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ impl SimpleQueryHandler for DfSessionService {
309309
.await
310310
{
311311
results.push(result?);
312-
break 'stmt;
312+
continue 'stmt;
313313
}
314314
}
315315

@@ -762,4 +762,33 @@ mod tests {
762762
let result = hook.handle_simple_query(stmt, &ctx, &mut client).await;
763763
assert!(result.is_none());
764764
}
765+
766+
#[tokio::test]
767+
async fn test_multiple_statements_with_hook_continue() {
768+
// Bug #227: when a hook returned a result, the code used `break 'stmt`
769+
// which would exit the entire statement loop, preventing subsequent statements
770+
// from being processed.
771+
let session_context = Arc::new(SessionContext::new());
772+
let auth_manager = Arc::new(AuthManager::new());
773+
774+
let hooks: Vec<Arc<dyn QueryHook>> = vec![Arc::new(TestHook)];
775+
let service = DfSessionService::new_with_hooks(session_context, auth_manager, hooks);
776+
777+
let mut client = MockClient::new();
778+
779+
// Mix of queries with hooks and those without
780+
let query = "SELECT magic; SELECT 1; SELECT magic; SELECT 1";
781+
782+
let results =
783+
<DfSessionService as SimpleQueryHandler>::do_query(&service, &mut client, query)
784+
.await
785+
.unwrap();
786+
787+
assert_eq!(results.len(), 4, "Expected 4 responses");
788+
789+
assert!(matches!(results[0], Response::EmptyQuery));
790+
assert!(matches!(results[1], Response::Query(_)));
791+
assert!(matches!(results[2], Response::EmptyQuery));
792+
assert!(matches!(results[3], Response::Query(_)));
793+
}
765794
}

0 commit comments

Comments
 (0)