Skip to content

Commit 6140a7e

Browse files
authored
Upgrade rusqlite to v0.37 & tokio-rusqlite to v0.7 (#495)
* Upgrade rusqlite to v0.37 & tokio-rusqlite to v0.7 * v0.37 updates
1 parent ce3794f commit 6140a7e

7 files changed

Lines changed: 54 additions & 38 deletions

File tree

Cargo.lock

Lines changed: 17 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ prost = { version = "0.14.1", optional = true }
6767
rand = { version = "0.9" }
6868
regex = { version = "1" }
6969
r2d2 = { version = "0.8", optional = true }
70-
rusqlite = { version = "0.32", optional = true }
70+
rusqlite = { version = "0.37.0", optional = true }
7171
sea-query = { version = "0.32", features = [
7272
"backend-sqlite",
7373
"backend-postgres",
@@ -90,7 +90,7 @@ tokio-postgres = { version = "0.7", features = [
9090
"with-serde_json-1",
9191
"with-geo-types-0_7",
9292
], optional = true }
93-
tokio-rusqlite = { version = "0.6.0", optional = true }
93+
tokio-rusqlite = { version = "0.7.0", optional = true }
9494
tonic = { version = "0.13", optional = true, features = [
9595
"tls-native-roots",
9696
"tls-webpki-roots",

core/src/sql/db_connection_pool/dbconnection/sqliteconn.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use super::Result;
2020
#[derive(Debug, Snafu)]
2121
pub enum Error {
2222
#[snafu(display("ConnectionError {source}"))]
23-
ConnectionError { source: tokio_rusqlite::Error },
23+
ConnectionError { source: tokio_rusqlite::Error<rusqlite::Error> },
2424

2525
#[snafu(display("Unable to query: {source}"))]
2626
QueryError { source: rusqlite::Error },
@@ -98,7 +98,7 @@ impl AsyncDbConnection<Connection, &'static (dyn ToSql + Sync)> for SqliteConnec
9898
)?;
9999
let rows = stmt.query_map([], |row| row.get::<_, String>(0))?;
100100
let tables: Result<Vec<_>, rusqlite::Error> = rows.collect();
101-
Ok(tables?)
101+
tables
102102
})
103103
.await
104104
.boxed()
@@ -126,7 +126,7 @@ impl AsyncDbConnection<Connection, &'static (dyn ToSql + Sync)> for SqliteConnec
126126
.context(ConversionSnafu)
127127
.map_err(to_tokio_rusqlite_error)?;
128128
let schema = rec.schema();
129-
Ok(schema)
129+
Ok::<SchemaRef, rusqlite::Error>(schema)
130130
})
131131
.await
132132
.boxed()
@@ -191,6 +191,6 @@ impl AsyncDbConnection<Connection, &'static (dyn ToSql + Sync)> for SqliteConnec
191191
}
192192
}
193193

