Skip to content

Commit

Permalink
Add tests for extension (#130)
Browse files Browse the repository at this point in the history
* add extension tests

Change-Id: Icb74e4909fd7d45c506fa110e4c66b8107dd85bf

* fix upgrade.sh

Change-Id: I191f8de3f60bea6ff1c1c441df8418c61f3510ae
  • Loading branch information
wangfenjin authored Mar 9, 2023
1 parent 0da3aef commit 6900106
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 5 deletions.
12 changes: 7 additions & 5 deletions libduckdb-sys/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
45 changes: 45 additions & 0 deletions src/extension.rs
Original file line number Diff line number Diff line change
@@ -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::<i32, _, _>(
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::<f32, _, _>(
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::<f32, _, _>(r#"SELECT SUM(value) FROM read_parquet('https://github.com/wangfenjin/duckdb-rs/raw/main/examples/int32_decimal.parquet');"#, [], |r| r.get(0))?
);
Ok(())
}
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ mod row;
mod statement;
mod transaction;

#[cfg(feature = "extensions-full")]
mod extension;

pub mod types;

pub(crate) mod util;
Expand Down

0 comments on commit 6900106

Please sign in to comment.