From 69001061c9c7f88dc7ed0c68fb1bff9d6bceeb57 Mon Sep 17 00:00:00 2001 From: Wang Fenjin Date: Thu, 9 Mar 2023 22:55:17 +0800 Subject: [PATCH] Add tests for extension (#130) * add extension tests Change-Id: Icb74e4909fd7d45c506fa110e4c66b8107dd85bf * fix upgrade.sh Change-Id: I191f8de3f60bea6ff1c1c441df8418c61f3510ae --- libduckdb-sys/upgrade.sh | 12 ++++++----- src/extension.rs | 45 ++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 3 +++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/extension.rs diff --git a/libduckdb-sys/upgrade.sh b/libduckdb-sys/upgrade.sh index 6297f108..64ed17d2 100755 --- a/libduckdb-sys/upgrade.sh +++ b/libduckdb-sys/upgrade.sh @@ -11,20 +11,22 @@ export DU_INCLUDE_DIR="$DUCKDB_LIB_DIR" # Download and extract amalgamation DUCKDB_VERSION=v0.7.1 -wget -T 20 "https://github.com/duckdb/duckdb/releases/download/$DUCKDB_VERSION/libduckdb-src.zip" -unzip -o libduckdb-src.zip -d duckdb -rm -f libduckdb-src.zip +git submodule update --init +cd "$SCRIPT_DIR/duckdb-sources" || { echo "fatal error" >&2; exit 1; } +git checkout "$DUCKDB_VERSION" +cd "$SCRIPT_DIR" || { echo "fatal error" >&2; exit 1; } +python "$SCRIPT_DIR/update_sources.py" # Regenerate bindgen file for DUCKDB rm -f "$DUCKDB_LIB_DIR/bindgen_bundled_version.rs" cargo update # Just to make sure there is only one bindgen.rs file in target dir find "$SCRIPT_DIR/../target" -type f -name bindgen.rs -exec rm {} \; -env LIBDUCKDB_SYS_BUNDLING=1 cargo test --features "bundled buildtime_bindgen" +env LIBDUCKDB_SYS_BUNDLING=1 cargo test --features "extensions-full buildtime_bindgen" find "$SCRIPT_DIR/../target" -type f -name bindgen.rs -exec cp {} "$DUCKDB_LIB_DIR/bindgen_bundled_version.rs" \; # Sanity checks cd "$SCRIPT_DIR/.." || { echo "fatal error" >&2; exit 1; } cargo update -cargo test --features "bundled buildtime_bindgen" +cargo test --features "extensions-full buildtime_bindgen" printf ' \e[35;1mFinished\e[0m bundled DUCKDB tests\n' diff --git a/src/extension.rs b/src/extension.rs new file mode 100644 index 00000000..1fa54c03 --- /dev/null +++ b/src/extension.rs @@ -0,0 +1,45 @@ +#[cfg(test)] +mod test { + use crate::{Connection, Result}; + + // https://duckdb.org/docs/extensions/json + #[test] + fn test_extension_json() -> Result<()> { + let db = Connection::open_in_memory()?; + assert_eq!( + 4, + db.query_row::( + r#"SELECT json_array_length('["duck","goose","swan",null]');"#, + [], + |r| r.get(0) + )? + ); + Ok(()) + } + + // https://duckdb.org/docs/data/parquet/overview.html + #[test] + fn test_extension_parquet() -> Result<()> { + let db = Connection::open_in_memory()?; + assert_eq!( + 300f32, + db.query_row::( + r#"SELECT SUM(value) FROM read_parquet('./examples/int32_decimal.parquet');"#, + [], + |r| r.get(0) + )? + ); + Ok(()) + } + + // https://duckdb.org/docs/extensions/httpfs + #[test] + fn test_extension_httpfs() -> Result<()> { + let db = Connection::open_in_memory()?; + assert_eq!( + 300f32, + db.query_row::(r#"SELECT SUM(value) FROM read_parquet('https://github.com/wangfenjin/duckdb-rs/raw/main/examples/int32_decimal.parquet');"#, [], |r| r.get(0))? + ); + Ok(()) + } +} diff --git a/src/lib.rs b/src/lib.rs index c723d140..4ad41cac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -108,6 +108,9 @@ mod row; mod statement; mod transaction; +#[cfg(feature = "extensions-full")] +mod extension; + pub mod types; pub(crate) mod util;