194-
fn to_tokio_rusqlite_error(e: impl Into<Error>) -> tokio_rusqlite::Error {
195-
tokio_rusqlite::Error::Other(Box::new(e.into()))
194+
fn to_tokio_rusqlite_error(e: impl Into<Error>) -> rusqlite::Error {
195+
rusqlite::Error::ToSqlConversionFailure(Box::new(e.into()))
196196
}

core/src/sql/db_connection_pool/sqlitepool.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::{sync::Arc, time::Duration};
22

33
use async_trait::async_trait;
4-
use snafu::{prelude::*, ResultExt};
4+
use snafu::prelude::*;
55
use tokio_rusqlite::{Connection, ToSql};
66

77
use super::{DbConnectionPool, Result};
@@ -13,7 +13,7 @@ use crate::sql::db_connection_pool::{
1313
#[derive(Debug, Snafu)]
1414
pub enum Error {
1515
#[snafu(display("ConnectionPoolError: {source}"))]
16-
ConnectionPoolError { source: tokio_rusqlite::Error },
16+
ConnectionPoolError { source: rusqlite::Error },
1717

1818
#[snafu(display("No path provided for SQLite connection"))]
1919
NoPathError {},
@@ -127,11 +127,11 @@ impl SqliteConnectionPool {
127127
let conn = match mode {
128128
Mode::Memory => Connection::open_in_memory()
129129
.await
130-
.context(ConnectionPoolSnafu)?,
130+
.map_err(|e| Error::ConnectionPoolError { source: e })?,
131131

132132
Mode::File => Connection::open(path.to_string())
133133
.await
134-
.context(ConnectionPoolSnafu)?,
134+
.map_err(|e| Error::ConnectionPoolError { source: e })?,
135135
};
136136

137137
Ok(SqliteConnectionPool {
@@ -150,7 +150,7 @@ impl SqliteConnectionPool {
150150
if mode == Mode::File {
151151
Connection::open(path.to_string())
152152
.await
153-
.context(ConnectionPoolSnafu)?;
153+
.map_err(|e| Error::ConnectionPoolError { source: e })?;
154154
}
155155

156156
Ok(())
@@ -178,7 +178,12 @@ impl SqliteConnectionPool {
178178
Ok(())
179179
})
180180
.await
181-
.context(ConnectionPoolSnafu)?;
181+
.map_err(|e| match e {
182+
tokio_rusqlite::Error::Error(e) => Error::ConnectionPoolError { source: e },
183+
tokio_rusqlite::Error::ConnectionClosed => Error::ConnectionPoolError { source: rusqlite::Error::InvalidQuery },
184+
tokio_rusqlite::Error::Close((_, e)) => Error::ConnectionPoolError { source: e },
185+
_ => Error::ConnectionPoolError { source: rusqlite::Error::InvalidQuery },
186+
})?;
182187

183188
// database attachments are only supported for file-mode databases
184189
#[cfg(feature = "sqlite-federation")]
@@ -199,7 +204,12 @@ impl SqliteConnectionPool {
199204
Ok(())
200205
})
201206
.await
202-
.context(ConnectionPoolSnafu)?;
207+
.map_err(|e| match e {
208+
tokio_rusqlite::Error::Error(e) => Error::ConnectionPoolError { source: e },
209+
tokio_rusqlite::Error::ConnectionClosed => Error::ConnectionPoolError { source: rusqlite::Error::InvalidQuery },
210+
tokio_rusqlite::Error::Close((_, e)) => Error::ConnectionPoolError { source: e },
211+
_ => Error::ConnectionPoolError { source: rusqlite::Error::InvalidQuery },
212+
})?;
203213
}
204214

205215
Ok::<(), super::Error>(())

core/src/sqlite.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ pub enum Error {
7171
},
7272

7373
#[snafu(display("Unable to create table in Sqlite: {source}"))]
74-
UnableToCreateTable { source: tokio_rusqlite::Error },
74+
UnableToCreateTable { source: tokio_rusqlite::Error<rusqlite::Error> },
7575

7676
#[snafu(display("Unable to insert data into the Sqlite table: {source}"))]
7777
UnableToInsertIntoTable { source: rusqlite::Error },
7878

7979
#[snafu(display("Unable to insert data into the Sqlite table: {source}"))]
80-
UnableToInsertIntoTableAsync { source: tokio_rusqlite::Error },
80+
UnableToInsertIntoTableAsync { source: tokio_rusqlite::Error<rusqlite::Error> },
8181

8282
#[snafu(display("Unable to insert data into the Sqlite table. The disk is full."))]
8383
DiskFull {},
@@ -535,7 +535,7 @@ impl Sqlite {
535535
.call(move |conn| {
536536
let mut stmt = conn.prepare(&sql)?;
537537
let exists = stmt.query_row([], |row| row.get(0))?;
538-
Ok(exists)
538+
Ok::<bool, rusqlite::Error>(exists)
539539
})
540540
.await
541541
.unwrap_or(false)

core/src/sqlite/write.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,7 @@ impl DataSink for SqliteDataSink {
221221
}
222222

223223
if on_commit_transaction.try_recv().is_err() {
224-
return Err(tokio_rusqlite::Error::Other(
225-
"No message to commit transaction has been received.".into(),
226-
));
224+
return Err(rusqlite::Error::InvalidQuery);
227225
}
228226

229227
transaction.commit()?;
@@ -234,14 +232,13 @@ impl DataSink for SqliteDataSink {
234232
.context(super::UnableToInsertIntoTableAsyncSnafu)
235233
.map_err(|e| {
236234
if let super::Error::UnableToInsertIntoTableAsync {
237-
source:
238-
tokio_rusqlite::Error::Rusqlite(rusqlite::Error::SqliteFailure(
239-
rusqlite::ffi::Error {
240-
code: rusqlite::ffi::ErrorCode::DiskFull,
241-
..
242-
},
243-
_,
244-
)),
235+
source: tokio_rusqlite::Error::Error(rusqlite::Error::SqliteFailure(
236+
rusqlite::ffi::Error {
237+
code: rusqlite::ffi::ErrorCode::DiskFull,
238+
..
239+
},
240+
_,
241+
)),
245242
} = e
246243
{
247244
DataFusionError::External(super::Error::DiskFull {}.into())

core/tests/sqlite/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ fn create_comprehensive_test_data() -> (RecordBatch, SchemaRef) {
211211
None,
212212
Some(500000u64),
213213
]);
214-
let col_float32 = Float32Array::from(vec![Some(1.5), None, Some(-3.14), Some(2.71)]);
214+
let col_float32 = Float32Array::from(vec![Some(1.5), None, Some(-std::f32::consts::PI), Some(2.71)]);
215215
let col_float64 =
216-
Float64Array::from(vec![None, Some(2.718281828), Some(-1.414), Some(3.14159)]);
216+
Float64Array::from(vec![None, Some(std::f64::consts::E), Some(-1.414), Some(std::f64::consts::PI)]);
217217
let col_utf8 = StringArray::from(vec![Some("hello"), Some("world"), None, Some("test")]);
218218
let col_large_utf8 = LargeStringArray::from(vec![
219219
None,

0 commit comments

Comments
 (0)