Skip to content

Commit

Permalink
Merge pull request #139 from ClickHouse/fix-empty-insert
Browse files Browse the repository at this point in the history
Don't panic on empty insert
  • Loading branch information
serprex authored Sep 4, 2024
2 parents 9d69c51 + ec5accc commit a38d0ff
Show file tree
Hide file tree
Showing 2 changed files with 22 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, // empty insert
InsertState::Active { handle, .. } => InsertState::Terminated { handle },
_ => unreachable!(),
});
Expand Down
21 changes: 21 additions & 0 deletions tests/it/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,24 @@ 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 client = prepare_database!();
create_simple_table(&client, table_name).await;

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

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

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

0 comments on commit a38d0ff

Please sign in to comment.