Skip to content

Commit

Permalink
Don't panic on empty insert
Browse files Browse the repository at this point in the history
Fixes #137
  • Loading branch information
serprex committed Sep 3, 2024
1 parent 9d69c51 commit 394e126
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ impl InsertState {
}

fn terminated(&mut self) {
debug_assert!(matches!(self, InsertState::Active { .. }));
replace_with_or_abort(self, |_self| match _self {
InsertState::NotStarted { .. } => InsertState::Completed,
InsertState::Active { handle, .. } => InsertState::Terminated { handle },
_ => unreachable!(),
});
Expand Down
25 changes: 25 additions & 0 deletions tests/it/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,28 @@ async fn overrides_client_options() {
let rows = fetch_simple_rows(&client, table_name).await;
assert_eq!(rows, vec!(row))
}

#[tokio::test]
async fn empty_insert() {
// https://github.com/ClickHouse/clickhouse-rs/issues/137

let table_name = "insert_empty";
let query_id = uuid::Uuid::new_v4().to_string();
let (setting_name, setting_value, override_value) = ("async_insert", "0", "1");

let client = prepare_database!().with_option(setting_name, setting_value);
create_simple_table(&client, table_name).await;

let insert = client
.insert::<SimpleRow>(table_name)
.unwrap()
.with_option(setting_name, override_value)
.with_option("query_id", &query_id);

insert.end().await.unwrap();

flush_query_log(&client).await;

let rows = fetch_simple_rows(&client, table_name).await;
assert!(rows.is_empty())
}

0 comments on commit 394e126

Please sign in to comment.