Skip to content

Commit

Permalink
Update appender tests to reflect computed columns support
Browse files Browse the repository at this point in the history
Prior to duckdb/duckdb#14346, the C API did not
support appending to tables with computed columns.

This would cause panics until
#296, where a test was
introduced asserting that an append to a table with computed columns
returns an error value.

Now that appending to is supported, update the test to reflect that.
  • Loading branch information
andrewhamon committed Nov 27, 2024
1 parent 640ecfd commit fd92f02
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions crates/duckdb/src/appender/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ impl fmt::Debug for Appender<'_> {

#[cfg(test)]
mod test {
use crate::{Connection, Result};
use core::panic;

use crate::{params, Connection, Result};

#[test]
fn test_append_one_row() -> Result<()> {
Expand Down Expand Up @@ -287,22 +289,23 @@ mod test {
}

#[test]
fn test_appender_error() -> Result<(), crate::Error> {
fn test_appender_computed_columns() -> Result<(), crate::Error> {
let conn = Connection::open_in_memory()?;
conn.execute(
r"CREATE TABLE foo (
foobar TEXT,
foobar_split TEXT[] AS (split(trim(foobar), ','))
foobar_twice TEXT AS (foobar || foobar)
);",
[],
)?;
let mut appender = conn.appender("foo")?;
match appender.append_row(["foo"]) {
Err(crate::Error::DuckDBFailure(.., Some(msg))) => {
assert_eq!(msg, "Call to EndRow before all columns have been appended to!")
}
_ => panic!("expected error"),
}
appender.append_row(["foo"])?;
appender.flush()?;
let val = conn.query_row("SELECT foobar, foobar_twice FROM foo", [], |row| {
Ok(<(String, String)>::try_from(row))
})??;
assert_eq!(val, ("foo".to_string(), "foofoo".to_string()));

Ok(())
}
}

0 comments on commit fd92f02

Please sign in to comment.