Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an appender to the DuckDbAppendManager to live for the duration of the transaction. #276

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/duckdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use datafusion::{
logical_expr::CreateExternalTable,
sql::TableReference,
};
use duckdb::{AccessMode, DuckdbConnectionManager, Transaction};
use duckdb::{AccessMode, Appender, DuckdbConnectionManager, Transaction};
use itertools::Itertools;
use snafu::prelude::*;
use std::collections::HashSet;
Expand Down Expand Up @@ -102,6 +102,9 @@ pub enum Error {
#[snafu(display("Unable to begin duckdb transaction: {source}"))]
UnableToBeginTransaction { source: duckdb::Error },

#[snafu(display("Unable to flush appender: {source}"))]
UnableToFlushAppender { source: duckdb::Error },

#[snafu(display("Unable to rollback transaction: {source}"))]
UnableToRollbackTransaction { source: duckdb::Error },

Expand Down Expand Up @@ -515,21 +518,15 @@ impl DuckDB {

fn insert_batch_no_constraints(
&self,
transaction: &Transaction<'_>,
appender: &mut Appender<'_>,
batch: &RecordBatch,
) -> Result<()> {
let mut appender = transaction
.appender(&self.table_name)
.context(UnableToGetAppenderToDuckDBTableSnafu)?;

for batch in Self::split_batch(batch) {
appender
.append_record_batch(batch.clone())
.context(UnableToInsertToDuckDBTableSnafu)?;
}

appender.flush().context(UnableToInsertToDuckDBTableSnafu)?;

Ok(())
}

Expand Down Expand Up @@ -791,7 +788,7 @@ pub(crate) mod tests {
let ctx = SessionContext::new();
let cmd = CreateExternalTable {
schema: Arc::new(schema.to_dfschema().expect("to df schema")),
name: table_name.into(),
name: table_name,
location: "".to_string(),
file_type: "".to_string(),
table_partition_cols: vec![],
Expand Down
Loading